mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
mysql parser refactor.
This commit is contained in:
@@ -190,6 +190,8 @@ public class Lexer {
|
||||
int sp;
|
||||
int np;
|
||||
char ch;
|
||||
long hash;
|
||||
long hash_lower;
|
||||
Token token;
|
||||
String stringVal;
|
||||
}
|
||||
@@ -206,6 +208,8 @@ public class Lexer {
|
||||
savePoint.ch = ch;
|
||||
savePoint.token = token;
|
||||
savePoint.stringVal = stringVal;
|
||||
savePoint.hash = hash;
|
||||
savePoint.hash_lower = hash_lower;
|
||||
return this.savePoint = savePoint;
|
||||
}
|
||||
|
||||
@@ -216,6 +220,8 @@ public class Lexer {
|
||||
this.ch = savePoint.ch;
|
||||
this.token = savePoint.token;
|
||||
this.stringVal = savePoint.stringVal;
|
||||
this.hash = savePoint.hash;
|
||||
this.hash_lower = savePoint.hash_lower;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
@@ -48,11 +49,25 @@ public class SQLSelectParser extends SQLParser {
|
||||
select.setWithSubQuery(with);
|
||||
}
|
||||
|
||||
select.setQuery(query());
|
||||
select.setOrderBy(parseOrderBy());
|
||||
SQLSelectQuery query = query();
|
||||
select.setQuery(query);
|
||||
|
||||
if (select.getOrderBy() == null) {
|
||||
select.setOrderBy(parseOrderBy());
|
||||
SQLOrderBy orderBy = this.parseOrderBy();
|
||||
|
||||
if (query instanceof SQLSelectQueryBlock) {
|
||||
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
|
||||
|
||||
if (queryBlock.getOrderBy() == null) {
|
||||
queryBlock.setOrderBy(orderBy);
|
||||
} else {
|
||||
select.setOrderBy(orderBy);
|
||||
}
|
||||
|
||||
if (orderBy != null) {
|
||||
parseFetchClause(queryBlock);
|
||||
}
|
||||
} else {
|
||||
select.setOrderBy(orderBy);
|
||||
}
|
||||
|
||||
while (lexer.token == Token.HINT) {
|
||||
@@ -609,17 +624,20 @@ public class SQLSelectParser extends SQLParser {
|
||||
rightTableSource = new SQLExprTableSource(expr);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("USING")) {
|
||||
if (lexer.token == Token.USING
|
||||
||lexer.identifierEquals(FNVUtils.USING))
|
||||
{
|
||||
Lexer.SavePoint savePoint = lexer.mark();
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(join.getUsing(), join);
|
||||
accept(Token.RPAREN);
|
||||
} else {
|
||||
join.getUsing().add(this.expr());
|
||||
}
|
||||
|
||||
join.setAlias(this.tableAlias());
|
||||
if (lexer.token == Token.LPAREN
|
||||
|| lexer.token == Token.IDENTIFIER) {
|
||||
lexer.reset(savePoint);
|
||||
join.setRight(rightTableSource);
|
||||
return join;
|
||||
} else {
|
||||
join.setAlias(this.tableAlias());
|
||||
}
|
||||
} else {
|
||||
rightTableSource.setAlias(this.tableAlias());
|
||||
|
||||
@@ -659,14 +677,16 @@ public class SQLSelectParser extends SQLParser {
|
||||
if (lexer.token == Token.ON) {
|
||||
lexer.nextToken();
|
||||
join.setCondition(expr());
|
||||
} else if (lexer.identifierEquals("USING")) {
|
||||
} else if (lexer.token == Token.USING
|
||||
|| lexer.identifierEquals(FNVUtils.USING)) {
|
||||
Lexer.SavePoint savePoint = lexer.mark();
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
this.exprParser.exprList(join.getUsing(), join);
|
||||
accept(Token.RPAREN);
|
||||
} else {
|
||||
join.getUsing().add(this.expr());
|
||||
lexer.reset(savePoint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -369,7 +369,15 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
}
|
||||
|
||||
int size = statementList.size();
|
||||
if (parseStatementListDialect(statementList)) {
|
||||
if (parent != null) {
|
||||
for (int i = size; i < statementList.size(); ++i) {
|
||||
SQLStatement dialectStmt = statementList.get(i);
|
||||
dialectStmt.setParent(parent);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2593,6 +2601,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
accept(Token.MERGE);
|
||||
|
||||
SQLMergeStatement stmt = new SQLMergeStatement();
|
||||
stmt.setDbType(dbType);
|
||||
|
||||
parseHints(stmt.getHints());
|
||||
|
||||
@@ -2608,7 +2617,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
stmt.setInto(exprParser.name());
|
||||
}
|
||||
|
||||
stmt.setAlias(tableAlias());
|
||||
stmt.getInto().setAlias(tableAlias());
|
||||
|
||||
accept(Token.USING);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user