mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
mysql parser
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
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 MySqlShowCreateProcedureStatement extends MySqlStatementImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLExpr name;
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, name);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr functionName) {
|
||||
this.name = functionName;
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
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 MySqlShowCreateTableStatement extends MySqlStatementImpl {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private SQLExpr name;
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, name);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr functionName) {
|
||||
this.name = functionName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -65,6 +65,8 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsSt
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
@@ -627,6 +629,22 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
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;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO " + lexer.stringVal());
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsSt
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
@@ -271,4 +273,12 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(MySqlShowCreateFunctionStatement x);
|
||||
|
||||
void endVisit(MySqlShowCreateFunctionStatement x);
|
||||
|
||||
boolean visit(MySqlShowCreateProcedureStatement x);
|
||||
|
||||
void endVisit(MySqlShowCreateProcedureStatement x);
|
||||
|
||||
boolean visit(MySqlShowCreateTableStatement x);
|
||||
|
||||
void endVisit(MySqlShowCreateTableStatement x);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsSt
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
@@ -586,4 +588,24 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
public void endVisit(MySqlShowCreateFunctionStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowCreateProcedureStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowCreateProcedureStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowCreateTableStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowCreateTableStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsSt
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
@@ -1625,4 +1627,28 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
public void endVisit(MySqlShowCreateFunctionStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowCreateProcedureStatement x) {
|
||||
print("SHOW CREATE PROCEDURE ");
|
||||
x.getName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowCreateProcedureStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowCreateTableStatement x) {
|
||||
print("SHOW CREATE TABLE ");
|
||||
x.getName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowCreateTableStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsSt
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement;
|
||||
@@ -648,4 +650,24 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
public void endVisit(MySqlShowCreateFunctionStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowCreateProcedureStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowCreateProcedureStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlShowCreateTableStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlShowCreateTableStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsSt
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement;
|
||||
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;
|
||||
@@ -367,26 +369,27 @@ public class DALParserTest extends TestCase {
|
||||
Assert.assertEquals("SHOW CREATE FUNCTION x", output);
|
||||
}
|
||||
|
||||
public void test_show_create_PROCEDURE() throws Exception {
|
||||
String sql = "SHOW CREATE PROCEDURE x";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowCreateProcedureStatement show = (MySqlShowCreateProcedureStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW CREATE PROCEDURE x", output);
|
||||
}
|
||||
|
||||
public void test_show_create_table() throws Exception {
|
||||
String sql = "SHOW CREATE table x";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
MySqlShowCreateTableStatement show = (MySqlShowCreateTableStatement) parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(show);
|
||||
Assert.assertEquals("SHOW CREATE TABLE x", output);
|
||||
}
|
||||
|
||||
//
|
||||
// public void testShow() throws Exception {
|
||||
//
|
||||
//
|
||||
// sql = "SHOW create procedure pro ";
|
||||
// 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 PROCEDURE pro", output);
|
||||
//
|
||||
// sql = "SHOW create table tb ";
|
||||
// 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 TABLE tb", output);
|
||||
//
|
||||
// sql = "SHOW create trigger tri ";
|
||||
// lexer = new SQLLexer(sql);
|
||||
// parser = new DALParser(lexer, new SQLExprParser(lexer));
|
||||
|
||||
Reference in New Issue
Block a user