mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser.
This commit is contained in:
@@ -25,14 +25,11 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLBlockStatement extends SQLStatementImpl {
|
||||
private String labelName;
|
||||
|
||||
private String endLabel;
|
||||
|
||||
private String endLabel;
|
||||
private List<SQLParameter> parameters = new ArrayList<SQLParameter>();
|
||||
|
||||
private List<SQLStatement> statementList = new ArrayList<SQLStatement>();
|
||||
|
||||
public SQLStatement exception;
|
||||
public SQLStatement exception;
|
||||
private boolean endOfCommit;
|
||||
|
||||
public SQLBlockStatement() {
|
||||
|
||||
@@ -124,4 +121,12 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isEndOfCommit() {
|
||||
return endOfCommit;
|
||||
}
|
||||
|
||||
public void setEndOfCommit(boolean value) {
|
||||
this.endOfCommit = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ public class SQLCommitStatement extends SQLStatementImpl {
|
||||
private SQLExpr transactionName;
|
||||
private SQLExpr delayedDurability;
|
||||
|
||||
public SQLCommitStatement() {
|
||||
|
||||
}
|
||||
|
||||
public SQLCommitStatement clone() {
|
||||
SQLCommitStatement x = new SQLCommitStatement();
|
||||
x.write = write;
|
||||
|
||||
@@ -1004,7 +1004,16 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
block.setDbType(dbType);
|
||||
|
||||
accept(Token.BEGIN);
|
||||
this.parseStatementList(block.getStatementList(), -1, block);
|
||||
List<SQLStatement> statementList = block.getStatementList();
|
||||
this.parseStatementList(statementList, -1, block);
|
||||
|
||||
if (lexer.token() != Token.END
|
||||
&& statementList.size() > 0
|
||||
&& (statementList.get(statementList.size() - 1) instanceof SQLCommitStatement
|
||||
|| statementList.get(statementList.size() - 1) instanceof SQLRollbackStatement)) {
|
||||
block.setEndOfCommit(true);
|
||||
return block;
|
||||
}
|
||||
accept(Token.END);
|
||||
|
||||
return block;
|
||||
|
||||
@@ -2977,8 +2977,13 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
this.indentCount--;
|
||||
println();
|
||||
}
|
||||
|
||||
print0(ucase ? "BEGIN" : "begin");
|
||||
this.indentCount++;
|
||||
if (!x.isEndOfCommit()) {
|
||||
this.indentCount++;
|
||||
} else {
|
||||
print(';');
|
||||
}
|
||||
println();
|
||||
List<SQLStatement> statementList = x.getStatementList();
|
||||
for (int i = 0, size = statementList.size(); i < size; ++i) {
|
||||
@@ -2988,13 +2993,17 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
stmt.accept(this);
|
||||
}
|
||||
this.indentCount--;
|
||||
println();
|
||||
print0(ucase ? "END" : "end");
|
||||
if (labelName != null && !labelName.equals("")) {
|
||||
print(' ');
|
||||
print0(labelName);
|
||||
|
||||
if (!x.isEndOfCommit()) {
|
||||
this.indentCount--;
|
||||
println();
|
||||
print0(ucase ? "END" : "end");
|
||||
if (labelName != null && !labelName.equals("")) {
|
||||
print(' ');
|
||||
print0(labelName);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -348,8 +348,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
|
||||
if (lexer.identifierEquals("ROLLBACK")) {
|
||||
SQLRollbackStatement stmt = parseRollback();
|
||||
|
||||
statementList.add(stmt);
|
||||
|
||||
if (parent instanceof SQLBlockStatement
|
||||
&& JdbcConstants.MYSQL.equals(dbType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -357,6 +362,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
SQLStatement stmt = parseCommit();
|
||||
|
||||
statementList.add(stmt);
|
||||
|
||||
if (parent instanceof SQLBlockStatement
|
||||
&& JdbcConstants.MYSQL.equals(dbType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user