Search in sources :

Example 11 with SQLNumericLiteralExpr

use of com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr 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);
}
Also used : SQLNumericLiteralExpr(com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr) SQLEvalVisitor(com.alibaba.druid.sql.visitor.SQLEvalVisitor)

Aggregations

SQLNumericLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr)11 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)7 SQLBooleanExpr (com.alibaba.druid.sql.ast.expr.SQLBooleanExpr)4 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)4 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)4 SQLObject (com.alibaba.druid.sql.ast.SQLObject)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)3 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)3 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)3 SQLNCharExpr (com.alibaba.druid.sql.ast.expr.SQLNCharExpr)3 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)3 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)2 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)2 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)2 ArrayList (java.util.ArrayList)2 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)1 MockResultSet (com.alibaba.druid.mock.MockResultSet)1 MockResultSetMetaData (com.alibaba.druid.mock.MockResultSetMetaData)1 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)1