diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java index 523195468c..f871d0f6fe 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlStatementParser.java @@ -17,6 +17,7 @@ package com.alibaba.druid.sql.dialect.mysql.parser; import java.util.List; +import com.alibaba.druid.bvt.sql.mysql.Kill_Test; import com.alibaba.druid.sql.ast.SQLExpr; import com.alibaba.druid.sql.ast.SQLName; import com.alibaba.druid.sql.ast.SQLOrderBy; @@ -57,816 +58,821 @@ import com.alibaba.druid.sql.parser.Token; public class MySqlStatementParser extends SQLStatementParser { - public MySqlStatementParser(String sql) throws ParserException{ - this(new MySqlLexer(sql)); - this.lexer.nextToken(); - } - - public MySqlStatementParser(Lexer lexer){ - super(lexer); - } - - protected SQLExprParser createExprParser() { - return new MySqlExprParser(lexer); - } - - public SQLCreateTableStatement parseCreateTable() throws ParserException { - MySqlCreateTableParser parser = new MySqlCreateTableParser(lexer); - return parser.parseCrateTable(); - } - - public SQLSelectStatement parseSelect() throws ParserException { - return new SQLSelectStatement(new MySqlSelectParser(lexer).select()); - } - - public SQLDeleteStatement parseDeleteStatement() throws ParserException { - accept(Token.DELETE); - - MySqlDeleteStatement deleteStatement = new MySqlDeleteStatement(); - - if (identifierEquals("LOW_PRIORITY")) { - deleteStatement.setLowPriority(true); - lexer.nextToken(); - } - - if (identifierEquals("QUICK")) { - deleteStatement.setQuick(true); - lexer.nextToken(); - } - - if (identifierEquals("IGNORE")) { - deleteStatement.setIgnore(true); - lexer.nextToken(); - } - - if (lexer.token() == Token.IDENTIFIER) { - exprParser.names(deleteStatement.getTableNames()); - - if (lexer.token() == Token.FROM) { - lexer.nextToken(); - SQLTableSource tableSource = createSQLSelectParser().parseTableSource(); - deleteStatement.setFrom(tableSource); - } - } else { - if (lexer.token() == Token.FROM) { - lexer.nextToken(); - } - exprParser.names(deleteStatement.getTableNames()); - } - - if (identifierEquals("USING")) { - lexer.nextToken(); - - SQLTableSource tableSource = createSQLSelectParser().parseTableSource(); - deleteStatement.setUsing(tableSource); - } - - if (lexer.token() == (Token.WHERE)) { - lexer.nextToken(); - SQLExpr where = this.exprParser.expr(); - deleteStatement.setWhere(where); - } - - if (lexer.token() == (Token.ORDER)) { - SQLOrderBy orderBy = exprParser.parseOrderBy(); - deleteStatement.setOrderBy(orderBy); - } - - if (lexer.token() == Token.LIMIT) { - lexer.nextToken(); - - MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit(); - SQLExpr rowCount = exprParser.expr(); - limit.setRowCount(rowCount); - - deleteStatement.setLimit(limit); - } - - return deleteStatement; - } - - public SQLStatement parseCreate() throws ParserException { - accept(Token.CREATE); - - if (lexer.token() == Token.TABLE || identifierEquals("TEMPORARY")) { - MySqlCreateTableParser parser = new MySqlCreateTableParser(lexer); - return parser.parseCrateTable(false); - } - - throw new ParserException("TODO " + lexer.token()); - } - - 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 { - throw new ParserException("not support kill type " + lexer.token()); - } - - SQLExpr threadId = this.exprParser.expr(); - stmt.setThreadId(threadId); - - return stmt; - } - - public SQLStatement parseBinlog() { - acceptIdentifier("binlog"); - - MySqlBinlogStatement stmt = new MySqlBinlogStatement(); - - SQLExpr expr = this.exprParser.expr(); - stmt.setExpr(expr); - - return stmt; - } - - public boolean parseStatementListDialect(List 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("LOAD")) { - SQLStatement stmt = parseLoad(); - statementList.add(stmt); - return true; - } - - if (identifierEquals("REPLACE")) { - MySqlReplicateStatement stmt = parseReplicate(); - statementList.add(stmt); - return true; - } - - if (identifierEquals("START")) { - MySqlStartTransactionStatement stmt = parseStart(); - statementList.add(stmt); - return true; - } - - if (identifierEquals("COMMIT")) { - MySqlCommitStatement stmt = parseCommit(); - statementList.add(stmt); - return true; - } - - if (identifierEquals("ROLLBACK")) { - MySqlRollbackStatement stmt = parseRollback(); - statementList.add(stmt); - return true; - } - - if (identifierEquals("SHOW")) { - SQLStatement stmt = parseShow(); - statementList.add(stmt); - return true; - } - - if (identifierEquals("BINLOG")) { - SQLStatement stmt = parseBinlog(); - statementList.add(stmt); - return true; - } - - return false; - } - - public SQLStatement parseShow() throws ParserException { - acceptIdentifier("SHOW"); - - if (identifierEquals("FULL")) { - lexer.nextToken(); - acceptIdentifier("COLUMNS"); - - MySqlShowColumnsStatement stmt = parseShowColumns(); - stmt.setFull(true); - - return stmt; - } - - if (identifierEquals("COLUMNS")) { - lexer.nextToken(); - - MySqlShowColumnsStatement stmt = parseShowColumns(); - - return stmt; - } - - if (identifierEquals("TABLES")) { - lexer.nextToken(); - - MySqlShowTablesStatement stmt = parseShowTabless(); - - 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); - acceptIdentifier("WARNINGS"); - - MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement(); - stmt.setCount(true); - - return stmt; - } - - if (identifierEquals("STATUS")) { - lexer.nextToken(); - - MySqlShowStatusStatement stmt = parseShowStatus(); - - return stmt; - } - - if (identifierEquals("GLOBAL")) { - lexer.nextToken(); - - if (identifierEquals("STATUS")) { - lexer.nextToken(); - MySqlShowStatusStatement stmt = parseShowStatus(); - 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("COBAR_STATUS")) { - lexer.nextToken(); - return new CobarShowStatus(); - } + public MySqlStatementParser(String sql) throws ParserException { + this(new MySqlLexer(sql)); + this.lexer.nextToken(); + } + + public MySqlStatementParser(Lexer lexer) { + super(lexer); + } + + protected SQLExprParser createExprParser() { + return new MySqlExprParser(lexer); + } + + public SQLCreateTableStatement parseCreateTable() throws ParserException { + MySqlCreateTableParser parser = new MySqlCreateTableParser(lexer); + return parser.parseCrateTable(); + } + + public SQLSelectStatement parseSelect() throws ParserException { + return new SQLSelectStatement(new MySqlSelectParser(lexer).select()); + } + + public SQLDeleteStatement parseDeleteStatement() throws ParserException { + accept(Token.DELETE); + + MySqlDeleteStatement deleteStatement = new MySqlDeleteStatement(); + + if (identifierEquals("LOW_PRIORITY")) { + deleteStatement.setLowPriority(true); + lexer.nextToken(); + } + + if (identifierEquals("QUICK")) { + deleteStatement.setQuick(true); + lexer.nextToken(); + } + + if (identifierEquals("IGNORE")) { + deleteStatement.setIgnore(true); + lexer.nextToken(); + } + + if (lexer.token() == Token.IDENTIFIER) { + exprParser.names(deleteStatement.getTableNames()); + + if (lexer.token() == Token.FROM) { + lexer.nextToken(); + SQLTableSource tableSource = createSQLSelectParser() + .parseTableSource(); + deleteStatement.setFrom(tableSource); + } + } else { + if (lexer.token() == Token.FROM) { + lexer.nextToken(); + } + exprParser.names(deleteStatement.getTableNames()); + } + + if (identifierEquals("USING")) { + lexer.nextToken(); + + SQLTableSource tableSource = createSQLSelectParser() + .parseTableSource(); + deleteStatement.setUsing(tableSource); + } + + if (lexer.token() == (Token.WHERE)) { + lexer.nextToken(); + SQLExpr where = this.exprParser.expr(); + deleteStatement.setWhere(where); + } + + if (lexer.token() == (Token.ORDER)) { + SQLOrderBy orderBy = exprParser.parseOrderBy(); + deleteStatement.setOrderBy(orderBy); + } + + if (lexer.token() == Token.LIMIT) { + lexer.nextToken(); + + MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit(); + SQLExpr rowCount = exprParser.expr(); + limit.setRowCount(rowCount); + + deleteStatement.setLimit(limit); + } + + return deleteStatement; + } + + public SQLStatement parseCreate() throws ParserException { + accept(Token.CREATE); + + if (lexer.token() == Token.TABLE || identifierEquals("TEMPORARY")) { + MySqlCreateTableParser parser = new MySqlCreateTableParser(lexer); + return parser.parseCrateTable(false); + } + + throw new ParserException("TODO " + lexer.token()); + } + + 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 { + throw new ParserException("not support kill type " + lexer.token()); + } + + SQLExpr threadId = this.exprParser.expr(); + stmt.setThreadId(threadId); + + return stmt; + } + + public SQLStatement parseBinlog() { + acceptIdentifier("binlog"); + + MySqlBinlogStatement stmt = new MySqlBinlogStatement(); + + SQLExpr expr = this.exprParser.expr(); + stmt.setExpr(expr); + + return stmt; + } + + public boolean parseStatementListDialect(List 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; + } - throw new ParserException("TODO"); - } + if (identifierEquals("LOAD")) { + SQLStatement stmt = parseLoad(); + statementList.add(stmt); + return true; + } - private MySqlShowStatusStatement parseShowStatus() throws ParserException { - MySqlShowStatusStatement stmt = new MySqlShowStatusStatement(); + if (identifierEquals("REPLACE")) { + MySqlReplicateStatement stmt = parseReplicate(); + statementList.add(stmt); + return true; + } - 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; - } - - private MySqlShowWarningsStatement parseShowWarnings() throws ParserException { - MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement(); - - if (lexer.token() == Token.LIMIT) { - lexer.nextToken(); - - MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit(); - - SQLExpr temp = this.createExprParser().expr(); - if (lexer.token() == (Token.COMMA)) { - limit.setOffset(temp); - lexer.nextToken(); - limit.setRowCount(createExprParser().expr()); - } else if (identifierEquals("OFFSET")) { - limit.setRowCount(temp); - lexer.nextToken(); - limit.setOffset(createExprParser().expr()); - } else { - limit.setRowCount(temp); - } - - stmt.setLimit(limit); - } - - return stmt; - } - - private MySqlShowDatabasesStatement parseShowDatabases() throws ParserException { - MySqlShowDatabasesStatement stmt = new MySqlShowDatabasesStatement(); - - 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; - } - - private MySqlShowTablesStatement parseShowTabless() throws ParserException { - MySqlShowTablesStatement stmt = new MySqlShowTablesStatement(); - - 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; - } - - private MySqlShowColumnsStatement parseShowColumns() throws ParserException { - MySqlShowColumnsStatement stmt = new MySqlShowColumnsStatement(); - - if (lexer.token() == Token.FROM) { - lexer.nextToken(); - SQLName table = exprParser.name(); - stmt.setTable(table); - - 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; - } - - public MySqlStartTransactionStatement parseStart() throws ParserException { - acceptIdentifier("START"); - acceptIdentifier("TRANSACTION"); - - MySqlStartTransactionStatement stmt = new MySqlStartTransactionStatement(); - - if (identifierEquals("WITH")) { - lexer.nextToken(); - acceptIdentifier("CONSISTENT"); - acceptIdentifier("SNAPSHOT"); - stmt.setConsistentSnapshot(true); - } - - if (identifierEquals("BEGIN")) { - lexer.nextToken(); - stmt.setBegin(true); - if (identifierEquals("WORK")) { - lexer.nextToken(); - stmt.setWork(true); - } - } - - return stmt; - } - - public MySqlRollbackStatement parseRollback() throws ParserException { - acceptIdentifier("ROLLBACK"); - - MySqlRollbackStatement stmt = new MySqlRollbackStatement(); - - if (identifierEquals("WORK")) { - lexer.nextToken(); - stmt.setWork(true); - } - - if (lexer.token() == Token.AND) { - lexer.nextToken(); - if (lexer.token() == Token.NOT) { - lexer.nextToken(); - acceptIdentifier("CHAIN"); - stmt.setChain(Boolean.FALSE); - } else { - acceptIdentifier("CHAIN"); - stmt.setChain(Boolean.TRUE); - } - } - - return stmt; - } - - public MySqlCommitStatement parseCommit() throws ParserException { - acceptIdentifier("COMMIT"); - - MySqlCommitStatement stmt = new MySqlCommitStatement(); - - if (identifierEquals("WORK")) { - lexer.nextToken(); - stmt.setWork(true); - } - - if (lexer.token() == Token.AND) { - lexer.nextToken(); - if (lexer.token() == Token.NOT) { - lexer.nextToken(); - acceptIdentifier("CHAIN"); - stmt.setChain(Boolean.FALSE); - } else { - acceptIdentifier("CHAIN"); - stmt.setChain(Boolean.TRUE); - } - } - - return stmt; - } - - public MySqlReplicateStatement parseReplicate() throws ParserException { - MySqlReplicateStatement stmt = new MySqlReplicateStatement(); - - acceptIdentifier("REPLACE"); - - if (identifierEquals("LOW_PRIORITY")) { - stmt.setLowPriority(true); - lexer.nextToken(); - } - - if (identifierEquals("DELAYED")) { - stmt.setDelayed(true); - lexer.nextToken(); - } - - if (lexer.token() == Token.INTO) { - lexer.nextToken(); - } - - SQLName tableName = exprParser.name(); - stmt.setTableName(tableName); - - if (lexer.token() == Token.VALUES || identifierEquals("VALUE")) { - lexer.nextToken(); - - for (;;) { - accept(Token.LPAREN); - SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause(); - this.exprParser.exprList(values.getValues()); - stmt.getValuesList().add(values); - accept(Token.RPAREN); - - if (lexer.token() == Token.COMMA) { - lexer.nextToken(); - continue; - } else { - break; - } - } - } else if (lexer.token() == Token.SELECT) { - SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr(); - stmt.setQuery(queryExpr); - } else if (lexer.token() == Token.SET) { - lexer.nextToken(); - for (;;) { - SQLUpdateSetItem item = new SQLUpdateSetItem(); - item.setColumn(this.exprParser.name()); - accept(Token.EQ); - item.setValue(this.exprParser.expr()); - - stmt.getSetItems().add(item); - - if (lexer.token() == (Token.COMMA)) { - lexer.nextToken(); - continue; - } - - break; - } - } - - return stmt; - } - - protected SQLStatement parseLoad() throws ParserException { - acceptIdentifier("LOAD"); - - if (identifierEquals("DATA")) { - SQLStatement stmt = parseLoadDataInFile(); - return stmt; - } - - if (identifierEquals("XML")) { - SQLStatement stmt = parseLoadXml(); - return stmt; - } - - throw new ParserException("TODO"); - } - - protected MySqlLoadXmlStatement parseLoadXml() throws ParserException { - acceptIdentifier("XML"); - - MySqlLoadXmlStatement stmt = new MySqlLoadXmlStatement(); - - if (identifierEquals("LOW_PRIORITY")) { - stmt.setLowPriority(true); - lexer.nextToken(); - } - - if (identifierEquals("CONCURRENT")) { - stmt.setConcurrent(true); - lexer.nextToken(); - } - - if (identifierEquals("LOCAL")) { - stmt.setLocal(true); - lexer.nextToken(); - } - - acceptIdentifier("INFILE"); - - SQLLiteralExpr fileName = (SQLLiteralExpr) exprParser.expr(); - stmt.setFileName(fileName); - - if (identifierEquals("REPLACE")) { - stmt.setReplicate(true); - lexer.nextToken(); - } - - if (identifierEquals("IGNORE")) { - stmt.setIgnore(true); - lexer.nextToken(); - } - - accept(Token.INTO); - accept(Token.TABLE); - - SQLName tableName = exprParser.name(); - stmt.setTableName(tableName); - - if (identifierEquals("CHARACTER")) { - lexer.nextToken(); - accept(Token.SET); - - if (lexer.token() != Token.LITERAL_CHARS) { - throw new ParserException("syntax error, illegal charset"); - } - - String charset = lexer.stringVal(); - lexer.nextToken(); - stmt.setCharset(charset); - } - - if (identifierEquals("ROWS")) { - lexer.nextToken(); - acceptIdentifier("IDENTIFIED"); - accept(Token.BY); - SQLExpr rowsIdentifiedBy = exprParser.expr(); - stmt.setRowsIdentifiedBy(rowsIdentifiedBy); - } + if (identifierEquals("START")) { + MySqlStartTransactionStatement stmt = parseStart(); + statementList.add(stmt); + return true; + } - if (identifierEquals("IGNORE")) { - throw new ParserException("TODO"); - } + if (identifierEquals("COMMIT")) { + MySqlCommitStatement stmt = parseCommit(); + statementList.add(stmt); + return true; + } - if (lexer.token() == Token.SET) { - throw new ParserException("TODO"); - } + if (identifierEquals("ROLLBACK")) { + MySqlRollbackStatement stmt = parseRollback(); + statementList.add(stmt); + return true; + } - return stmt; - } + if (identifierEquals("SHOW")) { + SQLStatement stmt = parseShow(); + statementList.add(stmt); + return true; + } - protected MySqlLoadDataInFileStatement parseLoadDataInFile() throws ParserException { - acceptIdentifier("DATA"); + if (identifierEquals("BINLOG")) { + SQLStatement stmt = parseBinlog(); + statementList.add(stmt); + return true; + } - MySqlLoadDataInFileStatement stmt = new MySqlLoadDataInFileStatement(); + return false; + } - if (identifierEquals("LOW_PRIORITY")) { - stmt.setLowPriority(true); - lexer.nextToken(); - } + public SQLStatement parseShow() throws ParserException { + acceptIdentifier("SHOW"); - if (identifierEquals("CONCURRENT")) { - stmt.setConcurrent(true); - lexer.nextToken(); - } + if (identifierEquals("FULL")) { + lexer.nextToken(); + acceptIdentifier("COLUMNS"); - if (identifierEquals("LOCAL")) { - stmt.setLocal(true); - lexer.nextToken(); - } + MySqlShowColumnsStatement stmt = parseShowColumns(); + stmt.setFull(true); + + return stmt; + } + + if (identifierEquals("COLUMNS")) { + lexer.nextToken(); - acceptIdentifier("INFILE"); + MySqlShowColumnsStatement stmt = parseShowColumns(); - SQLLiteralExpr fileName = (SQLLiteralExpr) exprParser.expr(); - stmt.setFileName(fileName); + return stmt; + } - if (identifierEquals("REPLACE")) { - stmt.setReplicate(true); - lexer.nextToken(); - } + if (identifierEquals("TABLES")) { + lexer.nextToken(); - if (identifierEquals("IGNORE")) { - stmt.setIgnore(true); - lexer.nextToken(); - } + MySqlShowTablesStatement stmt = parseShowTabless(); - accept(Token.INTO); - accept(Token.TABLE); + 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); + acceptIdentifier("WARNINGS"); + + MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement(); + stmt.setCount(true); + + return stmt; + } + + if (identifierEquals("STATUS")) { + lexer.nextToken(); - SQLName tableName = exprParser.name(); - stmt.setTableName(tableName); + MySqlShowStatusStatement stmt = parseShowStatus(); + + return stmt; + } - if (identifierEquals("CHARACTER")) { - lexer.nextToken(); - accept(Token.SET); + if (identifierEquals("GLOBAL")) { + lexer.nextToken(); + + if (identifierEquals("STATUS")) { + lexer.nextToken(); + MySqlShowStatusStatement stmt = parseShowStatus(); + stmt.setGlobal(true); + return stmt; + } + } - if (lexer.token() != Token.LITERAL_CHARS) { - throw new ParserException("syntax error, illegal charset"); - } + if (identifierEquals("SESSION")) { + lexer.nextToken(); + + if (identifierEquals("STATUS")) { + lexer.nextToken(); + MySqlShowStatusStatement stmt = parseShowStatus(); + stmt.setSession(true); + return stmt; + } + } - String charset = lexer.stringVal(); - lexer.nextToken(); - stmt.setCharset(charset); - } + if (identifierEquals("COBAR_STATUS")) { + lexer.nextToken(); + return new CobarShowStatus(); + } - if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) { - throw new ParserException("TODO"); - } - - if (identifierEquals("LINES")) { - throw new ParserException("TODO"); - } + throw new ParserException("TODO"); + } - if (identifierEquals("IGNORE")) { - throw new ParserException("TODO"); - } - - if (lexer.token() == Token.SET) { - throw new ParserException("TODO"); - } - - return stmt; - } - - public MySqlPrepareStatement parsePrepare() throws ParserException { - acceptIdentifier("PREPARE"); - - SQLName name = exprParser.name(); - accept(Token.FROM); - SQLExpr from = exprParser.expr(); - - return new MySqlPrepareStatement(name, from); - } - - public MySqlExecuteStatement parseExecute() throws ParserException { - acceptIdentifier("EXECUTE"); + private MySqlShowStatusStatement parseShowStatus() throws ParserException { + MySqlShowStatusStatement stmt = new MySqlShowStatusStatement(); - MySqlExecuteStatement stmt = new MySqlExecuteStatement(); + 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; + } + + private MySqlShowWarningsStatement parseShowWarnings() + throws ParserException { + MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement(); + + if (lexer.token() == Token.LIMIT) { + lexer.nextToken(); + + MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit(); + + SQLExpr temp = this.createExprParser().expr(); + if (lexer.token() == (Token.COMMA)) { + limit.setOffset(temp); + lexer.nextToken(); + limit.setRowCount(createExprParser().expr()); + } else if (identifierEquals("OFFSET")) { + limit.setRowCount(temp); + lexer.nextToken(); + limit.setOffset(createExprParser().expr()); + } else { + limit.setRowCount(temp); + } + + stmt.setLimit(limit); + } + + return stmt; + } + + private MySqlShowDatabasesStatement parseShowDatabases() + throws ParserException { + MySqlShowDatabasesStatement stmt = new MySqlShowDatabasesStatement(); + + 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; + } + + private MySqlShowTablesStatement parseShowTabless() throws ParserException { + MySqlShowTablesStatement stmt = new MySqlShowTablesStatement(); + + 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; + } + + private MySqlShowColumnsStatement parseShowColumns() throws ParserException { + MySqlShowColumnsStatement stmt = new MySqlShowColumnsStatement(); + + if (lexer.token() == Token.FROM) { + lexer.nextToken(); + SQLName table = exprParser.name(); + stmt.setTable(table); + + 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; + } + + public MySqlStartTransactionStatement parseStart() throws ParserException { + acceptIdentifier("START"); + acceptIdentifier("TRANSACTION"); + + MySqlStartTransactionStatement stmt = new MySqlStartTransactionStatement(); + + if (identifierEquals("WITH")) { + lexer.nextToken(); + acceptIdentifier("CONSISTENT"); + acceptIdentifier("SNAPSHOT"); + stmt.setConsistentSnapshot(true); + } + + if (identifierEquals("BEGIN")) { + lexer.nextToken(); + stmt.setBegin(true); + if (identifierEquals("WORK")) { + lexer.nextToken(); + stmt.setWork(true); + } + } + + return stmt; + } + + public MySqlRollbackStatement parseRollback() throws ParserException { + acceptIdentifier("ROLLBACK"); + + MySqlRollbackStatement stmt = new MySqlRollbackStatement(); + + if (identifierEquals("WORK")) { + lexer.nextToken(); + stmt.setWork(true); + } + + if (lexer.token() == Token.AND) { + lexer.nextToken(); + if (lexer.token() == Token.NOT) { + lexer.nextToken(); + acceptIdentifier("CHAIN"); + stmt.setChain(Boolean.FALSE); + } else { + acceptIdentifier("CHAIN"); + stmt.setChain(Boolean.TRUE); + } + } + + return stmt; + } + + public MySqlCommitStatement parseCommit() throws ParserException { + acceptIdentifier("COMMIT"); + + MySqlCommitStatement stmt = new MySqlCommitStatement(); + + if (identifierEquals("WORK")) { + lexer.nextToken(); + stmt.setWork(true); + } + + if (lexer.token() == Token.AND) { + lexer.nextToken(); + if (lexer.token() == Token.NOT) { + lexer.nextToken(); + acceptIdentifier("CHAIN"); + stmt.setChain(Boolean.FALSE); + } else { + acceptIdentifier("CHAIN"); + stmt.setChain(Boolean.TRUE); + } + } + + return stmt; + } + + public MySqlReplicateStatement parseReplicate() throws ParserException { + MySqlReplicateStatement stmt = new MySqlReplicateStatement(); + + acceptIdentifier("REPLACE"); + + if (identifierEquals("LOW_PRIORITY")) { + stmt.setLowPriority(true); + lexer.nextToken(); + } + + if (identifierEquals("DELAYED")) { + stmt.setDelayed(true); + lexer.nextToken(); + } + + if (lexer.token() == Token.INTO) { + lexer.nextToken(); + } + + SQLName tableName = exprParser.name(); + stmt.setTableName(tableName); + + if (lexer.token() == Token.VALUES || identifierEquals("VALUE")) { + lexer.nextToken(); + + for (;;) { + accept(Token.LPAREN); + SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause(); + this.exprParser.exprList(values.getValues()); + stmt.getValuesList().add(values); + accept(Token.RPAREN); + + if (lexer.token() == Token.COMMA) { + lexer.nextToken(); + continue; + } else { + break; + } + } + } else if (lexer.token() == Token.SELECT) { + SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr(); + stmt.setQuery(queryExpr); + } else if (lexer.token() == Token.SET) { + lexer.nextToken(); + for (;;) { + SQLUpdateSetItem item = new SQLUpdateSetItem(); + item.setColumn(this.exprParser.name()); + accept(Token.EQ); + item.setValue(this.exprParser.expr()); + + stmt.getSetItems().add(item); + + if (lexer.token() == (Token.COMMA)) { + lexer.nextToken(); + continue; + } + + break; + } + } + + return stmt; + } + + protected SQLStatement parseLoad() throws ParserException { + acceptIdentifier("LOAD"); + + if (identifierEquals("DATA")) { + SQLStatement stmt = parseLoadDataInFile(); + return stmt; + } + + if (identifierEquals("XML")) { + SQLStatement stmt = parseLoadXml(); + return stmt; + } + + throw new ParserException("TODO"); + } + + protected MySqlLoadXmlStatement parseLoadXml() throws ParserException { + acceptIdentifier("XML"); + + MySqlLoadXmlStatement stmt = new MySqlLoadXmlStatement(); + + if (identifierEquals("LOW_PRIORITY")) { + stmt.setLowPriority(true); + lexer.nextToken(); + } + + if (identifierEquals("CONCURRENT")) { + stmt.setConcurrent(true); + lexer.nextToken(); + } + + if (identifierEquals("LOCAL")) { + stmt.setLocal(true); + lexer.nextToken(); + } + + acceptIdentifier("INFILE"); + + SQLLiteralExpr fileName = (SQLLiteralExpr) exprParser.expr(); + stmt.setFileName(fileName); + + if (identifierEquals("REPLACE")) { + stmt.setReplicate(true); + lexer.nextToken(); + } + + if (identifierEquals("IGNORE")) { + stmt.setIgnore(true); + lexer.nextToken(); + } + + accept(Token.INTO); + accept(Token.TABLE); + + SQLName tableName = exprParser.name(); + stmt.setTableName(tableName); + + if (identifierEquals("CHARACTER")) { + lexer.nextToken(); + accept(Token.SET); + + if (lexer.token() != Token.LITERAL_CHARS) { + throw new ParserException("syntax error, illegal charset"); + } + + String charset = lexer.stringVal(); + lexer.nextToken(); + stmt.setCharset(charset); + } + + if (identifierEquals("ROWS")) { + lexer.nextToken(); + acceptIdentifier("IDENTIFIED"); + accept(Token.BY); + SQLExpr rowsIdentifiedBy = exprParser.expr(); + stmt.setRowsIdentifiedBy(rowsIdentifiedBy); + } - SQLName statementName = exprParser.name(); - stmt.setStatementName(statementName); + if (identifierEquals("IGNORE")) { + throw new ParserException("TODO"); + } - if (identifierEquals("USING")) { - lexer.nextToken(); - exprParser.exprList(stmt.getParameters()); - } + if (lexer.token() == Token.SET) { + throw new ParserException("TODO"); + } - return stmt; - } + return stmt; + } - public SQLInsertStatement parseInsert() { - accept(Token.INSERT); + protected MySqlLoadDataInFileStatement parseLoadDataInFile() + throws ParserException { + acceptIdentifier("DATA"); - MySqlInsertStatement insertStatement = new MySqlInsertStatement(); - - if (identifierEquals("LOW_PRIORITY")) { - insertStatement.setLowPriority(true); - lexer.nextToken(); - } - - if (identifierEquals("DELAYED")) { - insertStatement.setDelayed(true); - lexer.nextToken(); - } + MySqlLoadDataInFileStatement stmt = new MySqlLoadDataInFileStatement(); - if (identifierEquals("HIGH_PRIORITY")) { - insertStatement.setHighPriority(true); - lexer.nextToken(); - } + if (identifierEquals("LOW_PRIORITY")) { + stmt.setLowPriority(true); + lexer.nextToken(); + } - if (identifierEquals("IGNORE")) { - insertStatement.setIgnore(true); - lexer.nextToken(); - } - - if (lexer.token() == Token.INTO) { - lexer.nextToken(); - } - - SQLName tableName = this.exprParser.name(); - insertStatement.setTableName(tableName); - - if (lexer.token() == Token.IDENTIFIER) { - insertStatement.setAlias(lexer.stringVal()); - lexer.nextToken(); - } - - if (lexer.token() == (Token.LPAREN)) { - lexer.nextToken(); - this.exprParser.exprList(insertStatement.getColumns()); - accept(Token.RPAREN); - } - - if (lexer.token() == (Token.VALUES)) { - lexer.nextToken(); - - for (;;) { - accept(Token.LPAREN); - SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause(); - this.exprParser.exprList(values.getValues()); - insertStatement.getValuesList().add(values); - accept(Token.RPAREN); - - if (lexer.token() == Token.COMMA) { - lexer.nextToken(); - continue; - } else { - break; - } - } - - } else if (lexer.token() == (Token.SELECT)) { - SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr(); - insertStatement.setQuery(queryExpr.getSubQuery()); - } - - if (lexer.token() == Token.ON) { - lexer.nextToken(); - acceptIdentifier("DUPLICATE"); - accept(Token.KEY); - accept(Token.UPDATE); - - exprParser.exprList(insertStatement.getDuplicateKeyUpdate()); - } - - return insertStatement; - } + if (identifierEquals("CONCURRENT")) { + stmt.setConcurrent(true); + lexer.nextToken(); + } + + if (identifierEquals("LOCAL")) { + stmt.setLocal(true); + lexer.nextToken(); + } + + acceptIdentifier("INFILE"); + + SQLLiteralExpr fileName = (SQLLiteralExpr) exprParser.expr(); + stmt.setFileName(fileName); + + if (identifierEquals("REPLACE")) { + stmt.setReplicate(true); + lexer.nextToken(); + } + + if (identifierEquals("IGNORE")) { + stmt.setIgnore(true); + lexer.nextToken(); + } + + accept(Token.INTO); + accept(Token.TABLE); + + SQLName tableName = exprParser.name(); + stmt.setTableName(tableName); + + if (identifierEquals("CHARACTER")) { + lexer.nextToken(); + accept(Token.SET); + + if (lexer.token() != Token.LITERAL_CHARS) { + throw new ParserException("syntax error, illegal charset"); + } + + String charset = lexer.stringVal(); + lexer.nextToken(); + stmt.setCharset(charset); + } + + if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) { + throw new ParserException("TODO"); + } + + if (identifierEquals("LINES")) { + throw new ParserException("TODO"); + } + + if (identifierEquals("IGNORE")) { + throw new ParserException("TODO"); + } + + if (lexer.token() == Token.SET) { + throw new ParserException("TODO"); + } + + return stmt; + } + + public MySqlPrepareStatement parsePrepare() throws ParserException { + acceptIdentifier("PREPARE"); + + SQLName name = exprParser.name(); + accept(Token.FROM); + SQLExpr from = exprParser.expr(); + + return new MySqlPrepareStatement(name, from); + } + + public MySqlExecuteStatement parseExecute() throws ParserException { + acceptIdentifier("EXECUTE"); + + MySqlExecuteStatement stmt = new MySqlExecuteStatement(); + + SQLName statementName = exprParser.name(); + stmt.setStatementName(statementName); + + if (identifierEquals("USING")) { + lexer.nextToken(); + exprParser.exprList(stmt.getParameters()); + } + + return stmt; + } + + public SQLInsertStatement parseInsert() { + accept(Token.INSERT); + + MySqlInsertStatement insertStatement = new MySqlInsertStatement(); + + if (identifierEquals("LOW_PRIORITY")) { + insertStatement.setLowPriority(true); + lexer.nextToken(); + } + + if (identifierEquals("DELAYED")) { + insertStatement.setDelayed(true); + lexer.nextToken(); + } + + if (identifierEquals("HIGH_PRIORITY")) { + insertStatement.setHighPriority(true); + lexer.nextToken(); + } + + if (identifierEquals("IGNORE")) { + insertStatement.setIgnore(true); + lexer.nextToken(); + } + + if (lexer.token() == Token.INTO) { + lexer.nextToken(); + } + + SQLName tableName = this.exprParser.name(); + insertStatement.setTableName(tableName); + + if (lexer.token() == Token.IDENTIFIER) { + insertStatement.setAlias(lexer.stringVal()); + lexer.nextToken(); + } + + if (lexer.token() == (Token.LPAREN)) { + lexer.nextToken(); + this.exprParser.exprList(insertStatement.getColumns()); + accept(Token.RPAREN); + } + + if (lexer.token() == (Token.VALUES)) { + lexer.nextToken(); + + for (;;) { + accept(Token.LPAREN); + SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause(); + this.exprParser.exprList(values.getValues()); + insertStatement.getValuesList().add(values); + accept(Token.RPAREN); + + if (lexer.token() == Token.COMMA) { + lexer.nextToken(); + continue; + } else { + break; + } + } + + } else if (lexer.token() == (Token.SELECT)) { + SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr(); + insertStatement.setQuery(queryExpr.getSubQuery()); + } + + if (lexer.token() == Token.ON) { + lexer.nextToken(); + acceptIdentifier("DUPLICATE"); + accept(Token.KEY); + accept(Token.UPDATE); + + exprParser.exprList(insertStatement.getDuplicateKeyUpdate()); + } + + return insertStatement; + } } diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitor.java index 0987219f99..5955d51e8c 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitor.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitor.java @@ -47,115 +47,115 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor; public interface MySqlASTVisitor extends SQLASTVisitor { - boolean visit(MySqlBooleanExpr x); + boolean visit(MySqlBooleanExpr x); - void endVisit(MySqlBooleanExpr x); + void endVisit(MySqlBooleanExpr x); - boolean visit(MySqlSelectQueryBlock.Limit x); + boolean visit(MySqlSelectQueryBlock.Limit x); - void endVisit(MySqlSelectQueryBlock.Limit x); + void endVisit(MySqlSelectQueryBlock.Limit x); - boolean visit(MySqlTableIndex x); + boolean visit(MySqlTableIndex x); - void endVisit(MySqlTableIndex x); + void endVisit(MySqlTableIndex x); - boolean visit(MySqlKey x); + boolean visit(MySqlKey x); - void endVisit(MySqlKey x); + void endVisit(MySqlKey x); - boolean visit(MySqlPrimaryKey x); + boolean visit(MySqlPrimaryKey x); - void endVisit(MySqlPrimaryKey x); + void endVisit(MySqlPrimaryKey x); - void endVisit(MySqlIntervalExpr x); + void endVisit(MySqlIntervalExpr x); - boolean visit(MySqlIntervalExpr x); + boolean visit(MySqlIntervalExpr x); - void endVisit(MySqlExtractExpr x); + void endVisit(MySqlExtractExpr x); - boolean visit(MySqlExtractExpr x); + boolean visit(MySqlExtractExpr x); - void endVisit(MySqlMatchAgainstExpr x); + void endVisit(MySqlMatchAgainstExpr x); - boolean visit(MySqlMatchAgainstExpr x); + boolean visit(MySqlMatchAgainstExpr x); - void endVisit(MySqlBinaryExpr x); + void endVisit(MySqlBinaryExpr x); - boolean visit(MySqlBinaryExpr x); + boolean visit(MySqlBinaryExpr x); - void endVisit(MySqlPrepareStatement x); + void endVisit(MySqlPrepareStatement x); - boolean visit(MySqlPrepareStatement x); + boolean visit(MySqlPrepareStatement x); - void endVisit(MySqlExecuteStatement x); + void endVisit(MySqlExecuteStatement x); - boolean visit(MySqlExecuteStatement x); + boolean visit(MySqlExecuteStatement x); - void endVisit(MySqlDeleteStatement x); + void endVisit(MySqlDeleteStatement x); - boolean visit(MySqlDeleteStatement x); + boolean visit(MySqlDeleteStatement x); - void endVisit(MySqlInsertStatement x); + void endVisit(MySqlInsertStatement x); - boolean visit(MySqlInsertStatement x); + boolean visit(MySqlInsertStatement x); - void endVisit(MySqlLoadDataInFileStatement x); + void endVisit(MySqlLoadDataInFileStatement x); - boolean visit(MySqlLoadDataInFileStatement x); + boolean visit(MySqlLoadDataInFileStatement x); - void endVisit(MySqlLoadXmlStatement x); + void endVisit(MySqlLoadXmlStatement x); - boolean visit(MySqlLoadXmlStatement x); + boolean visit(MySqlLoadXmlStatement x); - void endVisit(MySqlReplicateStatement x); + void endVisit(MySqlReplicateStatement x); - boolean visit(MySqlReplicateStatement x); + boolean visit(MySqlReplicateStatement x); - void endVisit(MySqlSelectGroupBy x); + void endVisit(MySqlSelectGroupBy x); - boolean visit(MySqlSelectGroupBy x); + boolean visit(MySqlSelectGroupBy x); - void endVisit(MySqlStartTransactionStatement x); + void endVisit(MySqlStartTransactionStatement x); - boolean visit(MySqlStartTransactionStatement x); + boolean visit(MySqlStartTransactionStatement x); - void endVisit(MySqlCommitStatement x); + void endVisit(MySqlCommitStatement x); - boolean visit(MySqlCommitStatement x); + boolean visit(MySqlCommitStatement x); - void endVisit(MySqlRollbackStatement x); + void endVisit(MySqlRollbackStatement x); - boolean visit(MySqlRollbackStatement x); + boolean visit(MySqlRollbackStatement x); - void endVisit(MySqlShowColumnsStatement x); + void endVisit(MySqlShowColumnsStatement x); - boolean visit(MySqlShowColumnsStatement x); + boolean visit(MySqlShowColumnsStatement x); - void endVisit(MySqlShowTablesStatement x); + void endVisit(MySqlShowTablesStatement x); - boolean visit(MySqlShowTablesStatement x); + boolean visit(MySqlShowTablesStatement x); - void endVisit(MySqlShowDatabasesStatement x); + void endVisit(MySqlShowDatabasesStatement x); - boolean visit(MySqlShowDatabasesStatement x); + boolean visit(MySqlShowDatabasesStatement x); - void endVisit(MySqlShowWarningsStatement x); + void endVisit(MySqlShowWarningsStatement x); - boolean visit(MySqlShowWarningsStatement x); + boolean visit(MySqlShowWarningsStatement x); - void endVisit(MySqlShowStatusStatement x); + void endVisit(MySqlShowStatusStatement x); - boolean visit(MySqlShowStatusStatement x); - - void endVisit(CobarShowStatus x); - - boolean visit(CobarShowStatus x); - - void endVisit(MySqlKillStatement x); - - boolean visit(MySqlKillStatement x); - - void endVisit(MySqlBinlogStatement x); - - boolean visit(MySqlBinlogStatement x); + boolean visit(MySqlShowStatusStatement x); + + void endVisit(CobarShowStatus x); + + boolean visit(CobarShowStatus x); + + void endVisit(MySqlKillStatement x); + + boolean visit(MySqlKillStatement x); + + void endVisit(MySqlBinlogStatement x); + + boolean visit(MySqlBinlogStatement x); } diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitorAdapter.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitorAdapter.java index 9d6475dd1a..64165f645f 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitorAdapter.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlASTVisitorAdapter.java @@ -30,304 +30,305 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionSt import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex; import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter; -public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySqlASTVisitor { +public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements + MySqlASTVisitor { - @Override - public boolean visit(MySqlBooleanExpr x) { - return true; - } + @Override + public boolean visit(MySqlBooleanExpr x) { + return true; + } - @Override - public void endVisit(MySqlBooleanExpr x) { + @Override + public void endVisit(MySqlBooleanExpr x) { - } + } - @Override - public boolean visit(Limit x) { - return true; - } + @Override + public boolean visit(Limit x) { + return true; + } - @Override - public void endVisit(Limit x) { + @Override + public void endVisit(Limit x) { - } + } - @Override - public boolean visit(MySqlTableIndex x) { - return true; - } + @Override + public boolean visit(MySqlTableIndex x) { + return true; + } - @Override - public void endVisit(MySqlTableIndex x) { + @Override + public void endVisit(MySqlTableIndex x) { - } + } - @Override - public boolean visit(MySqlKey x) { - return true; - } + @Override + public boolean visit(MySqlKey x) { + return true; + } - @Override - public void endVisit(MySqlKey x) { + @Override + public void endVisit(MySqlKey x) { - } + } - @Override - public boolean visit(MySqlPrimaryKey x) { + @Override + public boolean visit(MySqlPrimaryKey x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlPrimaryKey x) { + @Override + public void endVisit(MySqlPrimaryKey x) { - } + } - @Override - public void endVisit(MySqlIntervalExpr x) { + @Override + public void endVisit(MySqlIntervalExpr x) { - } + } - @Override - public boolean visit(MySqlIntervalExpr x) { + @Override + public boolean visit(MySqlIntervalExpr x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlExtractExpr x) { + @Override + public void endVisit(MySqlExtractExpr x) { - } + } - @Override - public boolean visit(MySqlExtractExpr x) { + @Override + public boolean visit(MySqlExtractExpr x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlMatchAgainstExpr x) { + @Override + public void endVisit(MySqlMatchAgainstExpr x) { - } + } - @Override - public boolean visit(MySqlMatchAgainstExpr x) { + @Override + public boolean visit(MySqlMatchAgainstExpr x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlBinaryExpr x) { + @Override + public void endVisit(MySqlBinaryExpr x) { - } + } - @Override - public boolean visit(MySqlBinaryExpr x) { + @Override + public boolean visit(MySqlBinaryExpr x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlPrepareStatement x) { + @Override + public void endVisit(MySqlPrepareStatement x) { - } + } - @Override - public boolean visit(MySqlPrepareStatement x) { + @Override + public boolean visit(MySqlPrepareStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlExecuteStatement x) { + @Override + public void endVisit(MySqlExecuteStatement x) { - } + } - @Override - public boolean visit(MySqlExecuteStatement x) { + @Override + public boolean visit(MySqlExecuteStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlDeleteStatement x) { + @Override + public void endVisit(MySqlDeleteStatement x) { - } + } - @Override - public boolean visit(MySqlDeleteStatement x) { + @Override + public boolean visit(MySqlDeleteStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlInsertStatement x) { + @Override + public void endVisit(MySqlInsertStatement x) { - } + } - @Override - public boolean visit(MySqlInsertStatement x) { + @Override + public boolean visit(MySqlInsertStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlLoadDataInFileStatement x) { + @Override + public void endVisit(MySqlLoadDataInFileStatement x) { - } + } - @Override - public boolean visit(MySqlLoadDataInFileStatement x) { + @Override + public boolean visit(MySqlLoadDataInFileStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlLoadXmlStatement x) { + @Override + public void endVisit(MySqlLoadXmlStatement x) { - } + } - @Override - public boolean visit(MySqlLoadXmlStatement x) { + @Override + public boolean visit(MySqlLoadXmlStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlReplicateStatement x) { + @Override + public void endVisit(MySqlReplicateStatement x) { - } + } - @Override - public boolean visit(MySqlReplicateStatement x) { + @Override + public boolean visit(MySqlReplicateStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlSelectGroupBy x) { + @Override + public void endVisit(MySqlSelectGroupBy x) { - } + } - @Override - public boolean visit(MySqlSelectGroupBy x) { + @Override + public boolean visit(MySqlSelectGroupBy x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlStartTransactionStatement x) { + @Override + public void endVisit(MySqlStartTransactionStatement x) { - } + } - @Override - public boolean visit(MySqlStartTransactionStatement x) { + @Override + public boolean visit(MySqlStartTransactionStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlCommitStatement x) { + @Override + public void endVisit(MySqlCommitStatement x) { - } + } - @Override - public boolean visit(MySqlCommitStatement x) { + @Override + public boolean visit(MySqlCommitStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlRollbackStatement x) { + @Override + public void endVisit(MySqlRollbackStatement x) { - } + } - @Override - public boolean visit(MySqlRollbackStatement x) { + @Override + public boolean visit(MySqlRollbackStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlShowColumnsStatement x) { + @Override + public void endVisit(MySqlShowColumnsStatement x) { - } + } - @Override - public boolean visit(MySqlShowColumnsStatement x) { + @Override + public boolean visit(MySqlShowColumnsStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlShowTablesStatement x) { + @Override + public void endVisit(MySqlShowTablesStatement x) { - } + } - @Override - public boolean visit(MySqlShowTablesStatement x) { + @Override + public boolean visit(MySqlShowTablesStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlShowDatabasesStatement x) { + @Override + public void endVisit(MySqlShowDatabasesStatement x) { - } + } - @Override - public boolean visit(MySqlShowDatabasesStatement x) { + @Override + public boolean visit(MySqlShowDatabasesStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlShowWarningsStatement x) { + @Override + public void endVisit(MySqlShowWarningsStatement x) { - } + } - @Override - public boolean visit(MySqlShowWarningsStatement x) { + @Override + public boolean visit(MySqlShowWarningsStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(MySqlShowStatusStatement x) { + @Override + public void endVisit(MySqlShowStatusStatement x) { - } + } - @Override - public boolean visit(MySqlShowStatusStatement x) { + @Override + public boolean visit(MySqlShowStatusStatement x) { - return true; - } + return true; + } - @Override - public void endVisit(CobarShowStatus x) { - - } + @Override + public void endVisit(CobarShowStatus x) { - @Override - public boolean visit(CobarShowStatus x) { - return true; - } + } + + @Override + public boolean visit(CobarShowStatus x) { + return true; + } @Override public void endVisit(MySqlKillStatement x) { - + } @Override public boolean visit(MySqlKillStatement x) { return true; } - + @Override public void endVisit(MySqlBinlogStatement x) { - + } - + @Override public boolean visit(MySqlBinlogStatement x) { return true; diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java index a5fd303b80..c3ed5033c0 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java @@ -62,1152 +62,1161 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionSt import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex; import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor; -public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTVisitor { - - public MySqlOutputVisitor(Appendable appender){ - super(appender); - } - - public boolean visit(MySqlBooleanExpr x) { - print(x.getValue() ? "true" : "false"); - - return false; - } - - public void endVisit(MySqlBooleanExpr x) { - } - - @Override - public boolean visit(SQLSelectQueryBlock select) { - if (select instanceof MySqlSelectQueryBlock) { - return visit((MySqlSelectQueryBlock) select); - } - - return false; - } - - public boolean visit(MySqlSelectQueryBlock select) { - print("SELECT "); - - if (SQLSetQuantifier.ALL == select.getDistionOption()) print("ALL "); - else if (SQLSetQuantifier.DISTINCT == select.getDistionOption()) print("DISTINCT "); - else if (SQLSetQuantifier.DISTINCTROW == select.getDistionOption()) { - print("DISTINCTROW "); - } - - if (select.isHignPriority()) { - print("HIGH_PRIORITY "); - } - - if (select.isSmallResult()) { - print("SQL_SMALL_RESULT "); - } - - if (select.isBigResult()) { - print("SQL_BIG_RESULT "); - } - - if (select.isBufferResult()) { - print("SQL_BUFFER_RESULT "); - } - - if (select.getCache() != null) { - if (select.getCache().booleanValue()) { - print("SQL_CACHE "); - } else { - print("SQL_NO_CACHE "); - } - } - - if (select.isCalcFoundRows()) { - print("SQL_CALC_FOUND_ROWS "); - } - - printSelectList(select.getSelectList()); - - if (select.getOutFile() != null) { - println(); - print("INTO OUTFILE "); - select.getOutFile().accept(this); - if (select.getOutFileCharset() != null) { - print(" CHARACTER SET "); - print(select.getOutFileCharset()); - } - - if (select.getOutFileColumnsTerminatedBy() != null || select.getOutFileColumnsEnclosedBy() != null - || select.getOutFileColumnsEscaped() != null) { - print(" COLUMNS"); - if (select.getOutFileColumnsTerminatedBy() != null) { - print(" TERMINATED BY "); - select.getOutFileColumnsTerminatedBy().accept(this); - } - - if (select.getOutFileColumnsEnclosedBy() != null) { - if (select.isOutFileColumnsEnclosedOptionally()) { - print(" OPTIONALLY"); - } - print(" ENCLOSED BY "); - select.getOutFileColumnsEnclosedBy().accept(this); - } - - if (select.getOutFileColumnsEscaped() != null) { - print(" ESCAPED BY "); - select.getOutFileColumnsEscaped().accept(this); - } - } - - if (select.getOutFileLinesStartingBy() != null || select.getOutFileLinesTerminatedBy() != null) { - print(" LINES"); - if (select.getOutFileLinesStartingBy() != null) { - print(" STARTING BY "); - select.getOutFileLinesStartingBy().accept(this); - } - - if (select.getOutFileLinesTerminatedBy() != null) { - print(" TERMINATED BY "); - select.getOutFileLinesTerminatedBy().accept(this); - } - } - } - - if (select.getFrom() != null) { - println(); - print("FROM "); - select.getFrom().accept(this); - } - - if (select.getWhere() != null) { - println(); - print("WHERE "); - select.getWhere().accept(this); - } - - if (select.getGroupBy() != null) { - println(); - select.getGroupBy().accept(this); - } - - if (select.getOrderBy() != null) { - println(); - select.getOrderBy().accept(this); - } - - if (select.getLimit() != null) { - println(); - select.getLimit().accept(this); - } - - if (select.getProcedureName() != null) { - print(" PROCEDURE "); - select.getProcedureName().accept(this); - if (select.getProcedureArgumentList().size() > 0) { - print("("); - printAndAccept(select.getProcedureArgumentList(), ", "); - print(")"); - } - } - - if (select.isForUpdate()) { - println(); - print("FOR UPDATE"); - } - - if (select.isLockInShareMode()) { - println(); - print("LOCK IN SHARE MODE"); - } - - return false; - } - - public boolean visit(SQLColumnDefinition x) { - MySqlSQLColumnDefinition mysqlColumn = null; - - if (x instanceof MySqlSQLColumnDefinition) { - mysqlColumn = (MySqlSQLColumnDefinition) x; - } - - x.getName().accept(this); - print(' '); - x.getDataType().accept(this); - - if (x.getDefaultExpr() != null) { - print(" DEFAULT "); - x.getDefaultExpr().accept(this); - } - - if (mysqlColumn != null && mysqlColumn.isAutoIncrement()) { - print(" AUTO_INCREMENT"); - } - - for (SQLColumnConstraint item : x.getConstaints()) { - print(' '); - item.accept(this); - } - - return false; - } - - public boolean visit(MySqlSelectQueryBlock.Limit x) { - print("LIMIT "); - if (x.getOffset() != null) { - x.getOffset().accept(this); - print(", "); - } - x.getRowCount().accept(this); - - return false; - } - - public boolean visit(SQLDataType x) { - print(x.getName()); - if (x.getArguments().size() > 0) { - print("("); - printAndAccept(x.getArguments(), ", "); - print(")"); - } - - if (x instanceof SQLCharactorDataType) { - SQLCharactorDataType charType = (SQLCharactorDataType) x; - if (charType.getCharSetName() != null) { - print(" CHARACTER SET "); - print(charType.getCharSetName()); - - if (charType.getCollate() != null) { - print(" COLLATE "); - print(charType.getCollate()); - } - } - } - return false; - } - - @Override - public void endVisit(Limit x) { - - } - - @Override - public void endVisit(MySqlTableIndex x) { - - } - - @Override - public boolean visit(MySqlTableIndex x) { - print("INDEX"); - if (x.getName() != null) { - print(" "); - x.getName().accept(this); - } - - if (x.getIndexType() != null) { - print(" USING "); - print(x.getIndexType()); - } - - print("("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - return false; - } - - public boolean visit(SQLCreateTableStatement x) { - - MySqlCreateTableStatement mysqlCreateTableStatement = null; - if (x instanceof MySqlCreateTableStatement) { - mysqlCreateTableStatement = (MySqlCreateTableStatement) x; - } - - if (SQLCreateTableStatement.Type.GLOBAL_TEMPORARY.equals(x.getType())) { - print("CREATE TEMPORARY TABLE "); - } else { - print("CREATE TABLE "); - } - - if (mysqlCreateTableStatement != null && mysqlCreateTableStatement.isIfNotExiists()) { - print("IF NOT EXISTS "); - } - - x.getName().accept(this); - print(" ("); - incrementIndent(); - println(); - for (int i = 0, size = x.getTableElementList().size(); i < size; ++i) { - if (i != 0) { - print(", "); - println(); - } - x.getTableElementList().get(i).accept(this); - } - decrementIndent(); - println(); - print(")"); - - if (mysqlCreateTableStatement != null) { - for (Map.Entry option : mysqlCreateTableStatement.getTableOptions().entrySet()) { - print(" "); - print(option.getKey()); - print(" = "); - print(option.getValue()); - } - } - - if (mysqlCreateTableStatement != null && mysqlCreateTableStatement.getQuery() != null) { - print(" "); - incrementIndent(); - println(); - mysqlCreateTableStatement.getQuery().accept(this); - decrementIndent(); - } - - return false; - } - - @Override - public void endVisit(MySqlKey x) { - - } - - @Override - public void endVisit(MySqlPrimaryKey x) { - - } - - @Override - public boolean visit(MySqlKey x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.accept(this); - print(' '); - } - - print("KEY"); - - if (x.getIndexType() != null) { - print(" USING "); - print(x.getIndexType()); - } - - print(" ("); - - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - - return false; - } - - @Override - public boolean visit(MySqlPrimaryKey x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.accept(this); - print(' '); - } - - print("PRIAMRY KEY"); - - if (x.getIndexType() != null) { - print(" USING "); - print(x.getIndexType()); - } - - print(" ("); - - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - - return false; - } - - public boolean visit(SQLCharExpr x) { - if (x instanceof MySqlCharExpr) { - print(x.toString()); - } else if ((x.getText() == null) || (x.getText().length() == 0)) { - print("NULL"); - } else { - print("'"); - print(x.getText().replaceAll("'", "''")); - print("'"); - } - - return false; - } - - public boolean visit(SQLVariantRefExpr x) { - print(x.getName()); - - String collate = (String) x.getAttribute("COLLATE"); - if (collate != null) { - print(" COLLATE "); - print(collate); - } - - return false; - } - - public boolean visit(SQLMethodInvokeExpr x) { - if ("SUBSTRING".equalsIgnoreCase(x.getMethodName())) { - if (x.getOwner() != null) { - x.getOwner().accept(this); - print("."); - } - print(x.getMethodName()); - print("("); - printAndAccept(x.getParameters(), ", "); - SQLExpr from = (SQLExpr) x.getAttribute("FROM"); - if (from != null) { - print(" FROM "); - from.accept(this); - } - - SQLExpr _for = (SQLExpr) x.getAttribute("FOR"); - if (_for != null) { - print(" FOR "); - _for.accept(this); - } - print(")"); - - return false; - } - - if ("TRIM".equalsIgnoreCase(x.getMethodName())) { - if (x.getOwner() != null) { - x.getOwner().accept(this); - print("."); - } - print(x.getMethodName()); - print("("); - - String trimType = (String) x.getAttribute("TRIM_TYPE"); - if (trimType != null) { - print(trimType); - print(' '); - } - - printAndAccept(x.getParameters(), ", "); - - SQLExpr from = (SQLExpr) x.getAttribute("FROM"); - if (from != null) { - print(" FROM "); - from.accept(this); - } - - print(")"); - - return false; - } - - if ("CONVERT".equalsIgnoreCase(x.getMethodName())) { - if (x.getOwner() != null) { - x.getOwner().accept(this); - print("."); - } - print(x.getMethodName()); - print("("); - printAndAccept(x.getParameters(), ", "); - - String charset = (String) x.getAttribute("USING"); - if (charset != null) { - print(" USING "); - print(charset); - } - print(")"); - return false; - } - - return super.visit(x); - } - - @Override - public void endVisit(MySqlIntervalExpr x) { - - } - - @Override - public boolean visit(MySqlIntervalExpr x) { - print("INTERVAL "); - x.getValue().accept(this); - print(' '); - print(x.getUnit().name()); - return false; - } - - @Override - public boolean visit(MySqlExtractExpr x) { - print("EXTRACT("); - print(x.getUnit().name()); - print(" FROM "); - x.getValue().accept(this); - print(')'); - return false; - } - - @Override - public void endVisit(MySqlExtractExpr x) { - - } - - @Override - public void endVisit(MySqlMatchAgainstExpr x) { - - } - - @Override - public boolean visit(MySqlMatchAgainstExpr x) { - print("MATCH ("); - printAndAccept(x.getColumns(), ", "); - print(")"); - - print(" AGAINST ("); - x.getAgainst().accept(this); - if (x.getSearchModifier() != null) { - print(' '); - print(x.getSearchModifier().name); - } - print(')'); - - return false; - } - - @Override - public void endVisit(MySqlBinaryExpr x) { - - } - - @Override - public boolean visit(MySqlBinaryExpr x) { - print("b'"); - print(x.getValue()); - print('\''); - - return false; - } - - @Override - public void endVisit(MySqlPrepareStatement x) { - } - - @Override - public boolean visit(MySqlPrepareStatement x) { - print("PREPARE "); - x.getName().accept(this); - print(" FROM "); - x.getFrom().accept(this); - return false; - } - - @Override - public void endVisit(MySqlExecuteStatement x) { - - } - - @Override - public boolean visit(MySqlExecuteStatement x) { - print("EXECUTE "); - x.getStatementName().accept(this); - if (x.getParameters().size() > 0) { - print(" USING "); - printAndAccept(x.getParameters(), ", "); - } - return false; - } - - @Override - public void endVisit(MySqlDeleteStatement x) { - - } - - @Override - public boolean visit(MySqlDeleteStatement x) { - print("DELETE "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isQuick()) { - print("QUICK "); - } - - if (x.isIgnore()) { - print("IGNORE "); - } - - if (x.getFrom() == null) { - print("FROM "); - printAndAccept(x.getTableNames(), ", "); - } else { - printAndAccept(x.getTableNames(), ", "); - println(); - print("FROM "); - x.getFrom().accept(this); - } - - if (x.getUsing() != null) { - println(); - print("USING "); - x.getUsing().accept(this); - } - - if (x.getWhere() != null) { - println(); - print("WHERE "); - x.getWhere().accept(this); - } - - if (x.getOrderBy() != null) { - println(); - x.getOrderBy().accept(this); - } - - if (x.getLimit() != null) { - println(); - x.getLimit().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlInsertStatement x) { - - } - - @Override - public boolean visit(MySqlInsertStatement x) { - print("INSERT "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isDelayed()) { - print("DELAYED "); - } - - if (x.isHighPriority()) { - print("HIGH_PRIORITY "); - } - - if (x.isIgnore()) { - print("IGNORE "); - } - - print("INTO "); - - x.getTableName().accept(this); - - if (x.getColumns().size() > 0) { - incrementIndent(); - println(); - print("("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - if (i % 5 == 0) { - println(); - } - print(", "); - } - - x.getColumns().get(i).accept(this); - } - print(")"); - decrementIndent(); - } - - if (x.getValuesList().size() != 0) { - println(); - print("VALUES"); - println(); - for (int i = 0, size = x.getValuesList().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getValuesList().get(i).accept(this); - } - - } - - if (x.getQuery() != null) { - print(" "); - x.getQuery().accept(this); - } - - if (x.getDuplicateKeyUpdate().size() != 0) { - print(" ON DUPLICATE KEY UPDATE "); - printAndAccept(x.getDuplicateKeyUpdate(), ", "); - } - - return false; - } - - @Override - public void endVisit(MySqlLoadDataInFileStatement x) { - - } - - @Override - public boolean visit(MySqlLoadDataInFileStatement x) { - print("LOAD DATA "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isConcurrent()) { - print("CONCURRENT "); - } - - if (x.isLocal()) { - print("LOCAL "); - } - - print("INFILE "); - - x.getFileName().accept(this); - - if (x.isReplicate()) { - print(" REPLACE "); - } - - if (x.isIgnore()) { - print(" IGNORE "); - } - - print(" INTO TABLE "); - x.getTableName().accept(this); - - if (x.getColumnsTerminatedBy() != null || x.getColumnsEnclosedBy() != null || x.getColumnsEscaped() != null) { - print(" COLUMNS"); - if (x.getColumnsTerminatedBy() != null) { - print(" TERMINATED BY "); - x.getColumnsTerminatedBy().accept(this); - } - - if (x.getColumnsEnclosedBy() != null) { - if (x.isColumnsEnclosedOptionally()) { - print(" OPTIONALLY"); - } - print(" ENCLOSED BY "); - x.getColumnsEnclosedBy().accept(this); - } - - if (x.getColumnsEscaped() != null) { - print(" ESCAPED BY "); - x.getColumnsEscaped().accept(this); - } - } - - if (x.getLinesStartingBy() != null || x.getLinesTerminatedBy() != null) { - print(" LINES"); - if (x.getLinesStartingBy() != null) { - print(" STARTING BY "); - x.getLinesStartingBy().accept(this); - } - - if (x.getLinesTerminatedBy() != null) { - print(" TERMINATED BY "); - x.getLinesTerminatedBy().accept(this); - } - } - - if (x.getSetList().size() != 0) { - print(" SET "); - printAndAccept(x.getSetList(), ", "); - } - - return false; - } - - @Override - public void endVisit(MySqlReplicateStatement x) { - - } - - @Override - public boolean visit(MySqlReplicateStatement x) { - print("REPLACE "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isDelayed()) { - print("DELAYED "); - } - - print("INTO "); - - x.getTableName().accept(this); - - if (x.getColumns().size() > 0) { - print(" ("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - } - - if (x.getValuesList().size() != 0) { - println(); - print("VALUES "); - int size = x.getValuesList().size(); - if (size == 0) { - print("()"); - } else { - for (int i = 0; i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getValuesList().get(i).accept(this); - } - } - } - - if (x.getQuery() != null) { - x.getQuery().accept(this); - } - - if (x.getSetItems().size() != 0) { - println(); - print("SET "); - printAndAccept(x.getSetItems(), ", "); - } - - return false; - } - - @Override - public void endVisit(MySqlSelectGroupBy x) { - - } - - @Override - public boolean visit(MySqlSelectGroupBy x) { - super.visit(x); - - if (x.isRollUp()) { - print(" WITH ROLLUP"); - } - - return false; - } - - @Override - public void endVisit(MySqlStartTransactionStatement x) { - - } - - @Override - public boolean visit(MySqlStartTransactionStatement x) { - print("START TRANSACTION"); - if (x.isConsistentSnapshot()) { - print(" WITH CONSISTENT SNAPSHOT"); - } - - if (x.isBegin()) { - print(" BEGIN"); - } - - if (x.isWork()) { - print(" WORK"); - } - - return false; - } - - @Override - public void endVisit(MySqlCommitStatement x) { - - } - - @Override - public boolean visit(MySqlCommitStatement x) { - print("COMMIT"); - - if (x.isWork()) { - print(" WORK"); - } - - if (x.getChain() != null) { - if (x.getChain().booleanValue()) { - print(" AND CHAIN"); - } else { - print(" AND NO CHAIN"); - } - } - - if (x.getRelease() != null) { - if (x.getRelease().booleanValue()) { - print(" AND RELEASE"); - } else { - print(" AND NO RELEASE"); - } - } - - return false; - } - - @Override - public void endVisit(MySqlRollbackStatement x) { - - } - - @Override - public boolean visit(MySqlRollbackStatement x) { - print("ROLLBACK"); - - if (x.isWork()) { - print(" WORK"); - } - - if (x.getChain() != null) { - if (x.getChain().booleanValue()) { - print(" AND CHAIN"); - } else { - print(" AND NO CHAIN"); - } - } - - if (x.getRelease() != null) { - if (x.getRelease().booleanValue()) { - print(" AND RELEASE"); - } else { - print(" AND NO RELEASE"); - } - } - - return false; - } - - @Override - public void endVisit(MySqlShowColumnsStatement x) { - - } - - @Override - public boolean visit(MySqlShowColumnsStatement x) { - if (x.isFull()) { - print("SHOW FULL COLUMNS"); - } else { - print("SHOW COLUMNS"); - } - - if (x.getTable() != null) { - print(" FROM "); - x.getTable().accept(this); - } - - if (x.getDatabase() != null) { - print(" FROM "); - x.getDatabase().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowTablesStatement x) { - - } - - @Override - public boolean visit(MySqlShowTablesStatement x) { - if (x.isFull()) { - print("SHOW FULL TABLES"); - } else { - print("SHOW TABLES"); - } - - if (x.getDatabase() != null) { - print(" FROM "); - x.getDatabase().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } +public class MySqlOutputVisitor extends SQLASTOutputVisitor implements + MySqlASTVisitor { + + public MySqlOutputVisitor(Appendable appender) { + super(appender); + } + + public boolean visit(MySqlBooleanExpr x) { + print(x.getValue() ? "true" : "false"); + + return false; + } + + public void endVisit(MySqlBooleanExpr x) { + } + + @Override + public boolean visit(SQLSelectQueryBlock select) { + if (select instanceof MySqlSelectQueryBlock) { + return visit((MySqlSelectQueryBlock) select); + } + + return false; + } + + public boolean visit(MySqlSelectQueryBlock select) { + print("SELECT "); + + if (SQLSetQuantifier.ALL == select.getDistionOption()) + print("ALL "); + else if (SQLSetQuantifier.DISTINCT == select.getDistionOption()) + print("DISTINCT "); + else if (SQLSetQuantifier.DISTINCTROW == select.getDistionOption()) { + print("DISTINCTROW "); + } + + if (select.isHignPriority()) { + print("HIGH_PRIORITY "); + } + + if (select.isSmallResult()) { + print("SQL_SMALL_RESULT "); + } + + if (select.isBigResult()) { + print("SQL_BIG_RESULT "); + } + + if (select.isBufferResult()) { + print("SQL_BUFFER_RESULT "); + } + + if (select.getCache() != null) { + if (select.getCache().booleanValue()) { + print("SQL_CACHE "); + } else { + print("SQL_NO_CACHE "); + } + } + + if (select.isCalcFoundRows()) { + print("SQL_CALC_FOUND_ROWS "); + } + + printSelectList(select.getSelectList()); + + if (select.getOutFile() != null) { + println(); + print("INTO OUTFILE "); + select.getOutFile().accept(this); + if (select.getOutFileCharset() != null) { + print(" CHARACTER SET "); + print(select.getOutFileCharset()); + } + + if (select.getOutFileColumnsTerminatedBy() != null + || select.getOutFileColumnsEnclosedBy() != null + || select.getOutFileColumnsEscaped() != null) { + print(" COLUMNS"); + if (select.getOutFileColumnsTerminatedBy() != null) { + print(" TERMINATED BY "); + select.getOutFileColumnsTerminatedBy().accept(this); + } + + if (select.getOutFileColumnsEnclosedBy() != null) { + if (select.isOutFileColumnsEnclosedOptionally()) { + print(" OPTIONALLY"); + } + print(" ENCLOSED BY "); + select.getOutFileColumnsEnclosedBy().accept(this); + } + + if (select.getOutFileColumnsEscaped() != null) { + print(" ESCAPED BY "); + select.getOutFileColumnsEscaped().accept(this); + } + } + + if (select.getOutFileLinesStartingBy() != null + || select.getOutFileLinesTerminatedBy() != null) { + print(" LINES"); + if (select.getOutFileLinesStartingBy() != null) { + print(" STARTING BY "); + select.getOutFileLinesStartingBy().accept(this); + } + + if (select.getOutFileLinesTerminatedBy() != null) { + print(" TERMINATED BY "); + select.getOutFileLinesTerminatedBy().accept(this); + } + } + } + + if (select.getFrom() != null) { + println(); + print("FROM "); + select.getFrom().accept(this); + } + + if (select.getWhere() != null) { + println(); + print("WHERE "); + select.getWhere().accept(this); + } + + if (select.getGroupBy() != null) { + println(); + select.getGroupBy().accept(this); + } + + if (select.getOrderBy() != null) { + println(); + select.getOrderBy().accept(this); + } + + if (select.getLimit() != null) { + println(); + select.getLimit().accept(this); + } + + if (select.getProcedureName() != null) { + print(" PROCEDURE "); + select.getProcedureName().accept(this); + if (select.getProcedureArgumentList().size() > 0) { + print("("); + printAndAccept(select.getProcedureArgumentList(), ", "); + print(")"); + } + } + + if (select.isForUpdate()) { + println(); + print("FOR UPDATE"); + } + + if (select.isLockInShareMode()) { + println(); + print("LOCK IN SHARE MODE"); + } + + return false; + } + + public boolean visit(SQLColumnDefinition x) { + MySqlSQLColumnDefinition mysqlColumn = null; + + if (x instanceof MySqlSQLColumnDefinition) { + mysqlColumn = (MySqlSQLColumnDefinition) x; + } + + x.getName().accept(this); + print(' '); + x.getDataType().accept(this); + + if (x.getDefaultExpr() != null) { + print(" DEFAULT "); + x.getDefaultExpr().accept(this); + } + + if (mysqlColumn != null && mysqlColumn.isAutoIncrement()) { + print(" AUTO_INCREMENT"); + } + + for (SQLColumnConstraint item : x.getConstaints()) { + print(' '); + item.accept(this); + } + + return false; + } + + public boolean visit(MySqlSelectQueryBlock.Limit x) { + print("LIMIT "); + if (x.getOffset() != null) { + x.getOffset().accept(this); + print(", "); + } + x.getRowCount().accept(this); + + return false; + } + + public boolean visit(SQLDataType x) { + print(x.getName()); + if (x.getArguments().size() > 0) { + print("("); + printAndAccept(x.getArguments(), ", "); + print(")"); + } + + if (x instanceof SQLCharactorDataType) { + SQLCharactorDataType charType = (SQLCharactorDataType) x; + if (charType.getCharSetName() != null) { + print(" CHARACTER SET "); + print(charType.getCharSetName()); + + if (charType.getCollate() != null) { + print(" COLLATE "); + print(charType.getCollate()); + } + } + } + return false; + } + + @Override + public void endVisit(Limit x) { + + } + + @Override + public void endVisit(MySqlTableIndex x) { + + } + + @Override + public boolean visit(MySqlTableIndex x) { + print("INDEX"); + if (x.getName() != null) { + print(" "); + x.getName().accept(this); + } + + if (x.getIndexType() != null) { + print(" USING "); + print(x.getIndexType()); + } + + print("("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + return false; + } + + public boolean visit(SQLCreateTableStatement x) { + + MySqlCreateTableStatement mysqlCreateTableStatement = null; + if (x instanceof MySqlCreateTableStatement) { + mysqlCreateTableStatement = (MySqlCreateTableStatement) x; + } + + if (SQLCreateTableStatement.Type.GLOBAL_TEMPORARY.equals(x.getType())) { + print("CREATE TEMPORARY TABLE "); + } else { + print("CREATE TABLE "); + } + + if (mysqlCreateTableStatement != null + && mysqlCreateTableStatement.isIfNotExiists()) { + print("IF NOT EXISTS "); + } + + x.getName().accept(this); + print(" ("); + incrementIndent(); + println(); + for (int i = 0, size = x.getTableElementList().size(); i < size; ++i) { + if (i != 0) { + print(", "); + println(); + } + x.getTableElementList().get(i).accept(this); + } + decrementIndent(); + println(); + print(")"); + + if (mysqlCreateTableStatement != null) { + for (Map.Entry option : mysqlCreateTableStatement + .getTableOptions().entrySet()) { + print(" "); + print(option.getKey()); + print(" = "); + print(option.getValue()); + } + } + + if (mysqlCreateTableStatement != null + && mysqlCreateTableStatement.getQuery() != null) { + print(" "); + incrementIndent(); + println(); + mysqlCreateTableStatement.getQuery().accept(this); + decrementIndent(); + } + + return false; + } + + @Override + public void endVisit(MySqlKey x) { + + } + + @Override + public void endVisit(MySqlPrimaryKey x) { + + } + + @Override + public boolean visit(MySqlKey x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.accept(this); + print(' '); + } + + print("KEY"); + + if (x.getIndexType() != null) { + print(" USING "); + print(x.getIndexType()); + } + + print(" ("); + + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + + return false; + } + + @Override + public boolean visit(MySqlPrimaryKey x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.accept(this); + print(' '); + } + + print("PRIAMRY KEY"); + + if (x.getIndexType() != null) { + print(" USING "); + print(x.getIndexType()); + } + + print(" ("); + + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + + return false; + } + + public boolean visit(SQLCharExpr x) { + if (x instanceof MySqlCharExpr) { + print(x.toString()); + } else if ((x.getText() == null) || (x.getText().length() == 0)) { + print("NULL"); + } else { + print("'"); + print(x.getText().replaceAll("'", "''")); + print("'"); + } + + return false; + } + + public boolean visit(SQLVariantRefExpr x) { + print(x.getName()); + + String collate = (String) x.getAttribute("COLLATE"); + if (collate != null) { + print(" COLLATE "); + print(collate); + } + + return false; + } + + public boolean visit(SQLMethodInvokeExpr x) { + if ("SUBSTRING".equalsIgnoreCase(x.getMethodName())) { + if (x.getOwner() != null) { + x.getOwner().accept(this); + print("."); + } + print(x.getMethodName()); + print("("); + printAndAccept(x.getParameters(), ", "); + SQLExpr from = (SQLExpr) x.getAttribute("FROM"); + if (from != null) { + print(" FROM "); + from.accept(this); + } + + SQLExpr _for = (SQLExpr) x.getAttribute("FOR"); + if (_for != null) { + print(" FOR "); + _for.accept(this); + } + print(")"); + + return false; + } + + if ("TRIM".equalsIgnoreCase(x.getMethodName())) { + if (x.getOwner() != null) { + x.getOwner().accept(this); + print("."); + } + print(x.getMethodName()); + print("("); + + String trimType = (String) x.getAttribute("TRIM_TYPE"); + if (trimType != null) { + print(trimType); + print(' '); + } + + printAndAccept(x.getParameters(), ", "); + + SQLExpr from = (SQLExpr) x.getAttribute("FROM"); + if (from != null) { + print(" FROM "); + from.accept(this); + } + + print(")"); + + return false; + } + + if ("CONVERT".equalsIgnoreCase(x.getMethodName())) { + if (x.getOwner() != null) { + x.getOwner().accept(this); + print("."); + } + print(x.getMethodName()); + print("("); + printAndAccept(x.getParameters(), ", "); + + String charset = (String) x.getAttribute("USING"); + if (charset != null) { + print(" USING "); + print(charset); + } + print(")"); + return false; + } + + return super.visit(x); + } + + @Override + public void endVisit(MySqlIntervalExpr x) { + + } + + @Override + public boolean visit(MySqlIntervalExpr x) { + print("INTERVAL "); + x.getValue().accept(this); + print(' '); + print(x.getUnit().name()); + return false; + } + + @Override + public boolean visit(MySqlExtractExpr x) { + print("EXTRACT("); + print(x.getUnit().name()); + print(" FROM "); + x.getValue().accept(this); + print(')'); + return false; + } + + @Override + public void endVisit(MySqlExtractExpr x) { + + } + + @Override + public void endVisit(MySqlMatchAgainstExpr x) { + + } + + @Override + public boolean visit(MySqlMatchAgainstExpr x) { + print("MATCH ("); + printAndAccept(x.getColumns(), ", "); + print(")"); + + print(" AGAINST ("); + x.getAgainst().accept(this); + if (x.getSearchModifier() != null) { + print(' '); + print(x.getSearchModifier().name); + } + print(')'); + + return false; + } + + @Override + public void endVisit(MySqlBinaryExpr x) { + + } + + @Override + public boolean visit(MySqlBinaryExpr x) { + print("b'"); + print(x.getValue()); + print('\''); + + return false; + } + + @Override + public void endVisit(MySqlPrepareStatement x) { + } + + @Override + public boolean visit(MySqlPrepareStatement x) { + print("PREPARE "); + x.getName().accept(this); + print(" FROM "); + x.getFrom().accept(this); + return false; + } + + @Override + public void endVisit(MySqlExecuteStatement x) { + + } + + @Override + public boolean visit(MySqlExecuteStatement x) { + print("EXECUTE "); + x.getStatementName().accept(this); + if (x.getParameters().size() > 0) { + print(" USING "); + printAndAccept(x.getParameters(), ", "); + } + return false; + } + + @Override + public void endVisit(MySqlDeleteStatement x) { + + } + + @Override + public boolean visit(MySqlDeleteStatement x) { + print("DELETE "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isQuick()) { + print("QUICK "); + } + + if (x.isIgnore()) { + print("IGNORE "); + } + + if (x.getFrom() == null) { + print("FROM "); + printAndAccept(x.getTableNames(), ", "); + } else { + printAndAccept(x.getTableNames(), ", "); + println(); + print("FROM "); + x.getFrom().accept(this); + } + + if (x.getUsing() != null) { + println(); + print("USING "); + x.getUsing().accept(this); + } + + if (x.getWhere() != null) { + println(); + print("WHERE "); + x.getWhere().accept(this); + } + + if (x.getOrderBy() != null) { + println(); + x.getOrderBy().accept(this); + } + + if (x.getLimit() != null) { + println(); + x.getLimit().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlInsertStatement x) { + + } + + @Override + public boolean visit(MySqlInsertStatement x) { + print("INSERT "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isDelayed()) { + print("DELAYED "); + } + + if (x.isHighPriority()) { + print("HIGH_PRIORITY "); + } + + if (x.isIgnore()) { + print("IGNORE "); + } + + print("INTO "); + + x.getTableName().accept(this); + + if (x.getColumns().size() > 0) { + incrementIndent(); + println(); + print("("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + if (i % 5 == 0) { + println(); + } + print(", "); + } + + x.getColumns().get(i).accept(this); + } + print(")"); + decrementIndent(); + } + + if (x.getValuesList().size() != 0) { + println(); + print("VALUES"); + println(); + for (int i = 0, size = x.getValuesList().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getValuesList().get(i).accept(this); + } + + } + + if (x.getQuery() != null) { + print(" "); + x.getQuery().accept(this); + } + + if (x.getDuplicateKeyUpdate().size() != 0) { + print(" ON DUPLICATE KEY UPDATE "); + printAndAccept(x.getDuplicateKeyUpdate(), ", "); + } + + return false; + } + + @Override + public void endVisit(MySqlLoadDataInFileStatement x) { + + } + + @Override + public boolean visit(MySqlLoadDataInFileStatement x) { + print("LOAD DATA "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isConcurrent()) { + print("CONCURRENT "); + } + + if (x.isLocal()) { + print("LOCAL "); + } + + print("INFILE "); + + x.getFileName().accept(this); + + if (x.isReplicate()) { + print(" REPLACE "); + } + + if (x.isIgnore()) { + print(" IGNORE "); + } + + print(" INTO TABLE "); + x.getTableName().accept(this); + + if (x.getColumnsTerminatedBy() != null + || x.getColumnsEnclosedBy() != null + || x.getColumnsEscaped() != null) { + print(" COLUMNS"); + if (x.getColumnsTerminatedBy() != null) { + print(" TERMINATED BY "); + x.getColumnsTerminatedBy().accept(this); + } + + if (x.getColumnsEnclosedBy() != null) { + if (x.isColumnsEnclosedOptionally()) { + print(" OPTIONALLY"); + } + print(" ENCLOSED BY "); + x.getColumnsEnclosedBy().accept(this); + } + + if (x.getColumnsEscaped() != null) { + print(" ESCAPED BY "); + x.getColumnsEscaped().accept(this); + } + } + + if (x.getLinesStartingBy() != null || x.getLinesTerminatedBy() != null) { + print(" LINES"); + if (x.getLinesStartingBy() != null) { + print(" STARTING BY "); + x.getLinesStartingBy().accept(this); + } + + if (x.getLinesTerminatedBy() != null) { + print(" TERMINATED BY "); + x.getLinesTerminatedBy().accept(this); + } + } + + if (x.getSetList().size() != 0) { + print(" SET "); + printAndAccept(x.getSetList(), ", "); + } + + return false; + } + + @Override + public void endVisit(MySqlReplicateStatement x) { + + } + + @Override + public boolean visit(MySqlReplicateStatement x) { + print("REPLACE "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isDelayed()) { + print("DELAYED "); + } + + print("INTO "); + + x.getTableName().accept(this); + + if (x.getColumns().size() > 0) { + print(" ("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + } + + if (x.getValuesList().size() != 0) { + println(); + print("VALUES "); + int size = x.getValuesList().size(); + if (size == 0) { + print("()"); + } else { + for (int i = 0; i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getValuesList().get(i).accept(this); + } + } + } + + if (x.getQuery() != null) { + x.getQuery().accept(this); + } + + if (x.getSetItems().size() != 0) { + println(); + print("SET "); + printAndAccept(x.getSetItems(), ", "); + } + + return false; + } + + @Override + public void endVisit(MySqlSelectGroupBy x) { + + } + + @Override + public boolean visit(MySqlSelectGroupBy x) { + super.visit(x); + + if (x.isRollUp()) { + print(" WITH ROLLUP"); + } + + return false; + } + + @Override + public void endVisit(MySqlStartTransactionStatement x) { + + } + + @Override + public boolean visit(MySqlStartTransactionStatement x) { + print("START TRANSACTION"); + if (x.isConsistentSnapshot()) { + print(" WITH CONSISTENT SNAPSHOT"); + } + + if (x.isBegin()) { + print(" BEGIN"); + } + + if (x.isWork()) { + print(" WORK"); + } + + return false; + } + + @Override + public void endVisit(MySqlCommitStatement x) { + + } + + @Override + public boolean visit(MySqlCommitStatement x) { + print("COMMIT"); + + if (x.isWork()) { + print(" WORK"); + } + + if (x.getChain() != null) { + if (x.getChain().booleanValue()) { + print(" AND CHAIN"); + } else { + print(" AND NO CHAIN"); + } + } + + if (x.getRelease() != null) { + if (x.getRelease().booleanValue()) { + print(" AND RELEASE"); + } else { + print(" AND NO RELEASE"); + } + } + + return false; + } + + @Override + public void endVisit(MySqlRollbackStatement x) { + + } + + @Override + public boolean visit(MySqlRollbackStatement x) { + print("ROLLBACK"); + + if (x.isWork()) { + print(" WORK"); + } + + if (x.getChain() != null) { + if (x.getChain().booleanValue()) { + print(" AND CHAIN"); + } else { + print(" AND NO CHAIN"); + } + } + + if (x.getRelease() != null) { + if (x.getRelease().booleanValue()) { + print(" AND RELEASE"); + } else { + print(" AND NO RELEASE"); + } + } + + return false; + } + + @Override + public void endVisit(MySqlShowColumnsStatement x) { + + } + + @Override + public boolean visit(MySqlShowColumnsStatement x) { + if (x.isFull()) { + print("SHOW FULL COLUMNS"); + } else { + print("SHOW COLUMNS"); + } + + if (x.getTable() != null) { + print(" FROM "); + x.getTable().accept(this); + } + + if (x.getDatabase() != null) { + print(" FROM "); + x.getDatabase().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowTablesStatement x) { + + } + + @Override + public boolean visit(MySqlShowTablesStatement x) { + if (x.isFull()) { + print("SHOW FULL TABLES"); + } else { + print("SHOW TABLES"); + } + + if (x.getDatabase() != null) { + print(" FROM "); + x.getDatabase().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } - return false; - } + return false; + } - @Override - public void endVisit(MySqlShowDatabasesStatement x) { + @Override + public void endVisit(MySqlShowDatabasesStatement x) { - } - - @Override - public boolean visit(MySqlShowDatabasesStatement x) { - print("SHOW DATABASES"); - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - - return false; - } + } + + @Override + public boolean visit(MySqlShowDatabasesStatement x) { + print("SHOW DATABASES"); + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + + return false; + } - @Override - public void endVisit(MySqlShowWarningsStatement x) { + @Override + public void endVisit(MySqlShowWarningsStatement x) { - } + } - @Override - public boolean visit(MySqlShowWarningsStatement x) { - if (x.isCount()) { - print("SHOW COUNT(*) WARNINGS"); - } else { - print("SHOW WARNINGS"); - if (x.getLimit() != null) { - print(' '); - x.getLimit().accept(this); - } - } - - return false; - } - - @Override - public void endVisit(MySqlShowStatusStatement x) { + @Override + public boolean visit(MySqlShowWarningsStatement x) { + if (x.isCount()) { + print("SHOW COUNT(*) WARNINGS"); + } else { + print("SHOW WARNINGS"); + if (x.getLimit() != null) { + print(' '); + x.getLimit().accept(this); + } + } + + return false; + } - } - - @Override - public boolean visit(MySqlShowStatusStatement x) { - print("SHOW "); + @Override + public void endVisit(MySqlShowStatusStatement x) { - if (x.isGlobal()) { - print("GLOBAL "); - } + } - if (x.isSession()) { - print("SESSION "); - } + @Override + public boolean visit(MySqlShowStatusStatement x) { + print("SHOW "); - print("STATUS"); + if (x.isGlobal()) { + print("GLOBAL "); + } - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } + if (x.isSession()) { + print("SESSION "); + } - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } + print("STATUS"); - return false; - } + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } - @Override - public void endVisit(MySqlLoadXmlStatement x) { + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } - } + return false; + } - @Override - public boolean visit(MySqlLoadXmlStatement x) { - print("LOAD XML "); + @Override + public void endVisit(MySqlLoadXmlStatement x) { - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } + } - if (x.isConcurrent()) { - print("CONCURRENT "); - } + @Override + public boolean visit(MySqlLoadXmlStatement x) { + print("LOAD XML "); - if (x.isLocal()) { - print("LOCAL "); - } + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } - print("INFILE "); + if (x.isConcurrent()) { + print("CONCURRENT "); + } - x.getFileName().accept(this); + if (x.isLocal()) { + print("LOCAL "); + } - if (x.isReplicate()) { - print(" REPLACE "); - } + print("INFILE "); - if (x.isIgnore()) { - print(" IGNORE "); - } + x.getFileName().accept(this); - print(" INTO TABLE "); - x.getTableName().accept(this); + if (x.isReplicate()) { + print(" REPLACE "); + } - if (x.getCharset() != null) { - print(" CHARSET "); - print(x.getCharset()); - } + if (x.isIgnore()) { + print(" IGNORE "); + } - if (x.getRowsIdentifiedBy() != null) { - print(" ROWS IDENTIFIED BY "); - x.getRowsIdentifiedBy().accept(this); - } + print(" INTO TABLE "); + x.getTableName().accept(this); - if (x.getSetList().size() != 0) { - print(" SET "); - printAndAccept(x.getSetList(), ", "); - } + if (x.getCharset() != null) { + print(" CHARSET "); + print(x.getCharset()); + } - return false; - } - - @Override - public void endVisit(CobarShowStatus x) { - - } + if (x.getRowsIdentifiedBy() != null) { + print(" ROWS IDENTIFIED BY "); + x.getRowsIdentifiedBy().accept(this); + } - @Override - public boolean visit(CobarShowStatus x) { - print("SHOW COBAR_STATUS"); - return false; - } - + if (x.getSetList().size() != 0) { + print(" SET "); + printAndAccept(x.getSetList(), ", "); + } + + return false; + } + + @Override + public void endVisit(CobarShowStatus x) { + + } + + @Override + public boolean visit(CobarShowStatus x) { + print("SHOW COBAR_STATUS"); + return false; + } @Override public void endVisit(MySqlKillStatement x) { - + } @Override @@ -1220,12 +1229,12 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV x.getThreadId().accept(this); return false; } - + @Override public void endVisit(MySqlBinlogStatement x) { - + } - + @Override public boolean visit(MySqlBinlogStatement x) { print("BINLOG ");