增加mysql存储过程LOOP,REPAET,LEAVE,ITEARATE语法支持,以及支持BEGIN-END和WHILE语句标签支持

This commit is contained in:
zhujunxxxxx
2015-09-14 18:32:27 +08:00
parent 44ce8cb8fa
commit 02a8376f09
23 changed files with 1207 additions and 27 deletions
@@ -1,3 +1,18 @@
/*
* 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.clause;
import java.util.ArrayList;
@@ -19,7 +34,7 @@ public class MySqlCaseStatement extends MySqlStatementImpl{
//case expr
private SQLExpr condition;
//when statement list
private List<MySqlWhenfStatement> whenList=new ArrayList<MySqlCaseStatement.MySqlWhenfStatement>();
private List<MySqlWhenStatement> whenList=new ArrayList<MySqlCaseStatement.MySqlWhenStatement>();
//else statement
private MySqlElseStatement elseItem;
@@ -31,15 +46,15 @@ public class MySqlCaseStatement extends MySqlStatementImpl{
this.condition = condition;
}
public List<MySqlWhenfStatement> getWhenList() {
public List<MySqlWhenStatement> getWhenList() {
return whenList;
}
public void setWhenList(List<MySqlWhenfStatement> whenList) {
public void setWhenList(List<MySqlWhenStatement> whenList) {
this.whenList = whenList;
}
public void addWhenStatement(MySqlWhenfStatement stmt)
public void addWhenStatement(MySqlWhenStatement stmt)
{
this.whenList.add(stmt);
}
@@ -68,7 +83,7 @@ public class MySqlCaseStatement extends MySqlStatementImpl{
* @author zz
*
*/
public static class MySqlWhenfStatement extends MySqlObjectImpl {
public static class MySqlWhenStatement extends MySqlObjectImpl {
private SQLExpr condition;
private List<SQLStatement> statements = new ArrayList<SQLStatement>();
@@ -1,3 +1,18 @@
/*
* 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.clause;
import java.util.ArrayList;
@@ -1,3 +1,18 @@
/*
* 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.clause;
import java.util.ArrayList;
@@ -1,3 +1,18 @@
/*
* 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.clause;
import java.util.ArrayList;
@@ -1,3 +1,18 @@
/*
* 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.clause;
import java.util.ArrayList;
@@ -0,0 +1,46 @@
/*
* 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.clause;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStatementImpl;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
/**
*
* @Description: MySql procedure iterate statement
* @author zz email:455910092@qq.com
* @date 2015-9-14
* @version V1.0
*/
public class MySqlIterateStatement extends MySqlStatementImpl {
private String labelName;
@Override
public void accept0(MySqlASTVisitor visitor) {
visitor.visit(this);
visitor.endVisit(this);
}
public String getLabelName() {
return labelName;
}
public void setLabelName(String labelName) {
this.labelName = labelName;
}
}
@@ -0,0 +1,46 @@
/*
* 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.clause;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStatementImpl;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
/**
*
* @Description: MySql procedure leave statement
* @author zz email:455910092@qq.com
* @date 2015-9-14
* @version V1.0
*/
public class MySqlLeaveStatement extends MySqlStatementImpl {
private String labelName;
@Override
public void accept0(MySqlASTVisitor visitor) {
visitor.visit(this);
visitor.endVisit(this);
}
public String getLabelName() {
return labelName;
}
public void setLabelName(String labelName) {
this.labelName = labelName;
}
}
@@ -0,0 +1,62 @@
/*
* 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.clause;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStatementImpl;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
/**
*
* @Description: MySql procedure loop statement
* @author zz email:455910092@qq.com
* @date 2015-9-14
* @version V1.0
*/
public class MySqlLoopStatement extends MySqlStatementImpl {
private String labelName;
private List<SQLStatement> statements = new ArrayList<SQLStatement>();
@Override
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, statements);
}
visitor.endVisit(this);
}
public List<SQLStatement> getStatements() {
return statements;
}
public void setStatements(List<SQLStatement> statements) {
this.statements = statements;
}
public String getLabelName() {
return labelName;
}
public void setLabelName(String labelName) {
this.labelName = labelName;
}
}
@@ -0,0 +1,73 @@
/*
* 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.clause;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStatementImpl;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
/**
*
* @Description: MySql procedure repeat statement
* @author zz email:455910092@qq.com
* @date 2015-9-14
* @version V1.0
*/
public class MySqlRepeatStatement extends MySqlStatementImpl {
private String labelName;
private List<SQLStatement> statements = new ArrayList<SQLStatement>();
private SQLExpr condition;
@Override
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, statements);
acceptChild(visitor, condition);
}
visitor.endVisit(this);
}
public List<SQLStatement> getStatements() {
return statements;
}
public void setStatements(List<SQLStatement> statements) {
this.statements = statements;
}
public String getLabelName() {
return labelName;
}
public void setLabelName(String labelName) {
this.labelName = labelName;
}
public SQLExpr getCondition() {
return condition;
}
public void setCondition(SQLExpr condition) {
this.condition = condition;
}
}
@@ -1,3 +1,18 @@
/*
* 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.clause;
import java.util.ArrayList;
@@ -1,3 +1,18 @@
/*
* 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.clause;
import com.alibaba.druid.sql.ast.SQLStatement;
@@ -1,3 +1,18 @@
/*
* 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.clause;
import java.util.ArrayList;
@@ -20,8 +35,18 @@ public class MySqlWhileStatement extends MySqlStatementImpl {
//while expr
private SQLExpr condition;
private List<SQLStatement> statements = new ArrayList<SQLStatement>();
//while label name
private String labelName;
public String getLabelName() {
return labelName;
}
public void setLabelName(String labelName) {
this.labelName = labelName;
}
@Override
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
@@ -23,7 +23,13 @@ import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
public class MySqlBlockStatement extends MySqlStatementImpl {
private List<SQLStatement> statementList = new ArrayList<SQLStatement>();
/**
* begin-end block label name
* @author zz
*/
private String labelName;
private List<SQLStatement> statementList = new ArrayList<SQLStatement>();
public List<SQLStatement> getStatementList() {
return statementList;
@@ -33,6 +39,14 @@ public class MySqlBlockStatement extends MySqlStatementImpl {
this.statementList = statementList;
}
public String getLabelName() {
return labelName;
}
public void setLabelName(String labelName) {
this.labelName = labelName;
}
@Override
public void accept0(MySqlASTVisitor visitor) {
if (visitor.visit(this)) {
@@ -62,13 +62,17 @@ import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCreateProcedureStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlElseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIterateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLeaveStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLoopStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement.MySqlElseIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlParameter;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlRepeatStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus;
@@ -2840,6 +2844,9 @@ public class MySqlStatementParser extends SQLStatementParser {
if (lexer.token() == Token.WHEN) {
return;
}
if (lexer.token() == Token.UNTIL) {
return;
}
// select into
if (lexer.token() == (Token.SELECT)) {
statementList.add(this.parseSelectInto());
@@ -2930,6 +2937,12 @@ public class MySqlStatementParser extends SQLStatementParser {
continue;
}
// loop statement
if (lexer.token() == Token.LOOP) {
statementList.add(this.parseLoop());
continue;
}
// if statement
if (lexer.token() == Token.IF) {
statementList.add(this.parseIf());
@@ -2948,6 +2961,61 @@ public class MySqlStatementParser extends SQLStatementParser {
continue;
}
// leave statement
if (lexer.token() == Token.LEAVE) {
statementList.add(this.parseLeave());
continue;
}
// iterate statement
if (lexer.token() == Token.ITERATE) {
statementList.add(this.parseIterate());
continue;
}
// repeat statement
if (lexer.token() == Token.REPEAT) {
statementList.add(this.parseRepeat());
continue;
}
if(lexer.token() == Token.IDENTIFIER)
{
String label=lexer.stringVal();
char ch = lexer.current();
int bp = lexer.bp();
lexer.nextToken();
if(lexer.token()==Token.VARIANT&&lexer.stringVal().equals(":"))
{
lexer.nextToken();
if(lexer.token()==Token.LOOP)
{
//parse loop statement
statementList.add(this.parseLoop(label));
}
else if(lexer.token()==Token.WHILE)
{
//parse while statement with label
statementList.add(this.parseWhile(label));
}
else if(lexer.token()==Token.BEGIN)
{
//parse begin-end statement with label
statementList.add(this.parseBlock(label));
}
else if(lexer.token()==Token.REPEAT)
{
//parse repeat statement with label
statementList.add(this.parseRepeat(label));
}
continue;
}
else
{
lexer.reset(bp, ch, Token.IDENTIFIER);
}
}
throw new ParserException("TODO : " + lexer.token() + " "
+ lexer.stringVal());
}
@@ -3022,6 +3090,35 @@ public class MySqlStatementParser extends SQLStatementParser {
}
/**
* parse while statement with label
* @return MySqlWhileStatement
*/
public MySqlWhileStatement parseWhile(String label) {
accept(Token.WHILE);
MySqlWhileStatement stmt = new MySqlWhileStatement();
stmt.setLabelName(label);
stmt.setCondition(this.exprParser.expr());
accept(Token.DO);
this.parseProcedureStatementList(stmt.getStatements());
accept(Token.END);
accept(Token.WHILE);
acceptIdentifier(label);
accept(Token.SEMI);
return stmt;
}
/**
* parse case statement
* @return MySqlCaseStatement
@@ -3035,7 +3132,7 @@ public class MySqlStatementParser extends SQLStatementParser {
{
while (lexer.token() == Token.WHEN) {
MySqlWhenfStatement when=new MySqlWhenfStatement();
MySqlWhenStatement when=new MySqlWhenStatement();
//when expr
when.setCondition(exprParser.expr());
@@ -3061,7 +3158,7 @@ public class MySqlStatementParser extends SQLStatementParser {
while (lexer.token() == Token.WHEN) {
accept(Token.WHEN);
MySqlWhenfStatement when=new MySqlWhenfStatement();
MySqlWhenStatement when=new MySqlWhenStatement();
//when expr
when.setCondition(exprParser.expr());
@@ -3141,4 +3238,108 @@ public class MySqlStatementParser extends SQLStatementParser {
MySqlSelectIntoParser parse=new MySqlSelectIntoParser(this.exprParser);
return parse.parseSelectInto();
}
/**
* parse loop statement
*/
public MySqlLoopStatement parseLoop()
{
MySqlLoopStatement loopStmt=new MySqlLoopStatement();
accept(Token.LOOP);
parseProcedureStatementList(loopStmt.getStatements());
accept(Token.END);
accept(Token.LOOP);
accept(Token.SEMI);
return loopStmt;
}
/**
* parse loop statement with label
*/
public MySqlLoopStatement parseLoop(String label)
{
MySqlLoopStatement loopStmt=new MySqlLoopStatement();
loopStmt.setLabelName(label);
accept(Token.LOOP);
parseProcedureStatementList(loopStmt.getStatements());
accept(Token.END);
accept(Token.LOOP);
acceptIdentifier(label);
accept(Token.SEMI);
return loopStmt;
}
/**
* parse loop statement with label
*/
public MySqlBlockStatement parseBlock(String label) {
MySqlBlockStatement block = new MySqlBlockStatement();
block.setLabelName(label);
accept(Token.BEGIN);
parseProcedureStatementList(block.getStatementList());
accept(Token.END);
acceptIdentifier(label);
return block;
}
/**
* parse leave statement
*/
public MySqlLeaveStatement parseLeave()
{
accept(Token.LEAVE);
MySqlLeaveStatement leaveStmt=new MySqlLeaveStatement();
leaveStmt.setLabelName(exprParser.name().getSimpleName());
accept(Token.SEMI);
return leaveStmt;
}
/**
* parse iterate statement
*/
public MySqlIterateStatement parseIterate()
{
accept(Token.ITERATE);
MySqlIterateStatement iterateStmt=new MySqlIterateStatement();
iterateStmt.setLabelName(exprParser.name().getSimpleName());
accept(Token.SEMI);
return iterateStmt;
}
/**
* parse repeat statement
* @return
*/
public MySqlRepeatStatement parseRepeat()
{
MySqlRepeatStatement repeatStmt=new MySqlRepeatStatement();
accept(Token.REPEAT);
parseProcedureStatementList(repeatStmt.getStatements());
accept(Token.UNTIL);
repeatStmt.setCondition(exprParser.expr());
accept(Token.END);
accept(Token.REPEAT);
accept(Token.SEMI);
return repeatStmt;
}
/**
* parse repeat statement with label
* @param label
* @return
*/
public MySqlRepeatStatement parseRepeat(String label)
{
MySqlRepeatStatement repeatStmt=new MySqlRepeatStatement();
repeatStmt.setLabelName(label);
accept(Token.REPEAT);
parseProcedureStatementList(repeatStmt.getStatements());
accept(Token.UNTIL);
repeatStmt.setCondition(exprParser.expr());
accept(Token.END);
accept(Token.REPEAT);
acceptIdentifier(label);
accept(Token.SEMI);
return repeatStmt;
}
}
@@ -23,13 +23,17 @@ import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint;
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCreateProcedureStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlElseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement.MySqlElseIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIterateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLeaveStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLoopStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlParameter;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlRepeatStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
@@ -622,7 +626,23 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
void endVisit(MySqlSelectIntoStatement x);
boolean visit(MySqlWhenfStatement x);
boolean visit(MySqlWhenStatement x);
void endVisit(MySqlWhenfStatement x);
void endVisit(MySqlWhenStatement x);
boolean visit(MySqlLoopStatement x);
void endVisit(MySqlLoopStatement x);
boolean visit(MySqlLeaveStatement x);
void endVisit(MySqlLeaveStatement x);
boolean visit(MySqlIterateStatement x);
void endVisit(MySqlIterateStatement x);
boolean visit(MySqlRepeatStatement x);
void endVisit(MySqlRepeatStatement x);
} //
@@ -23,13 +23,17 @@ import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint;
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCreateProcedureStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlElseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement.MySqlElseIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIterateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLeaveStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLoopStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlParameter;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlRepeatStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
@@ -1390,16 +1394,64 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
}
@Override
public boolean visit(MySqlWhenfStatement x) {
public boolean visit(MySqlWhenStatement x) {
// TODO Auto-generated method stub
return true;
}
@Override
public void endVisit(MySqlWhenfStatement x) {
public void endVisit(MySqlWhenStatement x) {
// TODO Auto-generated method stub
}
//add:end
@Override
public boolean visit(MySqlLoopStatement x) {
// TODO Auto-generated method stub
return true;
}
@Override
public void endVisit(MySqlLoopStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlLeaveStatement x) {
// TODO Auto-generated method stub
return false;
}
@Override
public void endVisit(MySqlLeaveStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlIterateStatement x) {
// TODO Auto-generated method stub
return false;
}
@Override
public void endVisit(MySqlIterateStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlRepeatStatement x) {
// TODO Auto-generated method stub
return false;
}
@Override
public void endVisit(MySqlRepeatStatement x) {
// TODO Auto-generated method stub
}
} //
@@ -45,13 +45,17 @@ import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint;
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCreateProcedureStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlElseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement.MySqlElseIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIterateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLeaveStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLoopStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlParameter;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlRepeatStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
@@ -3187,6 +3191,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
@Override
public boolean visit(MySqlBlockStatement x) {
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(x.getLabelName()+": ");
print("BEGIN");
incrementIndent();
println();
@@ -3202,6 +3208,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
decrementIndent();
println();
print("END");
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(" "+x.getLabelName());
return false;
}
@@ -3289,6 +3297,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
@Override
public boolean visit(MySqlWhileStatement x) {
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(x.getLabelName()+": ");
print("WHILE ");
x.getCondition().accept(this);
print(" DO");
@@ -3303,6 +3313,8 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
}
println();
print("END WHILE");
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(" "+x.getLabelName());
return false;
}
@@ -3442,7 +3454,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
}
@Override
public boolean visit(MySqlWhenfStatement x) {
public boolean visit(MySqlWhenStatement x) {
print("WHEN ");
x.getCondition().accept(this);
println(" THEN");
@@ -3457,7 +3469,89 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
}
@Override
public void endVisit(MySqlWhenfStatement x) {
public void endVisit(MySqlWhenStatement x) {
}
@Override
public boolean visit(MySqlLoopStatement x) {
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(x.getLabelName()+": ");
print("LOOP ");
println();
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
SQLStatement item = x.getStatements().get(i);
item.setParent(x);
item.accept(this);
if (i != size - 1) {
println();
}
}
println();
print("END LOOP");
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(" "+x.getLabelName());
return false;
}
@Override
public void endVisit(MySqlLoopStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlLeaveStatement x) {
print("LEAVE "+x.getLabelName());
return false;
}
@Override
public void endVisit(MySqlLeaveStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlIterateStatement x) {
print("ITERATE "+x.getLabelName());
return false;
}
@Override
public void endVisit(MySqlIterateStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlRepeatStatement x) {
// TODO Auto-generated method stub
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(x.getLabelName()+": ");
print("REPEAT ");
println();
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
SQLStatement item = x.getStatements().get(i);
item.setParent(x);
item.accept(this);
if (i != size - 1) {
println();
}
}
println();
print("UNTIL ");
x.getCondition().accept(this);
println();
print("END REPEAT");
if(x.getLabelName()!=null&&!x.getLabelName().equals(""))
print(" "+x.getLabelName());
return false;
}
@Override
public void endVisit(MySqlRepeatStatement x) {
// TODO Auto-generated method stub
}
@@ -38,13 +38,17 @@ import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint;
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCaseStatement.MySqlWhenStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlCreateProcedureStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlElseStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIfStatement.MySqlElseIfStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIterateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLeaveStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLoopStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlParameter;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlRepeatStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlWhileStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
@@ -1409,7 +1413,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
@Override
public boolean visit(MySqlWhileStatement x) {
// TODO Auto-generated method stub
accept(x.getStatements());
return false;
}
@@ -1421,7 +1425,9 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
@Override
public boolean visit(MySqlIfStatement x) {
// TODO Auto-generated method stub
accept(x.getStatements());
accept(x.getElseIfList());
accept(x.getElseItem());
return false;
}
@@ -1433,7 +1439,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
@Override
public boolean visit(MySqlElseIfStatement x) {
// TODO Auto-generated method stub
accept(x.getStatements());
return false;
}
@@ -1445,7 +1451,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
@Override
public boolean visit(MySqlElseStatement x) {
// TODO Auto-generated method stub
accept(x.getStatements());
return false;
}
@@ -1457,7 +1463,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
@Override
public boolean visit(MySqlCaseStatement x) {
// TODO Auto-generated method stub
accept(x.getWhenList());
return false;
}
@@ -1492,13 +1498,62 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
}
@Override
public boolean visit(MySqlWhenfStatement x) {
public boolean visit(MySqlWhenStatement x) {
accept(x.getStatements());
return false;
}
@Override
public void endVisit(MySqlWhenStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlLoopStatement x) {
accept(x.getStatements());
return false;
}
@Override
public void endVisit(MySqlLoopStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlLeaveStatement x) {
// TODO Auto-generated method stub
return false;
}
@Override
public void endVisit(MySqlWhenfStatement x) {
public void endVisit(MySqlLeaveStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlIterateStatement x) {
// TODO Auto-generated method stub
return false;
}
@Override
public void endVisit(MySqlIterateStatement x) {
// TODO Auto-generated method stub
}
@Override
public boolean visit(MySqlRepeatStatement x) {
// TODO Auto-generated method stub
accept(x.getStatements());
return false;
}
@Override
public void endVisit(MySqlRepeatStatement x) {
// TODO Auto-generated method stub
}
@@ -139,7 +139,12 @@ public class Keywords {
map.put("WHILE", Token.WHILE);
map.put("DO", Token.DO);
map.put("DECLARE", Token.DECLARE);
map.put("LOOP", Token.LOOP);
map.put("LEAVE", Token.LEAVE);
map.put("ITERATE", Token.ITERATE);
map.put("REPEAT", Token.REPEAT);
map.put("UNTIL", Token.UNTIL);
DEFAULT_KEYWORDS = new Keywords(map);
}
@@ -131,6 +131,10 @@ public enum Token {
// MySql procedure by:zz
WHILE("WHILE"),
DO("DO"),
LEAVE("LEAVE"),
ITERATE("ITERATE"),
REPEAT("REPEAT"),
UNTIL("UNTIL"),
//postgresql
WINDOW("WINDOW"),