improved mysql parser support flush statement.

This commit is contained in:
wenshao
2017-12-04 17:57:42 +08:00
parent 89f6a40ed3
commit 73fdc1a75f
17 changed files with 1013 additions and 11 deletions
@@ -934,8 +934,6 @@ public class MySqlStatementParser extends SQLStatementParser {
stmt.setLocal(true);
}
acceptIdentifier("TABLES");
for (;;) {
if (lexer.token() == Token.WITH) {
lexer.nextToken();
@@ -946,7 +944,7 @@ public class MySqlStatementParser extends SQLStatementParser {
lexer.nextToken();
acceptIdentifier("EXPORT");
stmt.setForExport(true);
} else if (lexer.identifierEquals("BINARY")) {
} else if (lexer.identifierEquals("BINARY") || lexer.token() == Token.BINARY) {
lexer.nextToken();
acceptIdentifier("LOGS");
stmt.setBinaryLogs(true);
@@ -979,11 +977,12 @@ public class MySqlStatementParser extends SQLStatementParser {
stmt.setOptimizerCosts(true);
} else if (lexer.identifierEquals("QUERY")) {
lexer.nextToken();
acceptIdentifier("CACHE");
accept(Token.CACHE);
stmt.setQueryCache(true);
} else if (lexer.identifierEquals("RELAY")) {
lexer.nextToken();
acceptIdentifier("LOGS");
stmt.setRelayLogs(true);
if (lexer.token() == Token.FOR) {
lexer.nextToken();
acceptIdentifier("CHANNEL");
@@ -996,10 +995,11 @@ public class MySqlStatementParser extends SQLStatementParser {
} else if (lexer.identifierEquals("STATUS")) {
lexer.nextToken();
stmt.setStatus(true);
} else if (lexer.identifierEquals("USER_RESOURCES")) {
} else if (lexer.identifierEquals("USER_RESOURCES")) {
lexer.nextToken();
stmt.setUserResources(true);
} else if (lexer.token() == Token.IDENTIFIER){
} else if (lexer.identifierEquals(FnvHash.Constants.TABLES)) {
lexer.nextToken();
for (;;) {
SQLName name = this.exprParser.name();
stmt.addTable(name);
@@ -3584,14 +3584,77 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
@Override
public boolean visit(MySqlFlushStatement x) {
print0(ucase ? "FLUSH " : "flush ");
print0(ucase ? "FLUSH" : "flush");
print0(ucase ? "TABLES" : "tables");
if (x.isBinaryLogs()) {
print0(ucase ? " BINARY LOGS" : " binary logs");
}
if (x.isPrivileges()) {
print0(ucase ? " PRIVILEGES" : " privileges");
}
if (x.isDesKeyFile()) {
print0(ucase ? " DES_KEY_FILE" : " des_key_file");
}
if (x.isEngineLogs()) {
print0(ucase ? " ENGINE LOGS" : " engine logs");
}
if (x.isErrorLogs()) {
print0(ucase ? " ERROR LOGS" : " error logs");
}
if (x.isGeneralLogs()) {
print0(ucase ? " GENERAL LOGS" : " general logs");
}
if (x.isHots()) {
print0(ucase ? " HOSTS" : " hosts");
}
if (x.isLogs()) {
print0(ucase ? " LOGS" : " logs");
}
if (x.isOptimizerCosts()) {
print0(ucase ? " OPTIMIZER_COSTS" : " optimizer_costs");
}
if (x.isQueryCache()) {
print0(ucase ? " QUERY CACHE" : " query cache");
}
if (x.isSlowLogs()) {
print0(ucase ? " SLOW LOGS" : " slow logs");
}
if (x.isStatus()) {
print0(ucase ? " STATUS" : " status");
}
if (x.isUserResources()) {
print0(ucase ? " USER_RESOURCES" : " user_resources");
}
if (x.isRelayLogs()) {
print0(ucase ? " RELAY LOGS" : " relay logs");
SQLExpr channel = x.getRelayLogsForChannel();
if (channel != null) {
print(' ');
channel.accept(this);
}
}
List<SQLExprTableSource> tables = x.getTables();
if (tables.size() > 0) {
print(' ');
printAndAccept(tables, ", ");
if (tables != null && tables.size() > 0) {
print0(ucase ? " TABLES" : " tables");
if (tables.size() > 0) {
print(' ');
printAndAccept(tables, ", ");
}
}
if (x.isWithReadLock()) {
@@ -624,5 +624,6 @@ public final class FnvHash {
long MERGE = fnv1a_64_lower("MERGE");
long INHERITS = fnv1a_64_lower("INHERITS");
long DELIMITED = fnv1a_64_lower("DELIMITED");
long TABLES = fnv1a_64_lower("TABLES");
}
}