use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class OracleStatementParser method parseStatementList.
public void parseStatementList(List<SQLStatement> statementList, int max) {
for (; ; ) {
if (max != -1) {
if (statementList.size() >= max) {
return;
}
}
if (lexer.token() == Token.EOF) {
return;
}
if (lexer.token() == Token.END) {
return;
}
if (lexer.token() == Token.ELSE) {
return;
}
if (lexer.token() == (Token.SEMI)) {
lexer.nextToken();
continue;
}
if (lexer.token() == (Token.SELECT)) {
SQLSelectStatement stmt = new SQLSelectStatement(new OracleSelectParser(this.exprParser).select(), JdbcConstants.ORACLE);
statementList.add(stmt);
continue;
}
if (lexer.token() == (Token.UPDATE)) {
statementList.add(parseUpdateStatement());
continue;
}
if (lexer.token() == (Token.CREATE)) {
statementList.add(parseCreate());
continue;
}
if (lexer.token() == Token.INSERT) {
statementList.add(parseInsert());
continue;
}
if (lexer.token() == (Token.DELETE)) {
statementList.add(parseDeleteStatement());
continue;
}
if (lexer.token() == (Token.SLASH)) {
lexer.nextToken();
statementList.add(new OraclePLSQLCommitStatement());
continue;
}
if (lexer.token() == Token.ALTER) {
statementList.add(parserAlter());
continue;
}
if (lexer.token() == Token.WITH) {
statementList.add(new SQLSelectStatement(new OracleSelectParser(this.exprParser).select()));
continue;
}
if (lexer.token() == Token.LBRACE || identifierEquals("CALL")) {
statementList.add(this.parseCall());
continue;
}
if (lexer.token() == Token.MERGE) {
statementList.add(this.parseMerge());
continue;
}
if (lexer.token() == Token.BEGIN) {
statementList.add(this.parseBlock());
continue;
}
if (lexer.token() == Token.DECLARE) {
statementList.add(this.parseBlock());
continue;
}
if (lexer.token() == Token.LOCK) {
statementList.add(this.parseLock());
continue;
}
if (lexer.token() == Token.TRUNCATE) {
statementList.add(this.parseTruncate());
continue;
}
if (lexer.token() == Token.VARIANT) {
SQLExpr variant = this.exprParser.primary();
if (variant instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) variant;
if (binaryOpExpr.getOperator() == SQLBinaryOperator.Assignment) {
SQLSetStatement stmt = new SQLSetStatement(binaryOpExpr.getLeft(), binaryOpExpr.getRight(), getDbType());
statementList.add(stmt);
continue;
}
}
accept(Token.COLONEQ);
SQLExpr value = this.exprParser.expr();
SQLSetStatement stmt = new SQLSetStatement(variant, value, getDbType());
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.EXCEPTION) {
statementList.add(this.parseException());
continue;
}
if (identifierEquals("EXIT")) {
lexer.nextToken();
OracleExitStatement stmt = new OracleExitStatement();
if (lexer.token() == Token.WHEN) {
lexer.nextToken();
stmt.setWhen(this.exprParser.expr());
}
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.FETCH || identifierEquals("FETCH")) {
SQLStatement stmt = parseFetch();
statementList.add(stmt);
continue;
}
if (identifierEquals("ROLLBACK")) {
SQLRollbackStatement stmt = parseRollback();
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.EXPLAIN) {
statementList.add(this.parseExplain());
continue;
}
if (lexer.token() == Token.IDENTIFIER) {
SQLExpr expr = exprParser.expr();
OracleExprStatement stmt = new OracleExprStatement(expr);
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.LPAREN) {
char ch = lexer.current();
int bp = lexer.bp();
lexer.nextToken();
if (lexer.token() == Token.SELECT) {
lexer.reset(bp, ch, Token.LPAREN);
statementList.add(this.parseSelect());
continue;
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
}
if (lexer.token() == Token.SET) {
statementList.add(this.parseSet());
continue;
}
if (lexer.token() == Token.GRANT) {
statementList.add(this.parseGrant());
continue;
}
if (lexer.token() == Token.REVOKE) {
statementList.add(this.parseRevoke());
continue;
}
if (lexer.token() == Token.COMMENT) {
statementList.add(this.parseComment());
continue;
}
if (lexer.token() == Token.FOR) {
statementList.add(this.parseFor());
continue;
}
if (lexer.token() == Token.LOOP) {
statementList.add(this.parseLoop());
continue;
}
if (lexer.token() == Token.IF) {
statementList.add(this.parseIf());
continue;
}
if (lexer.token() == Token.GOTO) {
lexer.nextToken();
SQLName label = this.exprParser.name();
OracleGotoStatement stmt = new OracleGotoStatement(label);
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.COMMIT) {
lexer.nextToken();
if (identifierEquals("WORK")) {
lexer.nextToken();
}
OracleCommitStatement stmt = new OracleCommitStatement();
if (identifierEquals("WRITE")) {
stmt.setWrite(true);
lexer.nextToken();
for (; ; ) {
if (lexer.token() == Token.WAIT) {
lexer.nextToken();
stmt.setWait(Boolean.TRUE);
continue;
} else if (lexer.token() == Token.NOWAIT) {
lexer.nextToken();
stmt.setWait(Boolean.FALSE);
continue;
} else if (lexer.token() == Token.IMMEDIATE) {
lexer.nextToken();
stmt.setImmediate(Boolean.TRUE);
continue;
} else if (identifierEquals("BATCH")) {
lexer.nextToken();
stmt.setImmediate(Boolean.FALSE);
continue;
}
break;
}
}
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.SAVEPOINT) {
lexer.nextToken();
OracleSavePointStatement stmt = new OracleSavePointStatement();
if (lexer.token() == Token.TO) {
lexer.nextToken();
stmt.setTo(this.exprParser.name());
}
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.LTLT) {
lexer.nextToken();
SQLName label = this.exprParser.name();
OracleLabelStatement stmt = new OracleLabelStatement(label);
accept(Token.GTGT);
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.DROP) {
lexer.nextToken();
if (lexer.token() == Token.TABLE) {
SQLDropTableStatement stmt = parseDropTable(false);
statementList.add(stmt);
continue;
}
boolean isPublic = false;
if (identifierEquals("PUBLIC")) {
lexer.nextToken();
isPublic = true;
}
if (lexer.token() == Token.DATABASE) {
lexer.nextToken();
if (identifierEquals("LINK")) {
lexer.nextToken();
OracleDropDbLinkStatement stmt = new OracleDropDbLinkStatement();
if (isPublic) {
stmt.setPublic(isPublic);
}
stmt.setName(this.exprParser.name());
statementList.add(stmt);
continue;
}
}
if (lexer.token() == Token.INDEX) {
SQLStatement stmt = parseDropIndex();
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.VIEW) {
SQLStatement stmt = parseDropView(false);
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.SEQUENCE) {
SQLDropSequenceStatement stmt = parseDropSequece(false);
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.TRIGGER) {
SQLDropTriggerStatement stmt = parseDropTrigger(false);
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.USER) {
SQLDropUserStatement stmt = parseDropUser();
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.PROCEDURE) {
SQLDropProcedureStatement stmt = parseDropProcedure(false);
statementList.add(stmt);
continue;
}
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
if (lexer.token() == Token.NULL) {
lexer.nextToken();
OracleExprStatement stmt = new OracleExprStatement(new SQLNullExpr());
statementList.add(stmt);
continue;
}
if (lexer.token() == Token.OPEN) {
SQLStatement stmt = this.parseOpen();
statementList.add(stmt);
continue;
}
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlStatementParser method parseStatementListDialect.
public boolean parseStatementListDialect(List<SQLStatement> statementList) {
if (lexer.token() == Token.KILL) {
SQLStatement stmt = parseKill();
statementList.add(stmt);
return true;
}
if (identifierEquals("PREPARE")) {
MySqlPrepareStatement stmt = parsePrepare();
statementList.add(stmt);
return true;
}
if (identifierEquals("EXECUTE")) {
MySqlExecuteStatement stmt = parseExecute();
statementList.add(stmt);
return true;
}
if (identifierEquals("DEALLOCATE")) {
MysqlDeallocatePrepareStatement stmt = parseDeallocatePrepare();
statementList.add(stmt);
return true;
}
if (identifierEquals("LOAD")) {
SQLStatement stmt = parseLoad();
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.REPLACE) {
MySqlReplaceStatement stmt = parseReplicate();
statementList.add(stmt);
return true;
}
if (identifierEquals("START")) {
SQLStartTransactionStatement stmt = parseStart();
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.SHOW) {
SQLStatement stmt = parseShow();
statementList.add(stmt);
return true;
}
if (identifierEquals(BINLOG)) {
SQLStatement stmt = parseBinlog();
statementList.add(stmt);
return true;
}
if (identifierEquals(RESET)) {
SQLStatement stmt = parseReset();
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.ANALYZE) {
SQLStatement stmt = parseAnalyze();
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.OPTIMIZE) {
SQLStatement stmt = parseOptimize();
statementList.add(stmt);
return true;
}
if (identifierEquals("HELP")) {
lexer.nextToken();
MySqlHelpStatement stmt = new MySqlHelpStatement();
stmt.setContent(this.exprParser.primary());
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.DESC || identifierEquals(DESCRIBE)) {
SQLStatement stmt = parseDescribe();
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.LOCK) {
lexer.nextToken();
String val = lexer.stringVal();
boolean isLockTables = TABLES.equalsIgnoreCase(val) && lexer.token() == Token.IDENTIFIER;
boolean isLockTable = "TABLE".equalsIgnoreCase(val) && lexer.token() == Token.TABLE;
if (isLockTables || isLockTable) {
lexer.nextToken();
} else {
setErrorEndPos(lexer.pos());
throw new ParserException("syntax error, expect TABLES or TABLE, actual " + lexer.token());
}
MySqlLockTableStatement stmt = new MySqlLockTableStatement();
stmt.setTableSource(this.exprParser.name());
if (identifierEquals(READ)) {
lexer.nextToken();
if (identifierEquals(LOCAL)) {
lexer.nextToken();
stmt.setLockType(LockType.READ_LOCAL);
} else {
stmt.setLockType(LockType.READ);
}
} else if (identifierEquals(WRITE)) {
stmt.setLockType(LockType.WRITE);
} else if (identifierEquals(LOW_PRIORITY)) {
lexer.nextToken();
acceptIdentifier(WRITE);
stmt.setLockType(LockType.LOW_PRIORITY_WRITE);
} else {
throw new ParserException("syntax error, expect READ or WRITE, actual " + lexer.token());
}
if (lexer.token() == Token.HINT) {
stmt.setHints(this.exprParser.parseHints());
}
statementList.add(stmt);
return true;
}
if (identifierEquals("UNLOCK")) {
lexer.nextToken();
String val = lexer.stringVal();
boolean isUnLockTables = TABLES.equalsIgnoreCase(val) && lexer.token() == Token.IDENTIFIER;
boolean isUnLockTable = "TABLE".equalsIgnoreCase(val) && lexer.token() == Token.TABLE;
statementList.add(new MySqlUnlockTablesStatement());
if (isUnLockTables || isUnLockTable) {
lexer.nextToken();
} else {
setErrorEndPos(lexer.pos());
throw new ParserException("syntax error, expect TABLES or TABLE, actual " + lexer.token());
}
return true;
}
if (lexer.token() == Token.HINT) {
List<SQLCommentHint> hints = this.exprParser.parseHints();
boolean tddlSelectHints = false;
if (hints.size() == 1 && statementList.size() == 0 && lexer.token() == Token.SELECT) {
SQLCommentHint hint = hints.get(0);
String hintText = hint.getText();
if (hintText.startsWith("+TDDL")) {
tddlSelectHints = true;
}
}
if (tddlSelectHints) {
SQLSelectStatement stmt = (SQLSelectStatement) this.parseStatement();
stmt.setHeadHints(hints);
statementList.add(stmt);
return true;
}
MySqlHintStatement stmt = new MySqlHintStatement();
stmt.setHints(hints);
statementList.add(stmt);
return true;
}
if (lexer.token() == Token.BEGIN) {
statementList.add(this.parseBlock());
return true;
}
return false;
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlStatementParser method parseKill.
public SQLStatement parseKill() {
accept(Token.KILL);
MySqlKillStatement stmt = new MySqlKillStatement();
if (identifierEquals("CONNECTION")) {
stmt.setType(MySqlKillStatement.Type.CONNECTION);
lexer.nextToken();
} else if (identifierEquals("QUERY")) {
stmt.setType(MySqlKillStatement.Type.QUERY);
lexer.nextToken();
} else if (lexer.token() == Token.LITERAL_INT) {
// skip
} else {
throw new ParserException("not support kill type " + lexer.token());
}
this.exprParser.exprList(stmt.getThreadIds(), stmt);
return stmt;
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlStatementParser method parseDeclareHandler.
/**
* 定义异常处理程序
* @author zhujun [455910092@qq.com]
* 2016-04-16
* @return
*/
public MySqlDeclareHandlerStatement parseDeclareHandler() {
//DECLARE handler_type HANDLER FOR condition_value[,...] sp_statement
//handler_type 取值为 CONTINUE | EXIT | UNDO
//condition_value 取值为 SQLWARNING | NOT FOUND | SQLEXCEPTION | SQLSTATE value(异常码 e.g 1062)
MySqlDeclareHandlerStatement stmt = new MySqlDeclareHandlerStatement();
accept(Token.DECLARE);
//String handlerType = exprParser.name().getSimpleName();
if (lexer.token() == Token.CONTINUE) {
stmt.setHandleType(MySqlHandlerType.CONTINUE);
} else if (lexer.token() == Token.EXIT) {
stmt.setHandleType(MySqlHandlerType.CONTINUE);
} else if (lexer.token() == Token.UNDO) {
stmt.setHandleType(MySqlHandlerType.CONTINUE);
} else {
throw new ParserException("unkown handle type");
}
lexer.nextToken();
acceptIdentifier("HANDLER");
accept(Token.FOR);
for (; ; ) {
String tokenName = lexer.stringVal();
ConditionValue condition = new ConditionValue();
if (tokenName.equalsIgnoreCase("NOT")) {
//for 'NOT FOUND'
lexer.nextToken();
acceptIdentifier("HANDLE");
condition.setType(ConditionType.SYSTEM);
condition.setValue("NOT FOUND");
} else if (tokenName.equalsIgnoreCase("SQLSTATE")) {
//for SQLSTATE (SQLSTATE '10001')
condition.setType(ConditionType.SQLSTATE);
lexer.nextToken();
//condition.setValue(lexer.stringVal());
//lexer.nextToken();
condition.setValue(exprParser.name().toString());
} else if (identifierEquals("SQLEXCEPTION")) {
//for SQLEXCEPTION
condition.setType(ConditionType.SYSTEM);
condition.setValue(lexer.stringVal());
lexer.nextToken();
} else if (identifierEquals("SQLWARNING")) {
//for SQLWARNING
condition.setType(ConditionType.SYSTEM);
condition.setValue(lexer.stringVal());
lexer.nextToken();
} else {
//for condition_name or mysql_error_code
if (lexer.token() == Token.LITERAL_INT) {
condition.setType(ConditionType.MYSQL_ERROR_CODE);
condition.setValue(lexer.integerValue().toString());
} else {
condition.setType(ConditionType.SELF);
condition.setValue(tokenName);
}
lexer.nextToken();
}
stmt.getConditionValues().add(condition);
if (lexer.token() == Token.COMMA) {
accept(Token.COMMA);
continue;
} else if (lexer.token() != Token.EOF) {
break;
} else {
throw new ParserException("declare handle not eof");
}
}
stmt.setSpStatement(parseSpStatement());
if (!(stmt.getSpStatement() instanceof SQLBlockStatement)) {
accept(Token.SEMI);
}
return stmt;
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlStatementParser method parseShow.
public SQLStatement parseShow() {
accept(Token.SHOW);
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
}
boolean full = false;
if (lexer.token() == Token.FULL) {
lexer.nextToken();
full = true;
}
if (identifierEquals("PROCESSLIST")) {
lexer.nextToken();
MySqlShowProcessListStatement stmt = new MySqlShowProcessListStatement();
stmt.setFull(full);
return stmt;
}
if (identifierEquals("COLUMNS") || identifierEquals("FIELDS")) {
lexer.nextToken();
MySqlShowColumnsStatement stmt = parseShowColumns();
stmt.setFull(full);
return stmt;
}
if (identifierEquals("COLUMNS")) {
lexer.nextToken();
MySqlShowColumnsStatement stmt = parseShowColumns();
return stmt;
}
if (identifierEquals(TABLES)) {
lexer.nextToken();
SQLShowTablesStatement stmt = parseShowTabless();
stmt.setFull(full);
return stmt;
}
if (identifierEquals("DATABASES")) {
lexer.nextToken();
MySqlShowDatabasesStatement stmt = parseShowDatabases();
return stmt;
}
if (identifierEquals("WARNINGS")) {
lexer.nextToken();
MySqlShowWarningsStatement stmt = parseShowWarnings();
return stmt;
}
if (identifierEquals("COUNT")) {
lexer.nextToken();
accept(Token.LPAREN);
accept(Token.STAR);
accept(Token.RPAREN);
if (identifierEquals(ERRORS)) {
lexer.nextToken();
MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
stmt.setCount(true);
return stmt;
} else {
acceptIdentifier("WARNINGS");
MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement();
stmt.setCount(true);
return stmt;
}
}
if (identifierEquals(ERRORS)) {
lexer.nextToken();
MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
stmt.setLimit(this.exprParser.parseLimit());
return stmt;
}
if (identifierEquals(STATUS)) {
lexer.nextToken();
MySqlShowStatusStatement stmt = parseShowStatus();
return stmt;
}
if (identifierEquals(VARIABLES)) {
lexer.nextToken();
MySqlShowVariantsStatement stmt = parseShowVariants();
return stmt;
}
if (identifierEquals(GLOBAL)) {
lexer.nextToken();
if (identifierEquals(STATUS)) {
lexer.nextToken();
MySqlShowStatusStatement stmt = parseShowStatus();
stmt.setGlobal(true);
return stmt;
}
if (identifierEquals(VARIABLES)) {
lexer.nextToken();
MySqlShowVariantsStatement stmt = parseShowVariants();
stmt.setGlobal(true);
return stmt;
}
}
if (identifierEquals(SESSION)) {
lexer.nextToken();
if (identifierEquals(STATUS)) {
lexer.nextToken();
MySqlShowStatusStatement stmt = parseShowStatus();
stmt.setSession(true);
return stmt;
}
if (identifierEquals(VARIABLES)) {
lexer.nextToken();
MySqlShowVariantsStatement stmt = parseShowVariants();
stmt.setSession(true);
return stmt;
}
}
if (identifierEquals("COBAR_STATUS")) {
lexer.nextToken();
return new CobarShowStatus();
}
if (identifierEquals("AUTHORS")) {
lexer.nextToken();
return new MySqlShowAuthorsStatement();
}
if (lexer.token() == Token.BINARY) {
lexer.nextToken();
acceptIdentifier("LOGS");
return new MySqlShowBinaryLogsStatement();
}
if (identifierEquals("MASTER")) {
lexer.nextToken();
if (identifierEquals("LOGS")) {
lexer.nextToken();
return new MySqlShowMasterLogsStatement();
}
acceptIdentifier(STATUS);
return new MySqlShowMasterStatusStatement();
}
if (identifierEquals(CHARACTER)) {
lexer.nextToken();
accept(Token.SET);
MySqlShowCharacterSetStatement stmt = new MySqlShowCharacterSetStatement();
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
stmt.setPattern(this.exprParser.expr());
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
stmt.setWhere(this.exprParser.expr());
}
return stmt;
}
if (identifierEquals("COLLATION")) {
lexer.nextToken();
MySqlShowCollationStatement stmt = new MySqlShowCollationStatement();
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
stmt.setPattern(this.exprParser.expr());
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
stmt.setWhere(this.exprParser.expr());
}
return stmt;
}
if (identifierEquals(BINLOG)) {
lexer.nextToken();
acceptIdentifier(EVENTS);
MySqlShowBinLogEventsStatement stmt = new MySqlShowBinLogEventsStatement();
if (lexer.token() == Token.IN) {
lexer.nextToken();
stmt.setIn(this.exprParser.expr());
}
if (lexer.token() == Token.FROM) {
lexer.nextToken();
stmt.setFrom(this.exprParser.expr());
}
stmt.setLimit(this.exprParser.parseLimit());
return stmt;
}
if (identifierEquals("CONTRIBUTORS")) {
lexer.nextToken();
return new MySqlShowContributorsStatement();
}
if (lexer.token() == Token.CREATE) {
lexer.nextToken();
if (lexer.token() == Token.DATABASE) {
lexer.nextToken();
MySqlShowCreateDatabaseStatement stmt = new MySqlShowCreateDatabaseStatement();
stmt.setDatabase(this.exprParser.name());
return stmt;
}
if (identifierEquals("EVENT")) {
lexer.nextToken();
MySqlShowCreateEventStatement stmt = new MySqlShowCreateEventStatement();
stmt.setEventName(this.exprParser.name());
return stmt;
}
if (lexer.token() == Token.FUNCTION) {
lexer.nextToken();
MySqlShowCreateFunctionStatement stmt = new MySqlShowCreateFunctionStatement();
stmt.setName(this.exprParser.name());
return stmt;
}
if (lexer.token() == Token.PROCEDURE) {
lexer.nextToken();
MySqlShowCreateProcedureStatement stmt = new MySqlShowCreateProcedureStatement();
stmt.setName(this.exprParser.name());
return stmt;
}
if (lexer.token() == Token.TABLE) {
lexer.nextToken();
MySqlShowCreateTableStatement stmt = new MySqlShowCreateTableStatement();
stmt.setName(this.exprParser.name());
return stmt;
}
if (lexer.token() == Token.VIEW) {
lexer.nextToken();
MySqlShowCreateViewStatement stmt = new MySqlShowCreateViewStatement();
stmt.setName(this.exprParser.name());
return stmt;
}
if (lexer.token() == Token.TRIGGER) {
lexer.nextToken();
MySqlShowCreateTriggerStatement stmt = new MySqlShowCreateTriggerStatement();
stmt.setName(this.exprParser.name());
return stmt;
}
throw new ParserException("TODO " + lexer.stringVal());
}
if (identifierEquals(ENGINE)) {
lexer.nextToken();
MySqlShowEngineStatement stmt = new MySqlShowEngineStatement();
stmt.setName(this.exprParser.name());
stmt.setOption(MySqlShowEngineStatement.Option.valueOf(lexer.stringVal().toUpperCase()));
lexer.nextToken();
return stmt;
}
if (identifierEquals("STORAGE")) {
lexer.nextToken();
acceptIdentifier(ENGINES);
MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
stmt.setStorage(true);
return stmt;
}
if (identifierEquals(ENGINES)) {
lexer.nextToken();
MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
return stmt;
}
if (identifierEquals(EVENTS)) {
lexer.nextToken();
MySqlShowEventsStatement stmt = new MySqlShowEventsStatement();
if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
lexer.nextToken();
stmt.setSchema(this.exprParser.name());
}
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
stmt.setLike(this.exprParser.expr());
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
stmt.setWhere(this.exprParser.expr());
}
return stmt;
}
if (lexer.token() == Token.FUNCTION) {
lexer.nextToken();
if (identifierEquals("CODE")) {
lexer.nextToken();
MySqlShowFunctionCodeStatement stmt = new MySqlShowFunctionCodeStatement();
stmt.setName(this.exprParser.name());
return stmt;
}
acceptIdentifier(STATUS);
MySqlShowFunctionStatusStatement stmt = new MySqlShowFunctionStatusStatement();
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
stmt.setLike(this.exprParser.expr());
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
stmt.setWhere(this.exprParser.expr());
}
return stmt;
}
if (identifierEquals(ENGINE)) {
lexer.nextToken();
MySqlShowEngineStatement stmt = new MySqlShowEngineStatement();
stmt.setName(this.exprParser.name());
stmt.setOption(MySqlShowEngineStatement.Option.valueOf(lexer.stringVal().toUpperCase()));
lexer.nextToken();
return stmt;
}
if (identifierEquals("STORAGE")) {
lexer.nextToken();
accept(Token.EQ);
accept(Token.DEFAULT);
MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
stmt.setStorage(true);
return stmt;
}
if (identifierEquals(ENGINES)) {
lexer.nextToken();
MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
return stmt;
}
if (identifierEquals("GRANTS")) {
lexer.nextToken();
MySqlShowGrantsStatement stmt = new MySqlShowGrantsStatement();
if (lexer.token() == Token.FOR) {
lexer.nextToken();
stmt.setUser(this.exprParser.expr());
}
return stmt;
}
if (lexer.token() == Token.INDEX || identifierEquals("INDEXES")) {
lexer.nextToken();
MySqlShowIndexesStatement stmt = new MySqlShowIndexesStatement();
if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
lexer.nextToken();
SQLName table = exprParser.name();
stmt.setTable(table);
if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
lexer.nextToken();
SQLName database = exprParser.name();
stmt.setDatabase(database);
}
}
if (lexer.token() == Token.HINT) {
stmt.setHints(this.exprParser.parseHints());
}
return stmt;
}
if (identifierEquals("KEYS")) {
lexer.nextToken();
MySqlShowKeysStatement stmt = new MySqlShowKeysStatement();
if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
lexer.nextToken();
SQLName table = exprParser.name();
stmt.setTable(table);
if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
lexer.nextToken();
SQLName database = exprParser.name();
stmt.setDatabase(database);
}
}
return stmt;
}
if (lexer.token() == Token.OPEN || identifierEquals("OPEN")) {
lexer.nextToken();
acceptIdentifier(TABLES);
MySqlShowOpenTablesStatement stmt = new MySqlShowOpenTablesStatement();
if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
lexer.nextToken();
stmt.setDatabase(this.exprParser.name());
}
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
stmt.setLike(this.exprParser.expr());
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
stmt.setWhere(this.exprParser.expr());
}
return stmt;
}
if (identifierEquals("PLUGINS")) {
lexer.nextToken();
MySqlShowPluginsStatement stmt = new MySqlShowPluginsStatement();
return stmt;
}
if (identifierEquals("PRIVILEGES")) {
lexer.nextToken();
MySqlShowPrivilegesStatement stmt = new MySqlShowPrivilegesStatement();
return stmt;
}
if (lexer.token() == Token.PROCEDURE) {
lexer.nextToken();
if (identifierEquals("CODE")) {
lexer.nextToken();
MySqlShowProcedureCodeStatement stmt = new MySqlShowProcedureCodeStatement();
stmt.setName(this.exprParser.name());
return stmt;
}
acceptIdentifier(STATUS);
MySqlShowProcedureStatusStatement stmt = new MySqlShowProcedureStatusStatement();
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
stmt.setLike(this.exprParser.expr());
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
stmt.setWhere(this.exprParser.expr());
}
return stmt;
}
if (identifierEquals("PROCESSLIST")) {
lexer.nextToken();
MySqlShowProcessListStatement stmt = new MySqlShowProcessListStatement();
return stmt;
}
if (identifierEquals("PROFILES")) {
lexer.nextToken();
MySqlShowProfilesStatement stmt = new MySqlShowProfilesStatement();
return stmt;
}
if (identifierEquals("PROFILE")) {
lexer.nextToken();
MySqlShowProfileStatement stmt = new MySqlShowProfileStatement();
for (; ; ) {
if (lexer.token() == Token.ALL) {
stmt.getTypes().add(MySqlShowProfileStatement.Type.ALL);
lexer.nextToken();
} else if (identifierEquals("BLOCK")) {
lexer.nextToken();
acceptIdentifier("IO");
stmt.getTypes().add(MySqlShowProfileStatement.Type.BLOCK_IO);
} else if (identifierEquals("CONTEXT")) {
lexer.nextToken();
acceptIdentifier("SWITCHES");
stmt.getTypes().add(MySqlShowProfileStatement.Type.CONTEXT_SWITCHES);
} else if (identifierEquals("CPU")) {
lexer.nextToken();
stmt.getTypes().add(MySqlShowProfileStatement.Type.CPU);
} else if (identifierEquals("IPC")) {
lexer.nextToken();
stmt.getTypes().add(MySqlShowProfileStatement.Type.IPC);
} else if (identifierEquals("MEMORY")) {
lexer.nextToken();
stmt.getTypes().add(MySqlShowProfileStatement.Type.MEMORY);
} else if (identifierEquals("PAGE")) {
lexer.nextToken();
acceptIdentifier("FAULTS");
stmt.getTypes().add(MySqlShowProfileStatement.Type.PAGE_FAULTS);
} else if (identifierEquals("SOURCE")) {
lexer.nextToken();
stmt.getTypes().add(MySqlShowProfileStatement.Type.SOURCE);
} else if (identifierEquals("SWAPS")) {
lexer.nextToken();
stmt.getTypes().add(MySqlShowProfileStatement.Type.SWAPS);
} else {
break;
}
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
if (lexer.token() == Token.FOR) {
lexer.nextToken();
acceptIdentifier("QUERY");
stmt.setForQuery(this.exprParser.primary());
}
stmt.setLimit(this.exprParser.parseLimit());
return stmt;
}
if (identifierEquals("RELAYLOG")) {
lexer.nextToken();
acceptIdentifier(EVENTS);
MySqlShowRelayLogEventsStatement stmt = new MySqlShowRelayLogEventsStatement();
if (lexer.token() == Token.IN) {
lexer.nextToken();
stmt.setLogName(this.exprParser.primary());
}
if (lexer.token() == Token.FROM) {
lexer.nextToken();
stmt.setFrom(this.exprParser.primary());
}
stmt.setLimit(this.exprParser.parseLimit());
return stmt;
}
if (identifierEquals("RELAYLOG")) {
lexer.nextToken();
acceptIdentifier(EVENTS);
MySqlShowRelayLogEventsStatement stmt = new MySqlShowRelayLogEventsStatement();
if (lexer.token() == Token.IN) {
lexer.nextToken();
stmt.setLogName(this.exprParser.primary());
}
if (lexer.token() == Token.FROM) {
lexer.nextToken();
stmt.setFrom(this.exprParser.primary());
}
stmt.setLimit(this.exprParser.parseLimit());
return stmt;
}
if (identifierEquals("SLAVE")) {
lexer.nextToken();
if (identifierEquals(STATUS)) {
lexer.nextToken();
return new MySqlShowSlaveStatusStatement();
} else {
acceptIdentifier("HOSTS");
MySqlShowSlaveHostsStatement stmt = new MySqlShowSlaveHostsStatement();
return stmt;
}
}
if (lexer.token() == Token.TABLE) {
lexer.nextToken();
acceptIdentifier(STATUS);
MySqlShowTableStatusStatement stmt = new MySqlShowTableStatusStatement();
if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
lexer.nextToken();
stmt.setDatabase(this.exprParser.name());
}
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
stmt.setLike(this.exprParser.expr());
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
stmt.setWhere(this.exprParser.expr());
}
return stmt;
}
if (identifierEquals("TRIGGERS")) {
lexer.nextToken();
MySqlShowTriggersStatement stmt = new MySqlShowTriggersStatement();
if (lexer.token() == Token.FROM) {
lexer.nextToken();
SQLName database = exprParser.name();
stmt.setDatabase(database);
}
if (lexer.token() == Token.LIKE) {
lexer.nextToken();
SQLExpr like = exprParser.expr();
stmt.setLike(like);
}
if (lexer.token() == Token.WHERE) {
lexer.nextToken();
SQLExpr where = exprParser.expr();
stmt.setWhere(where);
}
return stmt;
}
// MySqlShowSlaveHostsStatement
throw new ParserException("TODO " + lexer.stringVal());
}
Aggregations