Search in sources :

Example 81 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class SQLServerExprParser method primary.

public SQLExpr primary() {
    if (lexer.token() == Token.LBRACKET) {
        lexer.nextToken();
        SQLExpr name = this.name();
        accept(Token.RBRACKET);
        return primaryRest(name);
    }
    return super.primary();
}
Also used : SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 82 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class SchemaStatVisitor method visit.

@Override
public boolean visit(SQLCreateIndexStatement x) {
    setMode(x, Mode.CreateIndex);
    SQLName name = (SQLName) ((SQLExprTableSource) x.getTable()).getExpr();
    String table = name.toString();
    setCurrentTable(table);
    TableStat stat = getTableStat(table);
    stat.incrementDropIndexCount();
    Map<String, String> aliasMap = getAliasMap();
    putAliasMap(aliasMap, table, table);
    for (SQLSelectOrderByItem item : x.getItems()) {
        SQLExpr expr = item.getExpr();
        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            String columnName = identExpr.getName();
            addColumn(table, columnName);
        }
    }
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 83 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class Bin method eval.

public Object eval(SQLEvalVisitor visitor, SQLMethodInvokeExpr x) {
    if (x.getParameters().size() != 1) {
        return SQLEvalVisitor.EVAL_ERROR;
    }
    SQLExpr param0 = x.getParameters().get(0);
    param0.accept(visitor);
    Object param0Value = param0.getAttributes().get(EVAL_VALUE);
    if (param0Value == null) {
        return SQLEvalVisitor.EVAL_ERROR;
    }
    if (param0Value instanceof Number) {
        long longValue = ((Number) param0Value).longValue();
        String result = Long.toString(longValue, 2);
        return result;
    }
    return SQLEvalVisitor.EVAL_ERROR;
}
Also used : SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 84 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class BitLength method eval.

public Object eval(SQLEvalVisitor visitor, SQLMethodInvokeExpr x) {
    if (x.getParameters().size() != 1) {
        return SQLEvalVisitor.EVAL_ERROR;
    }
    SQLExpr param0 = x.getParameters().get(0);
    param0.accept(visitor);
    Object param0Value = param0.getAttributes().get(EVAL_VALUE);
    if (param0Value == null) {
        return SQLEvalVisitor.EVAL_ERROR;
    }
    if (param0Value instanceof String) {
        return ((String) param0Value).getBytes().length * 8;
    }
    return SQLEvalVisitor.EVAL_ERROR;
}
Also used : SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 85 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class Char method eval.

public Object eval(SQLEvalVisitor visitor, SQLMethodInvokeExpr x) {
    if (x.getParameters().size() == 0) {
        return SQLEvalVisitor.EVAL_ERROR;
    }
    StringBuffer buf = new StringBuffer(x.getParameters().size());
    for (SQLExpr param : x.getParameters()) {
        param.accept(visitor);
        Object paramValue = param.getAttributes().get(EVAL_VALUE);
        if (paramValue instanceof Number) {
            int charCode = ((Number) paramValue).intValue();
            buf.append((char) charCode);
        } else if (paramValue instanceof String) {
            try {
                int charCode = new BigDecimal((String) paramValue).intValue();
                buf.append((char) charCode);
            } catch (NumberFormatException e) {
            }
        } else {
            return SQLEvalVisitor.EVAL_ERROR;
        }
    }
    return buf.toString();
}
Also used : SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) BigDecimal(java.math.BigDecimal)

Aggregations

SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)225 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)42 SQLName (com.alibaba.druid.sql.ast.SQLName)33 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)30 ParserException (com.alibaba.druid.sql.parser.ParserException)23 SQLObject (com.alibaba.druid.sql.ast.SQLObject)22 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)17 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)16 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)13 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)13 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)12 ArrayList (java.util.ArrayList)12 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)11 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)10 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)10 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)10 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)8 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)8 SQLNumberExpr (com.alibaba.druid.sql.ast.expr.SQLNumberExpr)7 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)7