improve sql parser

This commit is contained in:
wenshao
2013-08-07 22:24:46 +08:00
parent 76e0de23c2
commit 17a83ebe44
11 changed files with 508 additions and 1 deletions
@@ -49,8 +49,11 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTriggerStatement.TriggerType
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropDatabaseStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropFunctionStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropProcedureStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropSequenceStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropTableSpaceStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropTriggerStatement;
import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
@@ -190,6 +193,18 @@ public class SQLStatementParser extends SQLParser {
SQLStatement stmt = parseDropDatabase(false);
statementList.add(stmt);
continue;
} else if (lexer.token() == Token.FUNCTION) {
SQLStatement stmt = parseDropFunction(false);
statementList.add(stmt);
continue;
} else if (lexer.token() == Token.TABLESPACE) {
SQLStatement stmt = parseDropTablespace(false);
statementList.add(stmt);
continue;
} else if (lexer.token() == Token.PROCEDURE) {
SQLStatement stmt = parseDropProcedure(false);
statementList.add(stmt);
continue;
} else {
throw new ParserException("TODO " + lexer.token());
}
@@ -871,6 +886,69 @@ public class SQLStatementParser extends SQLParser {
return stmt;
}
protected SQLDropFunctionStatement parseDropFunction(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropFunctionStatement stmt = new SQLDropFunctionStatement();
accept(Token.FUNCTION);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
SQLName name = this.exprParser.name();
stmt.setName(name);
return stmt;
}
protected SQLDropTableSpaceStatement parseDropTablespace(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropTableSpaceStatement stmt = new SQLDropTableSpaceStatement();
accept(Token.TABLESPACE);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
SQLName name = this.exprParser.name();
stmt.setName(name);
return stmt;
}
protected SQLDropProcedureStatement parseDropProcedure(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropProcedureStatement stmt = new SQLDropProcedureStatement();
accept(Token.PROCEDURE);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
SQLName name = this.exprParser.name();
stmt.setName(name);
return stmt;
}
public SQLStatement parseTruncate() {
accept(Token.TRUNCATE);