use of com.alibaba.druid.sql.ast.SQLExprImpl in project Mycat-Server by MyCATApache.
the class SQLQueryResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
if (parent.getParent() instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr pp = (SQLBinaryOpExpr) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
if (pp.getLeft().equals(parent)) {
pp.setLeft(listExpr);
} else if (pp.getRight().equals(parent)) {
pp.setRight(listExpr);
}
} else if (parent.getParent() instanceof SQLSelectItem) {
SQLSelectItem pp = (SQLSelectItem) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setExpr(listExpr);
} else if (parent.getParent() instanceof SQLSelectGroupByClause) {
SQLSelectGroupByClause pp = (SQLSelectGroupByClause) parent.getParent();
List<SQLExpr> items = pp.getItems();
for (int i = 0; i < items.size(); i++) {
SQLExpr expr = items.get(i);
if (expr instanceof SQLQueryExpr && ((SQLQueryExpr) expr).getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
items.set(i, listExpr);
}
}
} else if (parent.getParent() instanceof SQLSelectOrderByItem) {
SQLSelectOrderByItem orderItem = (SQLSelectOrderByItem) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
listExpr.setParent(orderItem);
orderItem.setExpr(listExpr);
} else if (parent.getParent() instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) parent.getParent();
// select * from subtest1 a where (select 1 from subtest3); 这种情况会进入到当前分支.
// 改写为 select * from subtest1 a where (1); 或 select * from subtest1 a where (null);
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
listExpr.setParent(query);
query.setWhere(listExpr);
}
return statement.toString();
}
use of com.alibaba.druid.sql.ast.SQLExprImpl in project Mycat_plus by coderczp.
the class SQLQueryResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
if (parent.getParent() instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr pp = (SQLBinaryOpExpr) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
if (pp.getLeft().equals(parent)) {
pp.setLeft(listExpr);
} else if (pp.getRight().equals(parent)) {
pp.setRight(listExpr);
}
} else if (parent.getParent() instanceof SQLSelectItem) {
SQLSelectItem pp = (SQLSelectItem) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setExpr(listExpr);
} else if (parent.getParent() instanceof SQLSelectGroupByClause) {
SQLSelectGroupByClause pp = (SQLSelectGroupByClause) parent.getParent();
List<SQLExpr> items = pp.getItems();
for (int i = 0; i < items.size(); i++) {
SQLExpr expr = items.get(i);
if (expr instanceof SQLQueryExpr && ((SQLQueryExpr) expr).getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
items.set(i, listExpr);
}
}
} else if (parent.getParent() instanceof SQLSelectOrderByItem) {
SQLSelectOrderByItem orderItem = (SQLSelectOrderByItem) parent.getParent();
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
listExpr.setParent(orderItem);
orderItem.setExpr(listExpr);
} else if (parent.getParent() instanceof MySqlSelectQueryBlock) {
MySqlSelectQueryBlock query = (MySqlSelectQueryBlock) parent.getParent();
// select * from subtest1 a where (select 1 from subtest3); 这种情况会进入到当前分支.
// 改写为 select * from subtest1 a where (1); 或 select * from subtest1 a where (null);
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
listExpr.setParent(query);
query.setWhere(listExpr);
}
return statement.toString();
}
use of com.alibaba.druid.sql.ast.SQLExprImpl in project Mycat-Server by MyCATApache.
the class InSubQueryResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
SQLExprImpl inlistExpr = null;
if (null == param || param.isEmpty()) {
inlistExpr = new SQLNullExpr();
} else {
inlistExpr = new SQLInListExpr();
((SQLInListExpr) inlistExpr).setTargetList(param);
((SQLInListExpr) inlistExpr).setExpr(((SQLInSubQueryExpr) parent).getExpr());
((SQLInListExpr) inlistExpr).setNot(((SQLInSubQueryExpr) parent).isNot());
((SQLInListExpr) inlistExpr).setParent(sqlselect.getParent());
}
if (parent.getParent() instanceof MySqlSelectQueryBlock) {
((MySqlSelectQueryBlock) parent.getParent()).setWhere(inlistExpr);
} else if (parent.getParent() instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr pp = ((SQLBinaryOpExpr) parent.getParent());
if (pp.getLeft().equals(parent)) {
pp.setLeft(inlistExpr);
} else if (pp.getRight().equals(parent)) {
pp.setRight(inlistExpr);
}
}
return statement.toString();
}
Aggregations