use of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement 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.dialect.mysql.ast.statement.MySqlUnlockTablesStatement in project druid by alibaba.
the class MySqlASTVisitorAdapterTest method test_adapter.
public void test_adapter() throws Exception {
MySqlASTVisitorAdapter adapter = new MySqlASTVisitorAdapter();
new SQLBooleanExpr().accept(adapter);
new SQLLimit().accept(adapter);
new MySqlTableIndex().accept(adapter);
new MySqlKey().accept(adapter);
new MySqlPrimaryKey().accept(adapter);
new MySqlIntervalExpr().accept(adapter);
new SQLBinaryExpr().accept(adapter);
new MySqlPrepareStatement().accept(adapter);
new MySqlExecuteStatement().accept(adapter);
new MysqlDeallocatePrepareStatement().accept(adapter);
new MySqlDeleteStatement().accept(adapter);
new MySqlInsertStatement().accept(adapter);
new MySqlLoadXmlStatement().accept(adapter);
new MySqlReplaceStatement().accept(adapter);
new SQLStartTransactionStatement().accept(adapter);
new MySqlRollbackStatement().accept(adapter);
new MySqlShowColumnsStatement().accept(adapter);
new MySqlShowDatabasesStatement().accept(adapter);
new MySqlShowWarningsStatement().accept(adapter);
new MySqlShowStatusStatement().accept(adapter);
new CobarShowStatus().accept(adapter);
new MySqlKillStatement().accept(adapter);
new MySqlBinlogStatement().accept(adapter);
new MySqlResetStatement().accept(adapter);
new UserSpecification().accept(adapter);
new MySqlPartitionByKey().accept(adapter);
new MySqlOutFileExpr().accept(adapter);
new MySqlUpdateStatement().accept(adapter);
new MySqlSetTransactionStatement().accept(adapter);
new MySqlSetNamesStatement().accept(adapter);
new MySqlShowMasterLogsStatement().accept(adapter);
new MySqlSetCharSetStatement().accept(adapter);
new MySqlShowAuthorsStatement().accept(adapter);
new MySqlShowCollationStatement().accept(adapter);
new MySqlShowBinLogEventsStatement().accept(adapter);
new MySqlShowCharacterSetStatement().accept(adapter);
new MySqlShowContributorsStatement().accept(adapter);
new MySqlShowCreateDatabaseStatement().accept(adapter);
new MySqlShowCreateEventStatement().accept(adapter);
new MySqlShowCreateFunctionStatement().accept(adapter);
new MySqlShowCreateProcedureStatement().accept(adapter);
new MySqlShowCreateTableStatement().accept(adapter);
new MySqlShowCreateTriggerStatement().accept(adapter);
new MySqlShowCreateViewStatement().accept(adapter);
new MySqlShowEngineStatement().accept(adapter);
new MySqlShowEnginesStatement().accept(adapter);
new MySqlShowErrorsStatement().accept(adapter);
new MySqlShowEventsStatement().accept(adapter);
new MySqlShowFunctionCodeStatement().accept(adapter);
new MySqlShowFunctionStatusStatement().accept(adapter);
new MySqlShowGrantsStatement().accept(adapter);
new MySqlUserName().accept(adapter);
new MySqlShowIndexesStatement().accept(adapter);
new MySqlShowKeysStatement().accept(adapter);
new MySqlShowMasterStatusStatement().accept(adapter);
new MySqlShowOpenTablesStatement().accept(adapter);
new MySqlShowBinaryLogsStatement().accept(adapter);
new MySqlShowPluginsStatement().accept(adapter);
new MySqlShowPrivilegesStatement().accept(adapter);
new MySqlShowProcedureCodeStatement().accept(adapter);
new MySqlShowProcedureStatusStatement().accept(adapter);
new MySqlShowProcessListStatement().accept(adapter);
new MySqlShowProfileStatement().accept(adapter);
new MySqlShowSlaveHostsStatement().accept(adapter);
new MySqlShowRelayLogEventsStatement().accept(adapter);
new MySqlShowSlaveStatusStatement().accept(adapter);
new MySqlShowTableStatusStatement().accept(adapter);
new MySqlShowTriggersStatement().accept(adapter);
new MySqlRenameTableStatement().accept(adapter);
new MySqlUnionQuery().accept(adapter);
new MySqlUseIndexHint().accept(adapter);
new MySqlIgnoreIndexHint().accept(adapter);
new MySqlLockTableStatement().accept(adapter);
new MySqlUnlockTablesStatement().accept(adapter);
new MySqlForceIndexHint().accept(adapter);
new MySqlAlterTableChangeColumn().accept(adapter);
new MySqlAlterTableCharacter().accept(adapter);
new MySqlAlterTableOption().accept(adapter);
new MySqlCreateTableStatement().accept(adapter);
new MySqlCharExpr().accept(adapter);
new MySqlUnique().accept(adapter);
new MySqlAlterTableModifyColumn().accept(adapter);
new MySqlAlterTableDiscardTablespace().accept(adapter);
new MySqlAlterTableImportTablespace().accept(adapter);
new TableSpaceOption().accept(adapter);
}
use of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement in project druid by alibaba.
the class MySQLLockTableTest method testUnlockTables.
public void testUnlockTables() {
String stmt1 = "unlock tables";
String stmt2 = "unlock table";
MySqlStatementParser parser1 = new MySqlStatementParser(stmt1);
MySqlStatementParser parser2 = new MySqlStatementParser(stmt2);
MySqlUnlockTablesStatement statment1 = (MySqlUnlockTablesStatement) parser1.parseStatement();
MySqlUnlockTablesStatement statment2 = (MySqlUnlockTablesStatement) parser2.parseStatement();
Assert.assertTrue(true);
}
Aggregations