mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed sql parser for db2. for issue #2332
This commit is contained in:
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -46,6 +47,7 @@ public class DB2ExprParser extends SQLExprParser {
|
||||
public DB2ExprParser(String sql){
|
||||
this(new DB2Lexer(sql));
|
||||
this.lexer.nextToken();
|
||||
this.dbType = JdbcConstants.DB2;
|
||||
}
|
||||
|
||||
public DB2ExprParser(String sql, SQLParserFeature... features){
|
||||
@@ -57,6 +59,7 @@ public class DB2ExprParser extends SQLExprParser {
|
||||
super(lexer);
|
||||
this.aggregateFunctions = AGGREGATE_FUNCTIONS;
|
||||
this.aggregateFunctionHashCodes = AGGREGATE_FUNCTIONS_CODES;
|
||||
this.dbType = JdbcConstants.DB2;
|
||||
}
|
||||
|
||||
public SQLExpr primaryRest(SQLExpr expr) {
|
||||
@@ -116,6 +119,15 @@ public class DB2ExprParser extends SQLExprParser {
|
||||
expr = new SQLIdentifierExpr("CURRENT SCHEMA");
|
||||
}
|
||||
}
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.PATH)) {
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
|
||||
if (identExpr.hashCode64() == FnvHash.Constants.CURRENT) {
|
||||
lexer.nextToken();
|
||||
|
||||
expr = new SQLIdentifierExpr("CURRENT PATH");
|
||||
}
|
||||
}
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.MONTHS)) {
|
||||
SQLIntervalExpr intervalExpr = new SQLIntervalExpr(expr, SQLIntervalUnit.MONTH);
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -3679,7 +3679,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
renameStmt.addItem(item);
|
||||
|
||||
return renameStmt;
|
||||
}
|
||||
}
|
||||
} else if (lexer.token() == Token.ORDER) {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
} else if (lexer.identifierEquals("CONVERT")) {
|
||||
|
||||
@@ -2789,7 +2789,13 @@ public class SQLExprParser extends SQLParser {
|
||||
item.setValue(new SQLIdentifierExpr("ON"));
|
||||
return item;
|
||||
} else {
|
||||
accept(Token.EQ);
|
||||
if (lexer.token == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
} else if (JdbcConstants.DB2.equals(dbType)) {
|
||||
// skip
|
||||
} else {
|
||||
accept(Token.EQ);
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token == Token.ON) {
|
||||
|
||||
@@ -634,5 +634,6 @@ public final class FnvHash {
|
||||
long TBLPROPERTIES = fnv1a_64_lower("TBLPROPERTIES");
|
||||
long FULLTEXT = fnv1a_64_lower("FULLTEXT");
|
||||
long NO = fnv1a_64_lower("NO");
|
||||
long PATH = fnv1a_64_lower("PATH");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user