mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
mysql parser show statements
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlShowEngineStatement extends MySqlStatementImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLExpr name;
|
||||
private Option option;
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, name);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Option getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
public void setOption(Option option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public static enum Option {
|
||||
STATUS, MUTEX
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlShowEnginesStatement extends MySqlStatementImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean storage = false;
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public boolean isStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public void setStorage(boolean storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlShowErrorsStatement extends MySqlStatementImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private boolean count = false;
|
||||
private Limit limit;
|
||||
|
||||
public boolean isCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(boolean count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public Limit getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(Limit limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, limit);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
+83
-19
@@ -70,6 +70,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableSta
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTablesStatement;
|
||||
@@ -466,10 +469,48 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
accept(Token.LPAREN);
|
||||
accept(Token.STAR);
|
||||
accept(Token.RPAREN);
|
||||
acceptIdentifier("WARNINGS");
|
||||
|
||||
MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement();
|
||||
stmt.setCount(true);
|
||||
if (identifierEquals("ERRORS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
|
||||
stmt.setCount(true);
|
||||
|
||||
return stmt;
|
||||
} else {
|
||||
acceptIdentifier("WARNINGS");
|
||||
|
||||
MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement();
|
||||
stmt.setCount(true);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
}
|
||||
|
||||
if (identifierEquals("ERRORS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
|
||||
if (lexer.token() == Token.LIMIT) {
|
||||
lexer.nextToken();
|
||||
|
||||
MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit();
|
||||
|
||||
SQLExpr temp = this.exprParser.expr();
|
||||
if (lexer.token() == (Token.COMMA)) {
|
||||
limit.setOffset(temp);
|
||||
lexer.nextToken();
|
||||
limit.setRowCount(exprParser.expr());
|
||||
} else if (identifierEquals("OFFSET")) {
|
||||
limit.setRowCount(temp);
|
||||
lexer.nextToken();
|
||||
limit.setOffset(exprParser.expr());
|
||||
} else {
|
||||
limit.setRowCount(temp);
|
||||
}
|
||||
|
||||
stmt.setLimit(limit);
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
@@ -603,69 +644,92 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
return new MySqlShowContributorsStatement();
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.CREATE) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
if (identifierEquals("DATABASE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
MySqlShowCreateDatabaseStatement stmt = new MySqlShowCreateDatabaseStatement();
|
||||
stmt.setDatabase(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("EVENT")) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
MySqlShowCreateEventStatement stmt = new MySqlShowCreateEventStatement();
|
||||
stmt.setEventName(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("FUNCTION")) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
MySqlShowCreateFunctionStatement stmt = new MySqlShowCreateFunctionStatement();
|
||||
stmt.setName(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("PROCEDURE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
MySqlShowCreateProcedureStatement stmt = new MySqlShowCreateProcedureStatement();
|
||||
stmt.setName(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.TABLE) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
MySqlShowCreateTableStatement stmt = new MySqlShowCreateTableStatement();
|
||||
stmt.setName(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.VIEW) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
MySqlShowCreateViewStatement stmt = new MySqlShowCreateViewStatement();
|
||||
stmt.setName(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
if (identifierEquals("TRIGGER")) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
MySqlShowCreateTriggerStatement stmt = new MySqlShowCreateTriggerStatement();
|
||||
stmt.setName(this.exprParser.name());
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
throw new ParserException("TODO " + lexer.stringVal());
|
||||
}
|
||||
|
||||
if (identifierEquals("ENGINE")) {
|
||||
lexer.nextToken();
|
||||
MySqlShowEngineStatement stmt = new MySqlShowEngineStatement();
|
||||
stmt.setName(this.exprParser.name());
|
||||
stmt.setOption(MySqlShowEngineStatement.Option.valueOf(lexer.stringVal().toUpperCase()));
|
||||
lexer.nextToken();
|
||||
return stmt;
|
||||
}
|
||||
|
||||
if (identifierEquals("STORAGE")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("ENGINES");
|
||||
MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
|
||||
stmt.setStorage(true);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
if (identifierEquals("ENGINES")) {
|
||||
lexer.nextToken();
|
||||
MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
|
||||
return stmt;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO " + lexer.stringVal());
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableSta
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTablesStatement;
|
||||
@@ -291,4 +294,16 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(MySqlShowCreateViewStatement x);
|
||||
|
||||
void endVisit(MySqlShowCreateViewStatement x);
|
||||
|
||||
boolean visit(MySqlShowEngineStatement x);
|
||||
|
||||
void endVisit(MySqlShowEngineStatement x);
|
||||
|
||||
boolean visit(MySqlShowEnginesStatement x);
|
||||
|
||||
void endVisit(MySqlShowEnginesStatement x);
|
||||
|
||||
boolean visit(MySqlShowErrorsStatement x);
|
||||
|
||||
void endVisit(MySqlShowErrorsStatement x);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableSta
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTablesStatement;
|
||||
@@ -630,4 +633,34 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
public void endVisit(MySqlShowCreateViewStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowEngineStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowEngineStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowEnginesStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowEnginesStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowErrorsStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowErrorsStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableSta
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTablesStatement;
|
||||
@@ -1677,4 +1680,52 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
public void endVisit(MySqlShowCreateViewStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowEngineStatement x) {
|
||||
print("SHOW ENGINE ");
|
||||
x.getName().accept(this);
|
||||
print(' ');
|
||||
print(x.getOption().name());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowEngineStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowEnginesStatement x) {
|
||||
if (x.isStorage()) {
|
||||
print("SHOW STORAGE ENGINES");
|
||||
} else {
|
||||
print("SHOW ENGINES");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowEnginesStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowErrorsStatement x) {
|
||||
if (x.isCount()) {
|
||||
print("SHOW COUNT(*) ERRORS");
|
||||
} else {
|
||||
print("SHOW ERRORS");
|
||||
if (x.getLimit() != null) {
|
||||
print(' ');
|
||||
x.getLimit().accept(this);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowErrorsStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableSta
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTablesStatement;
|
||||
@@ -692,4 +695,34 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
public void endVisit(MySqlShowCreateViewStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowEngineStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowEngineStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowEnginesStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowEnginesStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowErrorsStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowErrorsStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedur
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
@@ -407,113 +411,117 @@ public class DALParserTest extends TestCase {
|
||||
Assert.assertEquals("SHOW CREATE VIEW x", output);
|
||||
}
|
||||
|
||||
public void test_show_databases() throws Exception {
|
||||
String sql = "SHOW DATABASES";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowDatabasesStatement show = (MySqlShowDatabasesStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW DATABASES", output);
|
||||
}
|
||||
|
||||
public void test_show_databases_1() throws Exception {
|
||||
String sql = "SHOW DATABASES LIKE 'a%'";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowDatabasesStatement show = (MySqlShowDatabasesStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW DATABASES LIKE 'a%'", output);
|
||||
}
|
||||
|
||||
public void test_show_databases_2() throws Exception {
|
||||
String sql = "SHOW DATABASES WHERE `Database` = 'mysql'";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowDatabasesStatement show = (MySqlShowDatabasesStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW DATABASES WHERE `Database` = 'mysql'", output);
|
||||
}
|
||||
|
||||
public void test_show_engine() throws Exception {
|
||||
String sql = "SHOW ENGINE INNODB STATUS";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowEngineStatement show = (MySqlShowEngineStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW ENGINE INNODB STATUS", output);
|
||||
}
|
||||
|
||||
public void test_show_engine_1() throws Exception {
|
||||
String sql = "SHOW ENGINE PERFORMANCE_SCHEMA STATUS";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowEngineStatement show = (MySqlShowEngineStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW ENGINE PERFORMANCE_SCHEMA STATUS", output);
|
||||
}
|
||||
|
||||
public void test_show_engine_2() throws Exception {
|
||||
String sql = "SHOW ENGINE INNODB mutex";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowEngineStatement show = (MySqlShowEngineStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW ENGINE INNODB MUTEX", output);
|
||||
}
|
||||
|
||||
public void test_show_engines() throws Exception {
|
||||
String sql = "SHOW ENGINES";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowEnginesStatement show = (MySqlShowEnginesStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW ENGINES", output);
|
||||
}
|
||||
|
||||
public void test_show_engines_1() throws Exception {
|
||||
String sql = "SHOW STORAGE ENGINES";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowEnginesStatement show = (MySqlShowEnginesStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW STORAGE ENGINES", output);
|
||||
}
|
||||
|
||||
public void test_show_errors() throws Exception {
|
||||
String sql = "SHOW COUNT(*) ERRORS";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowErrorsStatement show = (MySqlShowErrorsStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW COUNT(*) ERRORS", output);
|
||||
}
|
||||
|
||||
public void test_show_errors_1() throws Exception {
|
||||
String sql = "SHOW ERRORS";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowErrorsStatement show = (MySqlShowErrorsStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW ERRORS", output);
|
||||
}
|
||||
|
||||
public void test_show_errors_2() throws Exception {
|
||||
String sql = "SHOW ERRORS limit 1";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowErrorsStatement show = (MySqlShowErrorsStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW ERRORS LIMIT 1", output);
|
||||
}
|
||||
|
||||
public void test_show_errors_3() throws Exception {
|
||||
String sql = "SHOW ERRORS limit 1, 2";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowErrorsStatement show = (MySqlShowErrorsStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW ERRORS LIMIT 1, 2", output);
|
||||
}
|
||||
|
||||
//
|
||||
// public void testShow() throws Exception {
|
||||
//
|
||||
// sql = "SHOW create trigger tri ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW CREATE TRIGGER tri", output);
|
||||
//
|
||||
// sql = "SHOW create view view";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW CREATE VIEW view", output);
|
||||
//
|
||||
// sql = "SHOW databases like 'var'";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW DATABASES LIKE 'var'", output);
|
||||
//
|
||||
// sql = "SHOW databases where (select * from `select`)is not null";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW DATABASES WHERE (SELECT * FROM `select`) IS NOT NULL", output);
|
||||
//
|
||||
// sql = "SHOW databases ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW DATABASES", output);
|
||||
//
|
||||
// sql = "SHOW engine innodb status";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW ENGINE INNODB STATUS", output);
|
||||
//
|
||||
// sql = "SHOW engine innodb mutex";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW ENGINE INNODB MUTEX", output);
|
||||
//
|
||||
// sql = "SHOW engine performance_schema status";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW ENGINE PERFORMANCE SCHEMA STATUS", output);
|
||||
//
|
||||
// sql = "SHOW engines";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW ENGINES", output);
|
||||
//
|
||||
// sql = "SHOW storage engines";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW ENGINES", output);
|
||||
//
|
||||
// sql = "SHOW errors";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW ERRORS", output);
|
||||
//
|
||||
// sql = "SHOW errors limit 1 ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW ERRORS LIMIT 0, 1", output);
|
||||
//
|
||||
// sql = "SHOW count(*) errors";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
// show = (DALShowStatement) parser.show();
|
||||
// parser.match(Token.EOF);
|
||||
// output = output2MySQL(show, sql);
|
||||
// Assert.assertEquals("SHOW COUNT(*) ERRORS", output);
|
||||
//
|
||||
// sql = "SHOW events";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
|
||||
Reference in New Issue
Block a user