improved sql parser.

This commit is contained in:
wenshao
2017-07-23 16:44:43 +08:00
parent 82fe08109f
commit 6829a23bce
41 changed files with 1183 additions and 514 deletions
@@ -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;
}
}