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:
@@ -53,6 +53,19 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements SQLReplaceable, Seri
|
||||
setLeft(left);
|
||||
setRight(right);
|
||||
this.operator = operator;
|
||||
|
||||
if (dbType == null) {
|
||||
if (left instanceof SQLBinaryOpExpr) {
|
||||
dbType = ((SQLBinaryOpExpr) left).dbType;
|
||||
}
|
||||
}
|
||||
|
||||
if (dbType == null) {
|
||||
if (right instanceof SQLBinaryOpExpr) {
|
||||
dbType = ((SQLBinaryOpExpr) right).dbType;
|
||||
}
|
||||
}
|
||||
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
@@ -392,4 +405,16 @@ public class SQLBinaryOpExpr extends SQLExprImpl implements SQLReplaceable, Seri
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public SQLExpr other(SQLExpr x) {
|
||||
if (x == left) {
|
||||
return right;
|
||||
}
|
||||
|
||||
if (x == right) {
|
||||
return left;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.ast.SQLReplaceable;
|
||||
@@ -185,4 +186,28 @@ public class SQLMethodInvokeExpr extends SQLExprImpl implements SQLReplaceable,
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean match(String owner, String function) {
|
||||
if (function == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SQLUtils.nameEquals(function, methodName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (owner == null && this.owner == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (owner == null || this.owner == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.owner instanceof SQLIdentifierExpr) {
|
||||
return SQLUtils.nameEquals(((SQLIdentifierExpr) this.owner).name, owner);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user