mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve flush syntax support for mysql 5.7 ;
This commit is contained in:
+9
@@ -50,6 +50,7 @@ public class MySqlFlushStatement extends MySqlStatementImpl {
|
||||
private boolean slowLogs;
|
||||
private boolean status;
|
||||
private boolean userResources;
|
||||
private boolean tableOption;
|
||||
|
||||
public boolean isNoWriteToBinlog() {
|
||||
return noWriteToBinlog;
|
||||
@@ -207,6 +208,14 @@ public class MySqlFlushStatement extends MySqlStatementImpl {
|
||||
this.errorLogs = errorLogs;
|
||||
}
|
||||
|
||||
public boolean isTableOption() {
|
||||
return tableOption;
|
||||
}
|
||||
|
||||
public void setTableOption(boolean tableOption) {
|
||||
this.tableOption = tableOption;
|
||||
}
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, tables);
|
||||
|
||||
+45
-21
@@ -935,16 +935,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("READ");
|
||||
accept(Token.LOCK);
|
||||
stmt.setWithReadLock(true);
|
||||
} else if (lexer.token() == Token.FOR) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("EXPORT");
|
||||
stmt.setForExport(true);
|
||||
} else if (lexer.identifierEquals("BINARY") || lexer.token() == Token.BINARY) {
|
||||
if (lexer.token() == Token.BINARY || lexer.identifierEquals("BINARY")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("LOGS");
|
||||
stmt.setBinaryLogs(true);
|
||||
@@ -992,28 +983,61 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("LOGS");
|
||||
stmt.setSlowLogs(true);
|
||||
} else if (lexer.identifierEquals("STATUS")) {
|
||||
} 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.identifierEquals(FnvHash.Constants.TABLES)) {
|
||||
} else if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
for (;;) {
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.addTable(name);
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
if (lexer.identifierEquals("TABLES")) {
|
||||
lexer.nextToken();
|
||||
|
||||
stmt.setTableOption(true);
|
||||
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("READ");
|
||||
accept(Token.LOCK);
|
||||
stmt.setWithReadLock(true);
|
||||
}
|
||||
for(;;) {
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
for (; ; ) {
|
||||
SQLName name = this.exprParser.name();
|
||||
stmt.addTable(name);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
if (stmt.getTables().size() != 0) {
|
||||
if (lexer.token() == Token.FOR) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("EXPORT");
|
||||
stmt.setForExport(true);
|
||||
} else if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("READ");
|
||||
accept(Token.LOCK);
|
||||
stmt.setWithReadLock(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return stmt;
|
||||
|
||||
@@ -3586,83 +3586,76 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
public boolean visit(MySqlFlushStatement x) {
|
||||
print0(ucase ? "FLUSH" : "flush");
|
||||
|
||||
if (x.isBinaryLogs()) {
|
||||
if (x.isNoWriteToBinlog()) {
|
||||
print0(ucase ? " NO_WRITE_TO_BINLOG" : " no_write_to_binlog");
|
||||
} else if (x.isLocal()) {
|
||||
print0(ucase ? " LOCAL" : " local");
|
||||
}
|
||||
|
||||
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.isPrivileges()) {
|
||||
print0(ucase ? " PRIVILEGES" : " privileges");
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
List<SQLExprTableSource> tables = x.getTables();
|
||||
if (tables != null && tables.size() > 0) {
|
||||
if(x.isTableOption()){
|
||||
print0(ucase ? " TABLES" : " tables");
|
||||
if (tables.size() > 0) {
|
||||
|
||||
List<SQLExprTableSource> tables = x.getTables();
|
||||
if (tables != null && tables.size() > 0) {
|
||||
print(' ');
|
||||
printAndAccept(tables, ", ");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.isWithReadLock()) {
|
||||
print0(ucase ? " WITH READ LOCK" : " with read lock");
|
||||
}
|
||||
if (x.isWithReadLock()) {
|
||||
print0(ucase ? " WITH READ LOCK" : " with read lock");
|
||||
}
|
||||
|
||||
if (x.isForExport()) {
|
||||
print0(ucase ? " FOR EXPORT" : " for export");
|
||||
if (x.isForExport()) {
|
||||
print0(ucase ? " FOR EXPORT" : " for export");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user