mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.Utils;
|
||||
|
||||
public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
|
||||
|
||||
@@ -147,6 +148,25 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean equalsIgoreOrder(SQLBinaryOpExpr other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (operator != other.operator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (Utils.equals(this.left, other.left)
|
||||
&& Utils.equals(this.right, other.right))
|
||||
|| (Utils.equals(this.left, other.right)
|
||||
&& Utils.equals(this.right, other.left));
|
||||
}
|
||||
|
||||
public SQLBinaryOpExpr clone() {
|
||||
return new SQLBinaryOpExpr(left, operator, right, dbType);
|
||||
}
|
||||
@@ -155,7 +175,7 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements Serializable {
|
||||
return SQLUtils.toSQLString(this, getDbType());
|
||||
}
|
||||
|
||||
public static SQLExpr combine(List<SQLExpr> items, SQLBinaryOperator op) {
|
||||
public static SQLExpr combine(List<? extends SQLExpr> items, SQLBinaryOperator op) {
|
||||
if (items == null || op == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,6 @@ public class SQLSelect extends SQLObjectImpl {
|
||||
|
||||
public boolean isSimple() {
|
||||
return withSubQuery == null
|
||||
&& orderBy == null
|
||||
&& (hints == null || hints.size() == 0)
|
||||
&& restriction == null
|
||||
&& (!forBrowse)
|
||||
|
||||
@@ -272,6 +272,9 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
acceptChild(visitor, this.startWith);
|
||||
acceptChild(visitor, this.connectBy);
|
||||
acceptChild(visitor, this.groupBy);
|
||||
acceptChild(visitor, this.orderBy);
|
||||
acceptChild(visitor, this.waitTime);
|
||||
acceptChild(visitor, this.limit);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
@@ -386,4 +389,30 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
public void setBracket(boolean bracket) {
|
||||
this.bracket = bracket;
|
||||
}
|
||||
|
||||
public SQLTableSource findTableSource(String alias) {
|
||||
return findTableSource(from, alias);
|
||||
}
|
||||
|
||||
private static SQLTableSource findTableSource(SQLTableSource from, String alias) {
|
||||
if (from == null || alias == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (alias.equalsIgnoreCase(from.computeAlias())) {
|
||||
return from;
|
||||
}
|
||||
|
||||
if (from instanceof SQLJoinTableSource) {
|
||||
SQLJoinTableSource join = (SQLJoinTableSource) from;
|
||||
SQLTableSource result = findTableSource(join.getLeft(), alias);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return findTableSource(join.getRight(), alias);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user