improved sql parser.

This commit is contained in:
wenshao
2017-06-27 11:28:15 +08:00
parent 8339beee7a
commit c64c40e81d
11 changed files with 118 additions and 7 deletions
@@ -71,7 +71,14 @@ public abstract class SQLInsertInto extends SQLObjectImpl {
return query;
}
public void setQuery(SQLSelectQuery query) {
this.setQuery(new SQLSelect(query));
}
public void setQuery(SQLSelect query) {
if (query != null) {
query.setParent(this);
}
this.query = query;
}
@@ -154,7 +154,10 @@ public class SQLSelect extends SQLObjectImpl {
SQLSelect x = new SQLSelect();
x.withSubQuery = this.withSubQuery;
x.query = this.query;
if (query != null) {
x.setQuery(query.clone());
}
if (orderBy != null) {
x.setOrderBy(this.orderBy.clone());
}
@@ -21,4 +21,5 @@ public interface SQLSelectQuery extends SQLObject {
boolean isBracket();
void setBracket(boolean bracket);
SQLSelectQuery clone();
}
@@ -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.SQLBinaryOpExpr;
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@@ -439,4 +440,12 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
return null;
}
public void addCondition(SQLExpr expr) {
if (expr == null) {
return;
}
this.setWhere(SQLBinaryOpExpr.and(where, expr));
}
}
@@ -43,6 +43,12 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery {
}
public SQLUnionQuery(SQLSelectQuery left, SQLUnionOperator operator, SQLSelectQuery right){
this.setLeft(left);
this.operator = operator;
this.setRight(right);
}
public SQLSelectQuery getLeft() {
return left;
}
@@ -106,4 +112,27 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery {
public void setBracket(boolean bracket) {
this.bracket = bracket;
}
public SQLUnionQuery clone() {
SQLUnionQuery x = new SQLUnionQuery();
x.bracket = bracket;
if (left != null) {
x.setLeft(left.clone());
}
if (right != null) {
x.setRight(right.clone());
}
x.operator = operator;
if (orderBy != null) {
x.setOrderBy(orderBy.clone());
}
if (limit != null) {
x.setLimit(limit.clone());
}
return x;
}
}