use of com.alibaba.druid.sql.visitor.SQLEvalVisitor in project sharding-jdbc by dangdangdotcom.
the class ParseContext method evalExpression.
private ValuePair evalExpression(final DatabaseType databaseType, final SQLObject sqlObject, final List<Object> parameters) {
if (sqlObject instanceof SQLMethodInvokeExpr) {
// TODO 解析函数中的sharingValue不支持
return null;
}
SQLEvalVisitor visitor;
switch(databaseType.name().toLowerCase()) {
case JdbcUtils.MYSQL:
case JdbcUtils.H2:
visitor = new MySQLEvalVisitor();
break;
default:
visitor = SQLEvalVisitorUtils.createEvalVisitor(databaseType.name());
}
visitor.setParameters(parameters);
sqlObject.accept(visitor);
Object value = SQLEvalVisitorUtils.getValue(sqlObject);
if (null == value) {
// TODO 对于NULL目前解析为空字符串,此处待考虑解决方法
return null;
}
Comparable<?> finalValue;
if (value instanceof Comparable<?>) {
finalValue = (Comparable<?>) value;
} else {
finalValue = "";
}
Integer index = (Integer) sqlObject.getAttribute(MySQLEvalVisitor.EVAL_VAR_INDEX);
if (null == index) {
index = -1;
}
return new ValuePair(finalValue, index);
}
use of com.alibaba.druid.sql.visitor.SQLEvalVisitor in project druid by alibaba.
the class WallVisitorUtils method eval.
public static Object eval(WallVisitor wallVisitor, String dbType, SQLObject sqlObject, List<Object> parameters) {
SQLEvalVisitor visitor = SQLEvalVisitorUtils.createEvalVisitor(dbType);
visitor.setParameters(parameters);
visitor.registerFunction("rand", Nil.instance);
visitor.registerFunction("sin", Nil.instance);
visitor.registerFunction("cos", Nil.instance);
visitor.registerFunction("asin", Nil.instance);
visitor.registerFunction("acos", Nil.instance);
sqlObject.accept(visitor);
if (sqlObject instanceof SQLNumericLiteralExpr) {
return ((SQLNumericLiteralExpr) sqlObject).getNumber();
}
return getValueFromAttributes(wallVisitor, sqlObject);
}
Aggregations