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();
}
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;
}
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;
}
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;
}
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();
}
Aggregations