mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser support mysql create procedure.
This commit is contained in:
+19
-11
@@ -3195,17 +3195,19 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
*/
|
||||
SQLCreateProcedureStatement stmt = new SQLCreateProcedureStatement();
|
||||
|
||||
if (identifierEquals("DEFINER")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
SQLName definer = this.exprParser.name();
|
||||
stmt.setDefiner(definer);
|
||||
} else {
|
||||
accept(Token.CREATE);
|
||||
if (lexer.token() == Token.OR) {
|
||||
if (lexer.token() != Token.PROCEDURE) {
|
||||
if (identifierEquals("DEFINER")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.REPLACE);
|
||||
stmt.setOrReplace(true);
|
||||
accept(Token.EQ);
|
||||
SQLName definer = this.exprParser.name();
|
||||
stmt.setDefiner(definer);
|
||||
} else {
|
||||
accept(Token.CREATE);
|
||||
if (lexer.token() == Token.OR) {
|
||||
lexer.nextToken();
|
||||
accept(Token.REPLACE);
|
||||
stmt.setOrReplace(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3218,7 +3220,13 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
parserParameters(stmt.getParameters());
|
||||
accept(Token.RPAREN);// match ")"
|
||||
}
|
||||
SQLBlockStatement block = this.parseBlock();
|
||||
SQLStatement block;
|
||||
|
||||
if (lexer.token() == Token.BEGIN) {
|
||||
block = this.parseBlock();
|
||||
} else {
|
||||
block = this.parseStatement();
|
||||
}
|
||||
|
||||
stmt.setBlock(block);
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 1999-2017 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.bvt.sql.mysql.create;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlCreateProcedureTest10 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "CREATE PROCEDURE p2(p INT) SET @x = p ;";
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
// print(statementList);
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.MYSQL);
|
||||
statemen.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
// System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user