use of com.alibaba.druid.sql.ast.SQLReplaceable in project dble by actiontech.
the class PrepareChangeVisitor method visit.
@Override
public boolean visit(SQLVariantRefExpr x) {
if (x.getParent() != null && x.getParent() instanceof SQLSelectItem) {
((SQLSelectItem) x.getParent()).replace(x, SQLUtils.toSQLExpr("true"));
return false;
}
SQLObject parent;
SQLObject current = x.getParent();
// nest lookup. find closest SQLReplaceable and replace if possible.
while (current != null && (parent = current.getParent()) != null) {
if (parent instanceof SQLReplaceable) {
if (current instanceof SQLExpr) {
((SQLReplaceable) parent).replace((SQLExpr) current, SQLUtils.toSQLExpr("true"));
break;
} else {
current = parent;
}
} else {
current = parent;
}
}
return false;
}
use of com.alibaba.druid.sql.ast.SQLReplaceable in project Mycat2 by MyCATApache.
the class VertxMycatConnectionPool method deparameterize.
public static String deparameterize(String sql, List<Object> params) {
if (sql.startsWith("be")) {
return sql;
}
SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql);
sqlStatement.accept(new MySqlASTVisitorAdapter() {
int index;
@Override
public void endVisit(SQLVariantRefExpr x) {
if ("?".equalsIgnoreCase(x.getName())) {
if (index < params.size()) {
Object value = params.get(index++);
SQLReplaceable parent = (SQLReplaceable) x.getParent();
parent.replace(x, PreparedStatement.fromJavaObject(value));
}
}
super.endVisit(x);
}
});
sql = sqlStatement.toString();
return sql;
}
Aggregations