mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved oracle sql parser.
This commit is contained in:
@@ -51,6 +51,7 @@ public class OracleLexer extends Lexer {
|
||||
map.put("EXTRACT", Token.EXTRACT);
|
||||
map.put("GOTO", Token.GOTO);
|
||||
map.put("IF", Token.IF);
|
||||
map.put("ELSIF", Token.ELSIF);
|
||||
|
||||
map.put("LIMIT", Token.LIMIT);
|
||||
map.put("LOOP", Token.LOOP);
|
||||
|
||||
@@ -148,7 +148,7 @@ public class OracleSelectParser extends SQLSelectParser {
|
||||
|
||||
select.setRestriction(checkOption);
|
||||
} else {
|
||||
throw new ParserException("syntax error");
|
||||
throw new ParserException("syntax error. " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-2
@@ -104,7 +104,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
}
|
||||
}
|
||||
|
||||
public void parseStatementList(List<SQLStatement> statementList, int max) {
|
||||
public void parseStatementList(List<SQLStatement> statementList, int max, SQLStatement parent) {
|
||||
for (;;) {
|
||||
if (max != -1) {
|
||||
if (statementList.size() >= max) {
|
||||
@@ -459,6 +459,10 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.ELSIF && parent instanceof SQLIfStatement) {
|
||||
break;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
}
|
||||
@@ -472,7 +476,20 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
accept(Token.THEN);
|
||||
|
||||
this.parseStatementList(stmt.getStatements());
|
||||
this.parseStatementList(stmt.getStatements(), -1, stmt);
|
||||
|
||||
while (lexer.token() == Token.ELSIF) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLIfStatement.ElseIf elseIf = new SQLIfStatement.ElseIf();
|
||||
|
||||
elseIf.setCondition(this.exprParser.expr());
|
||||
|
||||
accept(Token.THEN);
|
||||
this.parseStatementList(elseIf.getStatements(), -1, stmt);
|
||||
|
||||
stmt.getElseIfList().add(elseIf);
|
||||
}
|
||||
|
||||
while (lexer.token() == Token.ELSE) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -80,6 +80,10 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
|
||||
public void parseStatementList(List<SQLStatement> statementList, int max) {
|
||||
parseStatementList(statementList, max, null);
|
||||
}
|
||||
|
||||
public void parseStatementList(List<SQLStatement> statementList, int max, SQLStatement parent) {
|
||||
for (;;) {
|
||||
if (max != -1) {
|
||||
if (statementList.size() >= max) {
|
||||
|
||||
@@ -95,7 +95,8 @@ public enum Token {
|
||||
CASE("CASE"),
|
||||
WHEN("WHEN"),
|
||||
THEN("THEN"),
|
||||
ELSE("ELSE"),
|
||||
ELSE("ELSE"),
|
||||
ELSIF("ELSIF"),
|
||||
END("END"),
|
||||
EXISTS("EXISTS"),
|
||||
IN("IN"),
|
||||
|
||||
Reference in New Issue
Block a user