mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
修正运算符优先级别处理不当的问题
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@160 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -98,6 +98,10 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
case FALSE:
|
||||
lexer.nextToken();
|
||||
return primaryRest(new MySqlBooleanExpr(false));
|
||||
case LITERAL_ALIAS:
|
||||
String aliasValue = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
return primaryRest(new SQLCharExpr(aliasValue));
|
||||
default:
|
||||
return super.primary();
|
||||
}
|
||||
|
||||
@@ -102,8 +102,10 @@ public class MySqlLexer extends Lexer {
|
||||
map.put("LOCK", Token.LOCK);
|
||||
map.put("SOME", Token.SOME);
|
||||
map.put("ANY", Token.ANY);
|
||||
|
||||
map.put("TRUE", Token.TRUE);
|
||||
map.put("FALSE", Token.FALSE);
|
||||
map.put("LIMIT", Token.LIMIT);
|
||||
|
||||
DEFAULT_MYSQL_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,41 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
this(new MySqlLexer(sql));
|
||||
this.lexer.nextToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final String as() throws ParserException {
|
||||
String rtnValue = null;
|
||||
|
||||
if (lexer.token() == Token.AS) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.LITERAL_ALIAS) {
|
||||
rtnValue = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
return rtnValue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
rtnValue = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
return rtnValue;
|
||||
}
|
||||
|
||||
throw new ParserException("Error", 0, 0);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LITERAL_ALIAS) {
|
||||
rtnValue = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.IDENTIFIER) {
|
||||
rtnValue = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.LITERAL_CHARS) {
|
||||
rtnValue = "'" + lexer.stringVal() + "'";
|
||||
lexer.nextToken();
|
||||
}
|
||||
return rtnValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SQLSelectQuery query() throws ParserException {
|
||||
@@ -164,7 +199,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
|
||||
queryBlock.setOrderBy(this.createExprParser().parseOrderBy());
|
||||
|
||||
if (identifierEquals("LIMIT")) {
|
||||
if (lexer.token() == Token.LIMIT) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit();
|
||||
|
||||
@@ -129,7 +129,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
deleteStatement.setOrderBy(orderBy);
|
||||
}
|
||||
|
||||
if (identifierEquals("LIMIT")) {
|
||||
if (lexer.token() == Token.LIMIT) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit();
|
||||
@@ -317,7 +317,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
private MySqlShowWarningsStatement parseShowWarnings() throws ParserException {
|
||||
MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement();
|
||||
|
||||
if (identifierEquals("LIMIT")) {
|
||||
if (lexer.token() == Token.LIMIT) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit();
|
||||
@@ -771,6 +771,11 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
SQLName tableName = this.exprParser.name();
|
||||
insertStatement.setTableName(tableName);
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
insertStatement.setAlias(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -189,7 +189,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
if (select.getLimit() != null) {
|
||||
print(" ");
|
||||
println();
|
||||
select.getLimit().accept(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user