mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser.
This commit is contained in:
@@ -30,6 +30,7 @@ public class SQLUpdateStatement extends SQLStatementImpl {
|
||||
protected SQLTableSource from;
|
||||
|
||||
protected SQLTableSource tableSource;
|
||||
protected List<SQLExpr> returning;
|
||||
|
||||
public SQLUpdateStatement(){
|
||||
|
||||
@@ -82,6 +83,14 @@ public class SQLUpdateStatement extends SQLStatementImpl {
|
||||
item.setParent(this);
|
||||
}
|
||||
|
||||
public List<SQLExpr> getReturning() {
|
||||
if (returning == null) {
|
||||
returning = new ArrayList<SQLExpr>(2);
|
||||
}
|
||||
|
||||
return returning;
|
||||
}
|
||||
|
||||
public SQLTableSource getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
+5
-6
@@ -39,8 +39,6 @@ public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlSta
|
||||
private boolean queryOnPk = false;
|
||||
private SQLExpr targetAffectRow;
|
||||
|
||||
private List<SQLSelectItem> returning = new ArrayList<SQLSelectItem>();
|
||||
|
||||
public MySqlUpdateStatement(){
|
||||
super(JdbcConstants.MYSQL);
|
||||
}
|
||||
@@ -56,14 +54,15 @@ public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlSta
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public List<SQLSelectItem> getReturning() {
|
||||
return returning;
|
||||
}
|
||||
// public List<SQLSelectItem> getReturning() {
|
||||
// return returning;
|
||||
// }
|
||||
|
||||
public void addReturning(List<SQLSelectItem> returning) {
|
||||
List<SQLExpr> thisReturning = this.getReturning();
|
||||
for (SQLSelectItem item : returning) {
|
||||
item.setParent(this);
|
||||
this.returning.add(item);
|
||||
thisReturning.add(item.getExpr());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
if (lexer.token() == Token.UPDATE) { // taobao returning to urgly syntax
|
||||
updateStmt = this.parseUpdateStatment();
|
||||
updateStmt.addReturning(queryBlock.getSelectList());
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.dialect.mysql.visitor;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
@@ -564,7 +565,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
public boolean visit(MySqlUpdateStatement x) {
|
||||
|
||||
visit((SQLUpdateStatement) x);
|
||||
for (SQLSelectItem item : x.getReturning()) {
|
||||
for (SQLExpr item : x.getReturning()) {
|
||||
item.accept(this);
|
||||
}
|
||||
|
||||
|
||||
-18
@@ -30,23 +30,13 @@ public class OracleUpdateStatement extends SQLUpdateStatement implements OracleS
|
||||
private final List<SQLHint> hints = new ArrayList<SQLHint>(1);
|
||||
private boolean only = false;
|
||||
private String alias;
|
||||
private SQLExpr where;
|
||||
|
||||
private List<SQLExpr> returning = new ArrayList<SQLExpr>();
|
||||
private List<SQLExpr> returningInto = new ArrayList<SQLExpr>();
|
||||
|
||||
public OracleUpdateStatement(){
|
||||
super (JdbcConstants.ORACLE);
|
||||
}
|
||||
|
||||
public List<SQLExpr> getReturning() {
|
||||
return returning;
|
||||
}
|
||||
|
||||
public void setReturning(List<SQLExpr> returning) {
|
||||
this.returning = returning;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getReturningInto() {
|
||||
return returningInto;
|
||||
}
|
||||
@@ -86,14 +76,6 @@ public class OracleUpdateStatement extends SQLUpdateStatement implements OracleS
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public SQLExpr getWhere() {
|
||||
return this.where;
|
||||
}
|
||||
|
||||
public void setWhere(SQLExpr where) {
|
||||
this.where = where;
|
||||
}
|
||||
|
||||
public boolean isOnly() {
|
||||
return this.only;
|
||||
}
|
||||
|
||||
-12
@@ -32,10 +32,6 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
|
||||
|
||||
private PGWithClause with;
|
||||
|
||||
private List<SQLExpr> returning = new ArrayList<SQLExpr>(2);
|
||||
|
||||
|
||||
|
||||
public PGUpdateStatement(){
|
||||
super (JdbcConstants.POSTGRESQL);
|
||||
}
|
||||
@@ -48,14 +44,6 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
|
||||
this.only = only;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getReturning() {
|
||||
return returning;
|
||||
}
|
||||
|
||||
public void setReturning(List<SQLExpr> returning) {
|
||||
this.returning = returning;
|
||||
}
|
||||
|
||||
public PGWithClause getWith() {
|
||||
return with;
|
||||
}
|
||||
|
||||
@@ -1147,6 +1147,8 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
x.getTableSource().accept(this);
|
||||
}
|
||||
|
||||
accept(x.getFrom());
|
||||
|
||||
accept(x.getItems());
|
||||
accept(x.getWhere());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user