mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support taobao urgly update returning sql. for issue 1196. https://github.com/alibaba/druid/issues/1196
This commit is contained in:
+43
-3
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
@@ -31,10 +32,14 @@ public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlSta
|
||||
private SQLOrderBy orderBy;
|
||||
private Limit limit;
|
||||
|
||||
private boolean lowPriority = false;
|
||||
private boolean ignore = false;
|
||||
private boolean lowPriority = false;
|
||||
private boolean ignore = false;
|
||||
private boolean commitOnSuccess = false;
|
||||
private boolean rollBackOnFail = false;
|
||||
private boolean queryOnPk = false;
|
||||
private SQLExpr targetAffectRow;
|
||||
|
||||
private List<SQLSelectItem> returning = new ArrayList<SQLSelectItem>();
|
||||
private List<SQLSelectItem> returning = new ArrayList<SQLSelectItem>();
|
||||
|
||||
public MySqlUpdateStatement(){
|
||||
super(JdbcConstants.MYSQL);
|
||||
@@ -98,6 +103,41 @@ public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlSta
|
||||
this.ignore = ignore;
|
||||
}
|
||||
|
||||
public boolean isCommitOnSuccess() {
|
||||
return commitOnSuccess;
|
||||
}
|
||||
|
||||
public void setCommitOnSuccess(boolean commitOnSuccess) {
|
||||
this.commitOnSuccess = commitOnSuccess;
|
||||
}
|
||||
|
||||
public boolean isRollBackOnFail() {
|
||||
return rollBackOnFail;
|
||||
}
|
||||
|
||||
public void setRollBackOnFail(boolean rollBackOnFail) {
|
||||
this.rollBackOnFail = rollBackOnFail;
|
||||
}
|
||||
|
||||
public boolean isQueryOnPk() {
|
||||
return queryOnPk;
|
||||
}
|
||||
|
||||
public void setQueryOnPk(boolean queryOnPk) {
|
||||
this.queryOnPk = queryOnPk;
|
||||
}
|
||||
|
||||
public SQLExpr getTargetAffectRow() {
|
||||
return targetAffectRow;
|
||||
}
|
||||
|
||||
public void setTargetAffectRow(SQLExpr targetAffectRow) {
|
||||
if (targetAffectRow != null) {
|
||||
targetAffectRow.setParent(this);
|
||||
}
|
||||
this.targetAffectRow = targetAffectRow;
|
||||
}
|
||||
|
||||
public SQLOrderBy getOrderBy() {
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
@@ -251,6 +252,27 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
lexer.nextToken();
|
||||
update.setIgnore(true);
|
||||
}
|
||||
|
||||
if (identifierEquals("COMMIT_ON_SUCCESS")) {
|
||||
lexer.nextToken();
|
||||
update.setCommitOnSuccess(true);
|
||||
}
|
||||
|
||||
if (identifierEquals("ROLLBACK_ON_FAIL")) {
|
||||
lexer.nextToken();
|
||||
update.setRollBackOnFail(true);
|
||||
}
|
||||
|
||||
if (identifierEquals("QUEUE_ON_PK")) {
|
||||
lexer.nextToken();
|
||||
update.setQueryOnPk(true);
|
||||
}
|
||||
|
||||
if (identifierEquals("TARGET_AFFECT_ROW")) {
|
||||
lexer.nextToken();
|
||||
SQLExpr targetAffectRow = this.exprParser.expr();
|
||||
update.setTargetAffectRow(targetAffectRow);
|
||||
}
|
||||
|
||||
SQLTableSource updateTableSource = this.exprParser.createSelectParser().parseTableSource();
|
||||
update.setTableSource(updateTableSource);
|
||||
|
||||
@@ -1645,6 +1645,24 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (x.isIgnore()) {
|
||||
print0(ucase ? "IGNORE " : "ignore ");
|
||||
}
|
||||
|
||||
if (x.isCommitOnSuccess()) {
|
||||
print0(ucase ? "COMMIT_ON_SUCCESS " : "commit_on_success ");
|
||||
}
|
||||
|
||||
if (x.isRollBackOnFail()) {
|
||||
print0(ucase ? "ROLLBACK_ON_FAIL " : "rollback_on_fail ");
|
||||
}
|
||||
|
||||
if (x.isQueryOnPk()) {
|
||||
print0(ucase ? "QUEUE_ON_PK " : "queue_on_pk ");
|
||||
}
|
||||
|
||||
if (x.getTargetAffectRow() != null) {
|
||||
print0(ucase ? "TARGET_AFFECT_ROW " : "target_affect_row ");
|
||||
x.getTargetAffectRow().accept(this);
|
||||
print(' ');
|
||||
}
|
||||
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
|
||||
+8
-1
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
@@ -538,7 +539,13 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlUpdateStatement x) {
|
||||
return visit((SQLUpdateStatement) x);
|
||||
|
||||
visit((SQLUpdateStatement) x);
|
||||
for (SQLSelectItem item : x.getReturning()) {
|
||||
item.accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user