use of com.alibaba.cobar.parser.recognizer.mysql.syntax.MySQLDMLReplaceParser in project cobar by alibaba.
the class SQLParserDelegate method parse.
public static SQLStatement parse(String sql, MySQLLexer lexer, String charset) throws SQLSyntaxErrorException {
try {
SQLStatement stmt = null;
boolean isEOF = true;
MySQLExprParser exprParser = new MySQLExprParser(lexer, charset);
stmtSwitch: switch(lexer.token()) {
case KW_DESC:
case KW_DESCRIBE:
stmt = new MySQLDALParser(lexer, exprParser).desc();
break stmtSwitch;
case KW_SELECT:
case PUNC_LEFT_PAREN:
stmt = new MySQLDMLSelectParser(lexer, exprParser).selectUnion();
break stmtSwitch;
case KW_DELETE:
stmt = new MySQLDMLDeleteParser(lexer, exprParser).delete();
break stmtSwitch;
case KW_INSERT:
stmt = new MySQLDMLInsertParser(lexer, exprParser).insert();
break stmtSwitch;
case KW_REPLACE:
stmt = new MySQLDMLReplaceParser(lexer, exprParser).replace();
break stmtSwitch;
case KW_UPDATE:
stmt = new MySQLDMLUpdateParser(lexer, exprParser).update();
break stmtSwitch;
case KW_CALL:
stmt = new MySQLDMLCallParser(lexer, exprParser).call();
break stmtSwitch;
case KW_SET:
stmt = new MySQLDALParser(lexer, exprParser).set();
break stmtSwitch;
case KW_SHOW:
stmt = new MySQLDALParser(lexer, exprParser).show();
break stmtSwitch;
case KW_ALTER:
case KW_CREATE:
case KW_DROP:
case KW_RENAME:
stmt = new MySQLDDLParser(lexer, exprParser).ddlStmt();
isEOF = isEOFedDDL(stmt);
break stmtSwitch;
case KW_RELEASE:
stmt = new MySQLMTSParser(lexer).release();
break stmtSwitch;
case IDENTIFIER:
SpecialIdentifier si = null;
if ((si = specialIdentifiers.get(lexer.stringValueUppercase())) != null) {
switch(si) {
case TRUNCATE:
stmt = new MySQLDDLParser(lexer, exprParser).truncate();
break stmtSwitch;
case SAVEPOINT:
stmt = new MySQLMTSParser(lexer).savepoint();
break stmtSwitch;
case ROLLBACK:
stmt = new MySQLMTSParser(lexer).rollback();
break stmtSwitch;
}
}
default:
throw new SQLSyntaxErrorException("sql is not a supported statement");
}
if (isEOF) {
while (lexer.token() == MySQLToken.PUNC_SEMICOLON) {
lexer.nextToken();
}
if (lexer.token() != MySQLToken.EOF) {
throw new SQLSyntaxErrorException("SQL syntax error!");
}
}
return stmt;
} catch (Exception e) {
throw new SQLSyntaxErrorException(buildErrorMsg(e, lexer, sql), e);
}
}
Aggregations