This commit is contained in:
高铁
2019-10-05 13:34:32 +08:00
parent 200c138726
commit f970286f67
2 changed files with 10 additions and 2 deletions
@@ -366,6 +366,8 @@ public class SQLExprParser extends SQLParser {
((SQLBinaryOpExpr) sqlExpr).setBracket(true);
}
accept(Token.RPAREN);
if (lexer.token == Token.UNION && sqlExpr instanceof SQLQueryExpr) {
SQLQueryExpr queryExpr = (SQLQueryExpr) sqlExpr;
@@ -377,7 +379,7 @@ public class SQLExprParser extends SQLParser {
//select * from test_a where id=(select id from test_b where id = 1) union all select * from test_c .....
//会解析为 select * from select * from test_a where id=(select id from test_b where id = 1 union all select * from test_c .....
//所以需要将accept(Token.RPAREN) 移动到 处理 Union all 以及 子查询之后
accept(Token.RPAREN);
break;
case INSERT:
@@ -1,6 +1,7 @@
package com.alibaba.druid.bvt.sql.oracle;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.util.JdbcConstants;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
@@ -16,7 +17,12 @@ public class AntlrExamplesTest extends TestCase {
for (File file : dir.listFiles()) {
System.out.println(file);
String sql = FileUtils.readFileToString(file);
SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
try {
SQLUtils.parseStatements(sql, JdbcConstants.ORACLE);
} catch (ParserException ex) {
System.out.println(sql);
throw ex;
}
}
}
}