use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class MySqlSchemaStatVisitor method visit.
@Override
public boolean visit(MySqlReplaceStatement x) {
setMode(x, Mode.Replace);
setAliasMap();
SQLName tableName = x.getTableName();
String ident = null;
if (tableName instanceof SQLIdentifierExpr) {
ident = ((SQLIdentifierExpr) tableName).getName();
} else if (tableName instanceof SQLPropertyExpr) {
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) tableName;
if (propertyExpr.getOwner() instanceof SQLIdentifierExpr) {
ident = propertyExpr.toString();
}
}
if (ident != null) {
setCurrentTable(x, ident);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
Map<String, String> aliasMap = getAliasMap();
putAliasMap(aliasMap, ident, ident);
}
accept(x.getColumns());
accept(x.getValuesList());
accept(x.getQuery());
return false;
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class SchemaStatVisitor method visit.
@Override
public boolean visit(SQLArrayExpr x) {
accept(x.getValues());
SQLExpr exp = x.getExpr();
if (exp instanceof SQLIdentifierExpr) {
if (((SQLIdentifierExpr) exp).getName().equals("ARRAY")) {
return false;
}
}
exp.accept(this);
return false;
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class WallVisitorUtils method queryBlockFromIsNull.
public static boolean queryBlockFromIsNull(WallVisitor visitor, SQLSelectQuery query, boolean checkSelectConst) {
if (query instanceof SQLSelectQueryBlock) {
SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
SQLTableSource from = queryBlock.getFrom();
if (queryBlock.getSelectList().size() < 1) {
return false;
}
if (from == null) {
boolean itemIsConst = true;
boolean itemHasAlias = false;
for (SQLSelectItem item : queryBlock.getSelectList()) {
if (item.getExpr() instanceof SQLIdentifierExpr || item.getExpr() instanceof SQLPropertyExpr) {
itemIsConst = false;
break;
}
if (item.getAlias() != null) {
itemHasAlias = true;
break;
}
}
if (itemIsConst && !itemHasAlias) {
return true;
} else {
return false;
}
}
if (from instanceof SQLExprTableSource) {
SQLExpr fromExpr = ((SQLExprTableSource) from).getExpr();
if (fromExpr instanceof SQLName) {
String name = fromExpr.toString();
name = form(name);
if (name.equalsIgnoreCase("DUAL")) {
return true;
}
}
}
if (queryBlock.getSelectList().size() == 1 && queryBlock.getSelectList().get(0).getExpr() instanceof SQLAllColumnExpr) {
if (from instanceof SQLSubqueryTableSource) {
SQLSelectQuery subQuery = ((SQLSubqueryTableSource) from).getSelect().getQuery();
if (queryBlockFromIsNull(visitor, subQuery)) {
return true;
}
}
}
if (checkSelectConst) {
SQLExpr where = queryBlock.getWhere();
if (where != null) {
Object whereValue = getValue(visitor, where);
if (Boolean.TRUE == whereValue) {
boolean allIsConst = true;
for (SQLSelectItem item : queryBlock.getSelectList()) {
if (getValue(visitor, item.getExpr()) == null) {
allIsConst = false;
break;
}
}
if (allIsConst) {
return true;
}
}
}
}
}
return false;
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.
the class WallVisitorUtils method createTenantCondition.
@Deprecated
private static SQLBinaryOpExpr createTenantCondition(WallVisitor visitor, String alias, StatementType statementType, String tableName) {
SQLExpr left, right;
if (alias != null) {
left = new SQLPropertyExpr(new SQLIdentifierExpr(alias), visitor.getConfig().getTenantColumn());
} else {
left = new SQLIdentifierExpr(visitor.getConfig().getTenantColumn());
}
right = generateTenantValue(visitor, alias, statementType, tableName);
SQLBinaryOpExpr tenantCondition = new SQLBinaryOpExpr(left, SQLBinaryOperator.Equality, right);
return tenantCondition;
}
use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project Mycat_plus by coderczp.
the class ParseUtil method changeInsertAddSlot.
public static String changeInsertAddSlot(String sql, int slotValue) {
SQLStatementParser parser = new MycatStatementParser(sql);
MySqlInsertStatement insert = (MySqlInsertStatement) parser.parseStatement();
insert.getColumns().add(new SQLIdentifierExpr("_slot"));
insert.getValues().getValues().add(new SQLIntegerExpr(slotValue));
return insert.toString();
}
Aggregations