Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复mysql语句解析异常问题,mysql实际执行正常 #6041

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public SQLSelectQuery query(SQLObject parent, boolean acceptUnion) {

SQLSelectQuery select = query();
select.setParenthesized(true);
// 修复特殊sql语句解析错误问题
// 解析异常语句: ((select * from b where 1=1) limit 0,123)
if (lexer.token() == Token.ORDER) {
parseSortBy((SQLSelectQueryBlock) select);
lexer.nextToken();
}
if (lexer.token() == Token.LIMIT) {
SQLLimit limit = this.exprParser.parseLimit();
((SQLSelectQueryBlock) select).setLimit(limit);
}
accept(Token.RPAREN);

return queryRest(select, acceptUnion);
Expand Down Expand Up @@ -416,6 +426,20 @@ public SQLTableSource parseTableSource(SQLObject parent) {
tableSource.getHints().addAll(hints);
}
}
// 修复特殊sql语句解析错误问题
// 解析异常语句: select * from (((select * from tb1 a where (a.cc IN('I') ) and 1=1 and (1=2) )) limit 0,1234) as a where (((a.cc IN('I') ) AND (a.cc IN('I') ))) order by a.cc
if (lexer.token() == Token.ORDER) {
SQLOrderBy orderBy = this.exprParser.parseOrderBy();
if (tableSource instanceof SQLSubqueryTableSource) {
((SQLSubqueryTableSource) tableSource).getSelect().setOrderBy(orderBy);
}
}
if (lexer.token() == Token.LIMIT) {
SQLLimit limit = this.exprParser.parseLimit();
if (tableSource instanceof SQLSubqueryTableSource) {
((SQLSubqueryTableSource) tableSource).getSelect().setLimit(limit);
}
}
accept(Token.RPAREN);
} else {
tableSource = parseTableSource();
Expand Down
Loading