mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
imporoved sql parser.
This commit is contained in:
@@ -550,7 +550,7 @@ public class Lexer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch == 'N') {
|
||||
if (ch == 'N' || ch == 'n') {
|
||||
if (charAt(pos + 1) == '\'') {
|
||||
++pos;
|
||||
ch = '\'';
|
||||
@@ -732,6 +732,14 @@ public class Lexer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch == '\\' && charAt(pos + 1) == 'N'
|
||||
&& JdbcConstants.MYSQL.equals(dbType)) {
|
||||
scanChar();
|
||||
scanChar();
|
||||
token = Token.NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// QS_TODO ?
|
||||
if (isEOF()) { // JLS
|
||||
token = EOF;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -89,7 +90,8 @@ public class SQLExprParser extends SQLParser {
|
||||
} else if (token == Token.EQ) {
|
||||
expr = equalityRest(expr);
|
||||
expr = andRest(expr);
|
||||
return orRest(expr);
|
||||
expr = orRest(expr);
|
||||
return expr;
|
||||
} else {
|
||||
return exprRest(expr);
|
||||
}
|
||||
@@ -338,13 +340,73 @@ public class SQLExprParser extends SQLParser {
|
||||
sqlExpr = lexer.numberExpr();
|
||||
lexer.nextToken();
|
||||
break;
|
||||
case LITERAL_CHARS:
|
||||
case LITERAL_CHARS: {
|
||||
sqlExpr = new SQLCharExpr(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
|
||||
if (JdbcConstants.MYSQL.equals(dbType)) {
|
||||
SQLMethodInvokeExpr concat = null;
|
||||
for (; ; ) {
|
||||
if (lexer.token == Token.LITERAL_ALIAS) {
|
||||
if (concat == null) {
|
||||
concat = new SQLMethodInvokeExpr("CONCAT");
|
||||
concat.addParameter(sqlExpr);
|
||||
sqlExpr = concat;
|
||||
}
|
||||
String alias = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
SQLCharExpr concat_right = new SQLCharExpr(alias.substring(1, alias.length() - 1));
|
||||
concat.addParameter(concat_right);
|
||||
} else if (lexer.token == Token.LITERAL_CHARS || lexer.token == Token.LITERAL_NCHARS) {
|
||||
if (concat == null) {
|
||||
concat = new SQLMethodInvokeExpr("CONCAT");
|
||||
concat.addParameter(sqlExpr);
|
||||
sqlExpr = concat;
|
||||
}
|
||||
|
||||
String chars = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
SQLCharExpr concat_right = new SQLCharExpr(chars);
|
||||
concat.addParameter(concat_right);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LITERAL_NCHARS:
|
||||
} case LITERAL_NCHARS:
|
||||
sqlExpr = new SQLNCharExpr(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
|
||||
if (JdbcConstants.MYSQL.equals(dbType)) {
|
||||
SQLMethodInvokeExpr concat = null;
|
||||
for (; ; ) {
|
||||
if (lexer.token == Token.LITERAL_ALIAS) {
|
||||
if (concat == null) {
|
||||
concat = new SQLMethodInvokeExpr("CONCAT");
|
||||
concat.addParameter(sqlExpr);
|
||||
sqlExpr = concat;
|
||||
}
|
||||
String alias = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
SQLCharExpr concat_right = new SQLCharExpr(alias.substring(1, alias.length() - 1));
|
||||
concat.addParameter(concat_right);
|
||||
} else if (lexer.token == Token.LITERAL_CHARS || lexer.token == Token.LITERAL_NCHARS) {
|
||||
if (concat == null) {
|
||||
concat = new SQLMethodInvokeExpr("CONCAT");
|
||||
concat.addParameter(sqlExpr);
|
||||
sqlExpr = concat;
|
||||
}
|
||||
|
||||
String chars = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
SQLCharExpr concat_right = new SQLCharExpr(chars);
|
||||
concat.addParameter(concat_right);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case VARIANT: {
|
||||
String varName = lexer.stringVal();
|
||||
@@ -591,6 +653,10 @@ public class SQLExprParser extends SQLParser {
|
||||
accept(Token.RPAREN);
|
||||
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
|
||||
break;
|
||||
case BANG:
|
||||
sqlExpr = expr();
|
||||
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Negative, sqlExpr);
|
||||
break;
|
||||
default:
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
@@ -617,6 +683,10 @@ public class SQLExprParser extends SQLParser {
|
||||
accept(Token.RPAREN);
|
||||
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Plus, sqlExpr);
|
||||
break;
|
||||
case SUB:
|
||||
sqlExpr = expr();
|
||||
sqlExpr = new SQLUnaryExpr(SQLUnaryOperator.Plus, sqlExpr);
|
||||
break;
|
||||
default:
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
@@ -773,13 +843,10 @@ public class SQLExprParser extends SQLParser {
|
||||
return methodInvokeExpr;
|
||||
}
|
||||
|
||||
SQLAnyExpr anyExpr = new SQLAnyExpr();
|
||||
SQLSelect anySubQuery = createSelectParser().select();
|
||||
anyExpr.setSubQuery(anySubQuery);
|
||||
SQLAnyExpr anyExpr = new SQLAnyExpr(anySubQuery);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
anySubQuery.setParent(anyExpr);
|
||||
|
||||
sqlExpr = anyExpr;
|
||||
} else {
|
||||
sqlExpr = new SQLIdentifierExpr("ANY");
|
||||
@@ -1003,6 +1070,9 @@ public class SQLExprParser extends SQLParser {
|
||||
if (lexer.token == Token.STAR) {
|
||||
lexer.nextToken();
|
||||
using = new SQLAllColumnExpr();
|
||||
} else if (lexer.token == Token.BINARY) {
|
||||
using = new SQLIdentifierExpr(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
using = this.primary();
|
||||
}
|
||||
@@ -1610,6 +1680,10 @@ public class SQLExprParser extends SQLParser {
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Assignment, rightExp, dbType);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.IS || lexer.token == Token.BETWEEN) {
|
||||
expr = relationalRest(expr);
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
@@ -1970,7 +2044,7 @@ public class SQLExprParser extends SQLParser {
|
||||
} else if (token == (Token.NOT)) {
|
||||
lexer.nextToken();
|
||||
expr = notRationalRest(expr);
|
||||
} else if (token == (Token.BETWEEN)) {
|
||||
} else if (token == Token.BETWEEN) {
|
||||
lexer.nextToken();
|
||||
SQLExpr beginExpr = bitOr();
|
||||
accept(Token.AND);
|
||||
@@ -2051,6 +2125,11 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token == Token.IS
|
||||
|| lexer.token == Token.BETWEEN) {
|
||||
expr = relationalRest(expr);
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
@@ -2252,8 +2331,10 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
accept(Token.SET);
|
||||
|
||||
if (lexer.token != Token.IDENTIFIER && lexer.token != Token.LITERAL_CHARS) {
|
||||
throw new ParserException();
|
||||
if (lexer.token != Token.IDENTIFIER
|
||||
&& lexer.token != Token.LITERAL_CHARS
|
||||
&& lexer.token != Token.BINARY) {
|
||||
throw new ParserException(lexer.info());
|
||||
}
|
||||
charType.setCharSetName(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
@@ -2347,6 +2428,18 @@ public class SQLExprParser extends SQLParser {
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.KEY) {
|
||||
lexer.nextToken();
|
||||
column.addConstraint(new SQLColumnUniqueKey());
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.REFERENCES) {
|
||||
SQLColumnReference ref = parseReference();
|
||||
column.addConstraint(ref);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.CONSTRAINT) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -2371,13 +2464,8 @@ public class SQLExprParser extends SQLParser {
|
||||
}
|
||||
|
||||
if (lexer.token == Token.REFERENCES) {
|
||||
lexer.nextToken();
|
||||
SQLColumnReference ref = new SQLColumnReference();
|
||||
SQLColumnReference ref = parseReference();
|
||||
ref.setName(name);
|
||||
ref.setTable(this.name());
|
||||
accept(Token.LPAREN);
|
||||
this.names(ref.getColumns(), ref);
|
||||
accept(Token.RPAREN);
|
||||
column.addConstraint(ref);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
@@ -2434,6 +2522,82 @@ public class SQLExprParser extends SQLParser {
|
||||
return column;
|
||||
}
|
||||
|
||||
private SQLColumnReference parseReference() {
|
||||
SQLColumnReference fk = new SQLColumnReference();
|
||||
|
||||
lexer.nextToken();
|
||||
fk.setTable(this.name());
|
||||
accept(Token.LPAREN);
|
||||
this.names(fk.getColumns(), fk);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.MATCH)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals("FULL") || lexer.token() == Token.FULL) {
|
||||
fk.setReferenceMatch(SQLForeignKeyImpl.Match.FULL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.PARTIAL)) {
|
||||
fk.setReferenceMatch(SQLForeignKeyImpl.Match.PARTIAL);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.SIMPLE)) {
|
||||
fk.setReferenceMatch(SQLForeignKeyImpl.Match.SIMPLE);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
while (lexer.token() == Token.ON) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.DELETE) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLForeignKeyImpl.Option option = parseReferenceOption();
|
||||
fk.setOnDelete(option);
|
||||
} else if (lexer.token() == Token.UPDATE) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLForeignKeyImpl.Option option = parseReferenceOption();
|
||||
fk.setOnUpdate(option);
|
||||
} else {
|
||||
throw new ParserException("syntax error, expect DELETE or UPDATE, actual " + lexer.token() + " "
|
||||
+ lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
return fk;
|
||||
}
|
||||
|
||||
protected SQLForeignKeyImpl.Option parseReferenceOption() {
|
||||
SQLForeignKeyImpl.Option option;
|
||||
if (lexer.token() == Token.RESTRICT || lexer.identifierEquals(FnvHash.Constants.RESTRICT)) {
|
||||
option = SQLForeignKeyImpl.Option.RESTRICT;
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.CASCADE)) {
|
||||
option = SQLForeignKeyImpl.Option.CASCADE;
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.SET) {
|
||||
lexer.nextToken();
|
||||
accept(Token.NULL);
|
||||
option = SQLForeignKeyImpl.Option.SET_NULL;
|
||||
} else if (lexer.token() == Token.ON || lexer.identifierEquals(FnvHash.Constants.ON)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.identifierEquals(FnvHash.Constants.ACTION)) {
|
||||
option = SQLForeignKeyImpl.Option.NO_ACTION;
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("syntax error, expect ACTION, actual " + lexer.token() + " "
|
||||
+ lexer.info());
|
||||
}
|
||||
} else {
|
||||
throw new ParserException("syntax error, expect ACTION, actual " + lexer.token() + " "
|
||||
+ lexer.info());
|
||||
}
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
protected SQLColumnCheck parseColumnCheck() {
|
||||
lexer.nextToken();
|
||||
SQLExpr expr = this.expr();
|
||||
@@ -2584,6 +2748,8 @@ public class SQLExprParser extends SQLParser {
|
||||
constraint = parsePrimaryKey();
|
||||
} else if (lexer.token == Token.UNIQUE) {
|
||||
constraint = parseUnique();
|
||||
} else if (lexer.token == Token.KEY) {
|
||||
constraint = parseUnique();
|
||||
} else if (lexer.token == Token.FOREIGN) {
|
||||
constraint = parseForeignKey();
|
||||
} else if (lexer.token == Token.CHECK) {
|
||||
@@ -2778,7 +2944,14 @@ public class SQLExprParser extends SQLParser {
|
||||
break;
|
||||
}
|
||||
|
||||
return new SQLSelectItem(expr, alias, connectByRoot);
|
||||
SQLSelectItem selectItem = new SQLSelectItem(expr, alias, connectByRoot);
|
||||
if (lexer.token == Token.HINT) {
|
||||
String comment = "/*" + lexer.stringVal() + "*/";
|
||||
selectItem.addAfterComment(comment);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
return selectItem;
|
||||
}
|
||||
|
||||
public SQLExpr parseGroupingSet() {
|
||||
|
||||
@@ -16,13 +16,9 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
public class SQLParser {
|
||||
|
||||
protected final Lexer lexer;
|
||||
|
||||
protected String dbType;
|
||||
|
||||
|
||||
|
||||
public SQLParser(String sql, String dbType){
|
||||
this(new Lexer(sql, null, dbType), dbType);
|
||||
this.lexer.nextToken();
|
||||
|
||||
@@ -663,8 +663,12 @@ public class SQLSelectParser extends SQLParser {
|
||||
SQLTableSource rightTableSource;
|
||||
if (lexer.token == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
SQLSelect select = this.select();
|
||||
rightTableSource = new SQLSubqueryTableSource(select);
|
||||
if (lexer.token == Token.SELECT) {
|
||||
SQLSelect select = this.select();
|
||||
rightTableSource = new SQLSubqueryTableSource(select);
|
||||
} else {
|
||||
rightTableSource = this.parseTableSource();
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
} else {
|
||||
SQLExpr expr = this.expr();
|
||||
@@ -677,8 +681,12 @@ public class SQLSelectParser extends SQLParser {
|
||||
Lexer.SavePoint savePoint = lexer.mark();
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token == Token.LPAREN
|
||||
|| lexer.token == Token.IDENTIFIER) {
|
||||
if (lexer.token == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
join.setRight(rightTableSource);
|
||||
this.exprParser.exprList(join.getUsing(), join);
|
||||
accept(Token.RPAREN);
|
||||
} else if (lexer.token == Token.IDENTIFIER) {
|
||||
lexer.reset(savePoint);
|
||||
join.setRight(rightTableSource);
|
||||
return join;
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerType;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
@@ -367,12 +368,18 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.token == Token.LPAREN) {
|
||||
char markChar = lexer.current();
|
||||
int markBp = lexer.bp();
|
||||
lexer.nextToken();
|
||||
|
||||
do {
|
||||
lexer.nextToken();
|
||||
} while (lexer.token == Token.LPAREN);
|
||||
|
||||
if (lexer.token == Token.SELECT) {
|
||||
lexer.reset(markBp, markChar, Token.LPAREN);
|
||||
SQLStatement stmt = parseSelect();
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,7 +433,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
stmt = parseDropView(false);
|
||||
} else if (lexer.token == Token.TRIGGER) {
|
||||
stmt = parseDropTrigger(false);
|
||||
} else if (lexer.token == Token.DATABASE) {
|
||||
} else if (lexer.token == Token.DATABASE || lexer.token == Token.SCHEMA) {
|
||||
stmt = parseDropDatabase(false);
|
||||
} else if (lexer.token == Token.FUNCTION) {
|
||||
stmt = parseDropFunction(false);
|
||||
@@ -437,10 +444,19 @@ public class SQLStatementParser extends SQLParser {
|
||||
stmt = parseDropProcedure(false);
|
||||
|
||||
} else if (lexer.token == Token.SEQUENCE) {
|
||||
stmt = parseDropSequece(false);
|
||||
stmt = parseDropSequence(false);
|
||||
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.EVENT)) {
|
||||
stmt = parseDropEvent();
|
||||
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.LOGFILE)) {
|
||||
stmt = parseDropLogFileGroup();
|
||||
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.SERVER)) {
|
||||
stmt = parseDropServer();
|
||||
|
||||
} else {
|
||||
throw new ParserException("TODO " + lexer.token);
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
if (beforeComments != null) {
|
||||
@@ -449,6 +465,80 @@ public class SQLStatementParser extends SQLParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected SQLStatement parseDropServer() {
|
||||
if (lexer.token == Token.DROP) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
acceptIdentifier("SERVER");
|
||||
|
||||
SQLDropServerStatement stmt = new SQLDropServerStatement();
|
||||
stmt.setDbType(dbType);
|
||||
|
||||
if (lexer.token == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EXISTS);
|
||||
stmt.setIfExists(true);
|
||||
}
|
||||
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.setName(name);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected SQLStatement parseDropLogFileGroup() {
|
||||
if (lexer.token == Token.DROP) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
acceptIdentifier("LOGFILE");
|
||||
accept(Token.GROUP);
|
||||
|
||||
SQLDropLogFileGroupStatement stmt = new SQLDropLogFileGroupStatement();
|
||||
stmt.setDbType(dbType);
|
||||
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.setName(name);
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.ENGINE)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr engine = this.exprParser.primary();
|
||||
stmt.setEngine(engine);
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected SQLStatement parseDropEvent() {
|
||||
if (lexer.token == Token.DROP) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
acceptIdentifier("EVENT");
|
||||
|
||||
SQLDropEventStatement stmt = new SQLDropEventStatement();
|
||||
stmt.setDbType(dbType);
|
||||
|
||||
if (lexer.token == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EXISTS);
|
||||
stmt.setIfExists(true);
|
||||
}
|
||||
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.setName(name);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected SQLStatement parseAlterFunction() {
|
||||
throw new ParserException("TODO " + lexer.info());
|
||||
}
|
||||
|
||||
public SQLStatement parseKill() {
|
||||
throw new ParserException("not supported. " + lexer.info());
|
||||
}
|
||||
@@ -1392,7 +1482,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
protected SQLDropSequenceStatement parseDropSequece(boolean acceptDrop) {
|
||||
protected SQLDropSequenceStatement parseDropSequence(boolean acceptDrop) {
|
||||
if (acceptDrop) {
|
||||
accept(Token.DROP);
|
||||
}
|
||||
@@ -1412,10 +1502,17 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
SQLDropTriggerStatement stmt = new SQLDropTriggerStatement(getDbType());
|
||||
|
||||
if (lexer.token == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EXISTS);
|
||||
stmt.setIfExists(true);
|
||||
}
|
||||
|
||||
SQLName name = this.exprParser.name();
|
||||
|
||||
SQLDropTriggerStatement stmt = new SQLDropTriggerStatement(getDbType());
|
||||
|
||||
stmt.setName(name);
|
||||
return stmt;
|
||||
}
|
||||
@@ -1468,7 +1565,11 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
SQLDropDatabaseStatement stmt = new SQLDropDatabaseStatement(getDbType());
|
||||
|
||||
accept(Token.DATABASE);
|
||||
if (lexer.token == Token.SCHEMA) {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
accept(Token.DATABASE);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.IF) {
|
||||
lexer.nextToken();
|
||||
@@ -1525,6 +1626,15 @@ public class SQLStatementParser extends SQLParser {
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.setName(name);
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.ENGINE)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr engine = this.exprParser.primary();
|
||||
stmt.setEngine(engine);
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -1766,6 +1876,25 @@ public class SQLStatementParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
stmt.setTableName(this.exprParser.name());
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.ALGORITHM)) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr algorithm = this.exprParser.primary();
|
||||
stmt.setAlgorithm(algorithm);
|
||||
}
|
||||
|
||||
if (lexer.token == Token.LOCK) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
SQLExpr option = this.exprParser.primary();
|
||||
stmt.setLockOption(option);
|
||||
}
|
||||
// for mysql
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -2077,6 +2206,18 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.DEFINER)) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
SQLName definer = this.exprParser.name();
|
||||
stmt.setDefiner(definer);
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
}
|
||||
|
||||
accept(Token.TRIGGER);
|
||||
|
||||
|
||||
@@ -2331,9 +2472,8 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.identifierEquals("DEFINER")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
SQLName definer = this.exprParser.name();
|
||||
SQLName definer = (SQLName) ((MySqlExprParser) this.exprParser).userName();
|
||||
createView.setDefiner(definer);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("SQL")) {
|
||||
@@ -2435,6 +2575,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
if (lexer.token == Token.CHECK) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("OPTION");
|
||||
createView.setWithCheckOption(true);
|
||||
}
|
||||
}
|
||||
@@ -2615,6 +2756,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
break;
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
|
||||
if (lexer.token == Token.COMMENT) {
|
||||
lexer.nextToken();
|
||||
SQLExpr comment = this.exprParser.primary();
|
||||
item.setComment(comment);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user