mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
+1
-1
@@ -77,7 +77,7 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
if (visitor instanceof MySqlASTVisitor) {
|
||||
accept0((MySqlASTVisitor) visitor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
|
||||
super.accept0(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ public class MySqlDeleteStatement extends SQLDeleteStatement {
|
||||
if (visitor instanceof MySqlASTVisitor) {
|
||||
accept0((MySqlASTVisitor) visitor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
|
||||
super.accept0(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class MySqlInsertStatement extends SQLInsertStatement {
|
||||
if (visitor instanceof MySqlASTVisitor) {
|
||||
accept0((MySqlASTVisitor) visitor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
|
||||
super.accept0(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlSta
|
||||
if (visitor instanceof MySqlASTVisitor) {
|
||||
accept0((MySqlASTVisitor) visitor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
|
||||
super.accept0(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -799,8 +799,10 @@ public class OracleExprParser extends SQLExprParser {
|
||||
}
|
||||
}
|
||||
|
||||
over.setOrderBy(parseOrderBy());
|
||||
if (over.getOrderBy() != null) {
|
||||
final SQLOrderBy orderBy = parseOrderBy();
|
||||
if (orderBy != null) {
|
||||
over.setOrderBy(orderBy);
|
||||
|
||||
OracleAnalyticWindowing windowing = null;
|
||||
if (lexer.identifierEquals(FnvHash.Constants.ROWS)) {
|
||||
lexer.nextToken();
|
||||
@@ -815,12 +817,9 @@ public class OracleExprParser extends SQLExprParser {
|
||||
if (windowing != null) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CURRENT)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.stringVal().equalsIgnoreCase("ROW")) {
|
||||
lexer.nextToken();
|
||||
windowing.setExpr(new SQLIdentifierExpr("CURRENT ROW"));
|
||||
over.setWindowing(windowing);
|
||||
}
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
accept(Token.ROW);
|
||||
windowing.setExpr(new SQLIdentifierExpr("CURRENT ROW"));
|
||||
over.setWindowing(windowing);
|
||||
}
|
||||
if (lexer.identifierEquals(FnvHash.Constants.UNBOUNDED)) {
|
||||
lexer.nextToken();
|
||||
@@ -830,6 +829,46 @@ public class OracleExprParser extends SQLExprParser {
|
||||
} else {
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
} else if (lexer.token() == Token.BETWEEN) {
|
||||
lexer.nextToken();
|
||||
SQLExpr beginExpr;
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CURRENT)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.ROW);
|
||||
beginExpr = new SQLIdentifierExpr("CURRENT ROW");
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.UNBOUNDED)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.stringVal().equalsIgnoreCase("PRECEDING")) {
|
||||
lexer.nextToken();
|
||||
beginExpr = new SQLIdentifierExpr("UNBOUNDED PRECEDING");
|
||||
} else {
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
} else {
|
||||
beginExpr = relational();
|
||||
}
|
||||
|
||||
accept(Token.AND);
|
||||
SQLExpr endExpr;
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CURRENT)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.ROW);
|
||||
endExpr = new SQLIdentifierExpr("CURRENT ROW");
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.UNBOUNDED)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.stringVal().equalsIgnoreCase("PRECEDING")) {
|
||||
lexer.nextToken();
|
||||
endExpr = new SQLIdentifierExpr("UNBOUNDED PRECEDING");
|
||||
} else {
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
} else {
|
||||
endExpr = relational();
|
||||
}
|
||||
|
||||
SQLExpr expr = new SQLBetweenExpr(null, beginExpr, endExpr);
|
||||
windowing.setExpr(expr);
|
||||
} else {
|
||||
SQLExpr expr = this.expr();
|
||||
windowing.setExpr(expr);
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class SQLServerRollbackStatement extends SQLRollbackStatement implements
|
||||
if (visitor instanceof SQLServerASTVisitor) {
|
||||
accept0((SQLServerASTVisitor) visitor);
|
||||
} else {
|
||||
throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
|
||||
super.accept0(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -480,12 +480,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
quote = true;
|
||||
}
|
||||
|
||||
if (quote) {
|
||||
print('(');
|
||||
printExpr(testExpr);
|
||||
print(')');
|
||||
} else {
|
||||
printExpr(testExpr);
|
||||
if (testExpr != null) {
|
||||
if (quote) {
|
||||
print('(');
|
||||
printExpr(testExpr);
|
||||
print(')');
|
||||
} else {
|
||||
printExpr(testExpr);
|
||||
}
|
||||
}
|
||||
|
||||
if (x.isNot()) {
|
||||
|
||||
Reference in New Issue
Block a user