mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser add refactor api.
This commit is contained in:
@@ -292,4 +292,13 @@ public class SQLDeleteStatement extends SQLStatementImpl implements SQLReplaceab
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addWhere(SQLExpr where) {
|
||||
if (where == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.addCondition(where);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -321,4 +322,26 @@ public class SQLSelect extends SQLObjectImpl {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean addWhere(SQLExpr where) {
|
||||
if (where == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (query instanceof SQLSelectQueryBlock) {
|
||||
((SQLSelectQueryBlock) query).addWhere(where);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (query instanceof SQLUnionQuery) {
|
||||
SQLSelectQueryBlock queryBlock = new SQLSelectQueryBlock();
|
||||
queryBlock.setFrom(new SQLSelect(query), "u");
|
||||
queryBlock.addSelectItem(new SQLAllColumnExpr());
|
||||
queryBlock.setParent(queryBlock);
|
||||
query = queryBlock;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -85,4 +86,8 @@ public class SQLSelectStatement extends SQLStatementImpl {
|
||||
public List<SQLObject> getChildren() {
|
||||
return Collections.<SQLObject>singletonList(select);
|
||||
}
|
||||
|
||||
public boolean addWhere(SQLExpr where) {
|
||||
return select.addWhere(where);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,4 +312,13 @@ public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceab
|
||||
result = 31 * result + (hints != null ? hints.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean addWhere(SQLExpr where) {
|
||||
if (where == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.addCondition(where);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user