mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
mysql parser bug fixed
This commit is contained in:
@@ -53,22 +53,37 @@ public class SQLSelectParser extends SQLParser {
|
||||
return select;
|
||||
}
|
||||
|
||||
protected SQLUnionQuery createSQLUnionQuery() {
|
||||
return new SQLUnionQuery();
|
||||
}
|
||||
|
||||
public SQLUnionQuery unionRest(SQLUnionQuery union) {
|
||||
if (lexer.token() == Token.ORDER) {
|
||||
SQLOrderBy orderBy = this.createExprParser().parseOrderBy();
|
||||
union.setOrderBy(orderBy);
|
||||
return unionRest(union);
|
||||
}
|
||||
return union;
|
||||
}
|
||||
|
||||
public SQLSelectQuery queryRest(SQLSelectQuery selectQuery) throws ParserException {
|
||||
if (lexer.token() == Token.UNION) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLUnionQuery union = new SQLUnionQuery();
|
||||
SQLUnionQuery union = createSQLUnionQuery();
|
||||
union.setLeft(selectQuery);
|
||||
|
||||
if (lexer.token() == Token.ALL) {
|
||||
union.setOperator(SQLUnionOperator.UNION_ALL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DISTINCT) {
|
||||
union.setOperator(SQLUnionOperator.DISTINCT);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
SQLSelectQuery right = this.query();
|
||||
union.setRight(right);
|
||||
|
||||
return union;
|
||||
return unionRest(union);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.INTERSECT) {
|
||||
@@ -227,18 +242,23 @@ public class SQLSelectParser extends SQLParser {
|
||||
}
|
||||
|
||||
private void parseTableSourceQueryTableExpr(SQLExprTableSource tableReference) throws ParserException {
|
||||
if (lexer.token() == Token.LITERAL_ALIAS || lexer.token() == Token.IDENTIFIED || lexer.token() == Token.LITERAL_CHARS) {
|
||||
if (lexer.token() == Token.LITERAL_ALIAS || lexer.token() == Token.IDENTIFIED
|
||||
|| lexer.token() == Token.LITERAL_CHARS) {
|
||||
tableReference.setExpr(this.createExprParser().name());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
tableReference.setExpr(expr());
|
||||
}
|
||||
|
||||
protected SQLTableSource parseTableSourceRest(SQLTableSource tableSource) throws ParserException {
|
||||
if ((tableSource.getAlias() == null) || (tableSource.getAlias().length() == 0)) {
|
||||
if (lexer.token() != Token.LEFT && lexer.token() != Token.RIGHT && lexer.token() != Token.FULL) {
|
||||
tableSource.setAlias(as());
|
||||
String alias = as();
|
||||
if (alias != null) {
|
||||
tableSource.setAlias(alias);
|
||||
return parseTableSourceRest(tableSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,6 +296,9 @@ public class SQLSelectParser extends SQLParser {
|
||||
} else if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
joinType = SQLJoinTableSource.JoinType.COMMA;
|
||||
} else if (identifierEquals("STRAIGHT_JOIN")) {
|
||||
lexer.nextToken();
|
||||
joinType = SQLJoinTableSource.JoinType.STRAIGHT_JOIN;
|
||||
}
|
||||
|
||||
if (joinType != null) {
|
||||
|
||||
Reference in New Issue
Block a user