mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #1398 from ZzzCrazyPig/dev
add mysql deallocate prepare statement parse
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MysqlDeallocatePrepareStatement extends MySqlStatementImpl {
|
||||
|
||||
private SQLName statementName;
|
||||
|
||||
public SQLName getStatementName() {
|
||||
return statementName;
|
||||
}
|
||||
|
||||
public void setStatementName(SQLName statementName) {
|
||||
this.statementName = statementName;
|
||||
}
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, statementName);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -182,6 +182,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatem
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
@@ -603,6 +604,12 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(identifierEquals("DEALLOCATE")) {
|
||||
MysqlDeallocatePrepareStatement stmt = parseDeallocatePrepare();
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (identifierEquals("LOAD")) {
|
||||
SQLStatement stmt = parseLoad();
|
||||
@@ -1931,6 +1938,17 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public MysqlDeallocatePrepareStatement parseDeallocatePrepare() {
|
||||
acceptIdentifier("DEALLOCATE");
|
||||
acceptIdentifier("PREPARE");
|
||||
|
||||
MysqlDeallocatePrepareStatement stmt = new MysqlDeallocatePrepareStatement();
|
||||
SQLName statementName = exprParser.name();
|
||||
stmt.setStatementName(statementName);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLInsertStatement parseInsert() {
|
||||
MySqlInsertStatement insertStatement = new MySqlInsertStatement();
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateTableSource;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
@@ -170,6 +171,10 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(MySqlPrepareStatement x);
|
||||
|
||||
void endVisit(MySqlExecuteStatement x);
|
||||
|
||||
boolean visit(MysqlDeallocatePrepareStatement x);
|
||||
|
||||
void endVisit(MysqlDeallocatePrepareStatement x);
|
||||
|
||||
boolean visit(MySqlExecuteStatement x);
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateTableSource;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
||||
|
||||
public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySqlASTVisitor {
|
||||
@@ -228,6 +229,16 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MysqlDeallocatePrepareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MysqlDeallocatePrepareStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlDeleteStatement x) {
|
||||
|
||||
@@ -163,6 +163,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateTableSource;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
@@ -875,6 +876,17 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MysqlDeallocatePrepareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
public boolean visit(MysqlDeallocatePrepareStatement x) {
|
||||
print0(ucase ? "DEALLOCATE PREPARE " : "deallocate prepare ");
|
||||
x.getStatementName().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlDeleteStatement x) {
|
||||
|
||||
@@ -144,6 +144,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateTableSource;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Mode;
|
||||
@@ -324,6 +325,16 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MysqlDeallocatePrepareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MysqlDeallocatePrepareStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlLoadDataInFileStatement x) {
|
||||
|
||||
@@ -84,6 +84,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -101,6 +102,7 @@ public class MySqlASTVisitorAdapterTest extends TestCase {
|
||||
new SQLBinaryExpr().accept(adapter);
|
||||
new MySqlPrepareStatement().accept(adapter);
|
||||
new MySqlExecuteStatement().accept(adapter);
|
||||
new MysqlDeallocatePrepareStatement().accept(adapter);
|
||||
new MySqlDeleteStatement().accept(adapter);
|
||||
new MySqlInsertStatement().accept(adapter);
|
||||
new MySqlLoadXmlStatement().accept(adapter);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DeallocatePrepareTest extends TestCase {
|
||||
|
||||
public void test() {
|
||||
String sql = "DEALLOCATE PREPARE stmt1";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt =parser.parseStatement();
|
||||
Assert.assertEquals(MysqlDeallocatePrepareStatement.class, stmt.getClass());
|
||||
MysqlDeallocatePrepareStatement dpStmt = (MysqlDeallocatePrepareStatement) stmt;
|
||||
Assert.assertEquals("stmt1", dpStmt.getStatementName().getSimpleName());
|
||||
Assert.assertEquals(sql, dpStmt.toString());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user