use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlSelectTest_171_multi_error method test_0.
public void test_0() throws Exception {
String sql = "select 1 select 2";
Exception error = null;
try {
SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
} catch (ParserException e) {
error = e;
}
assertNotNull(error);
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlSelectTest_94_error method test_0.
public void test_0() throws Exception {
String sql = "select * from ttt where exist (select max(id) from ttt);";
Exception error = null;
try {
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
} catch (ParserException ex) {
error = ex;
}
assertNotNull(error);
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class OracleCreateTableParser method parseOrganization.
private void parseOrganization(OracleCreateTableStatement stmt) {
OracleCreateTableStatement.Organization organization = new OracleCreateTableStatement.Organization();
acceptIdentifier("ORGANIZATION");
if (lexer.token() == Token.INDEX) {
lexer.nextToken();
organization.setType("INDEX");
this.getExprParser().parseSegmentAttributes(organization);
// index_org_table_clause http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7002.htm#i2129638
if (lexer.identifierEquals(FnvHash.Constants.PCTTHRESHOLD)) {
lexer.nextToken();
if (lexer.token() == Token.LITERAL_INT) {
int pctthreshold = ((SQLNumericLiteralExpr) this.exprParser.primary()).getNumber().intValue();
organization.setPctthreshold(pctthreshold);
}
}
} else if (lexer.identifierEquals("HEAP")) {
lexer.nextToken();
organization.setType("HEAP");
this.getExprParser().parseSegmentAttributes(organization);
} else if (lexer.identifierEquals("EXTERNAL")) {
lexer.nextToken();
organization.setType("EXTERNAL");
accept(Token.LPAREN);
if (lexer.identifierEquals("TYPE")) {
lexer.nextToken();
organization.setExternalType(this.exprParser.name());
}
accept(Token.DEFAULT);
acceptIdentifier("DIRECTORY");
organization.setExternalDirectory(this.exprParser.expr());
if (lexer.identifierEquals("ACCESS")) {
lexer.nextToken();
acceptIdentifier("PARAMETERS");
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
SQLExternalRecordFormat recordFormat = new SQLExternalRecordFormat();
if (lexer.identifierEquals("RECORDS")) {
lexer.nextToken();
if (lexer.identifierEquals("DELIMITED")) {
lexer.nextToken();
accept(Token.BY);
if (lexer.identifierEquals("NEWLINE")) {
lexer.nextToken();
recordFormat.setDelimitedBy(new SQLIdentifierExpr("NEWLINE"));
} else {
throw new ParserException("TODO " + lexer.info());
}
if (lexer.identifierEquals(FnvHash.Constants.NOLOGFILE)) {
lexer.nextToken();
recordFormat.setLogfile(false);
}
if (lexer.identifierEquals(FnvHash.Constants.NOBADFILE)) {
lexer.nextToken();
recordFormat.setBadfile(false);
}
} else {
throw new ParserException("TODO " + lexer.info());
}
}
if (lexer.identifierEquals(FnvHash.Constants.FIELDS)) {
lexer.nextToken();
if (lexer.identifierEquals(FnvHash.Constants.TERMINATED)) {
lexer.nextToken();
accept(Token.BY);
recordFormat.setTerminatedBy(this.exprParser.primary());
} else {
throw new ParserException("TODO " + lexer.info());
}
if (lexer.identifierEquals(FnvHash.Constants.LTRIM)) {
lexer.nextToken();
recordFormat.setLtrim(true);
}
}
if (lexer.identifierEquals(FnvHash.Constants.MISSING)) {
lexer.nextToken();
acceptIdentifier("FIELD");
accept(Token.VALUES);
acceptIdentifier("ARE");
accept(Token.NULL);
recordFormat.setMissingFieldValuesAreNull(true);
}
if (lexer.token() == Token.REJECT) {
lexer.nextToken();
acceptIdentifier("ROWS");
accept(Token.WITH);
accept(Token.ALL);
accept(Token.NULL);
acceptIdentifier("FIELDS");
recordFormat.setRejectRowsWithAllNullFields(true);
}
organization.setExternalDirectoryRecordFormat(recordFormat);
accept(Token.RPAREN);
} else if (lexer.token() == Token.USING) {
lexer.nextToken();
acceptIdentifier("CLOB");
throw new ParserException("TODO " + lexer.info());
}
}
acceptIdentifier("LOCATION");
accept(Token.LPAREN);
this.exprParser.exprList(organization.getExternalDirectoryLocation(), organization);
accept(Token.RPAREN);
accept(Token.RPAREN);
if (lexer.token() == Token.REJECT) {
lexer.nextToken();
accept(Token.LIMIT);
organization.setExternalRejectLimit(this.exprParser.primary());
}
//
} else {
throw new ParserException("TODO " + lexer.info());
}
stmt.setOrganization(organization);
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlAlterTableTest54 method test_5.
public void test_5() throws Exception {
String sql = "alter table event_log hot_partition_count = '10';";
MySqlStatementParser parser = new MySqlStatementParser(sql);
try {
SQLStatement stmt = parser.parseStatementList().get(0);
fail();
} catch (ParserException e) {
// do nothing
}
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlSelectTest_298 method test_x1.
public void test_x1() throws Exception {
String sql = "`default`.`row_number`() OVER (PARTITION BY `field` ORDER BY `field` ASC)";
SQLExprParser parser = SQLParserUtils.createExprParser(sql, DbType.mysql);
parser.config(SQLParserFeature.KeepNameQuotes, true);
parser.config(SQLParserFeature.PipesAsConcat, true);
parser.config(SQLParserFeature.EnableSQLBinaryOpExprGroup, true);
SQLExpr expr = parser.expr();
if (parser.getLexer().token() != com.alibaba.druid.sql.parser.Token.EOF) {
throw new ParserException("illegal sql expr : " + sql + ", " + parser.getLexer().info());
}
}
Aggregations