use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat_plus by coderczp.
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();
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat_plus by coderczp.
the class BinaryOpResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
SQLBinaryOpExpr pp = (SQLBinaryOpExpr) parent;
if (pp.getLeft() instanceof SQLQueryExpr) {
SQLQueryExpr left = (SQLQueryExpr) pp.getLeft();
if (left.getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
listExpr.setParent(left.getParent());
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setLeft(listExpr);
}
} else if (pp.getRight() instanceof SQLQueryExpr) {
SQLQueryExpr right = (SQLQueryExpr) pp.getRight();
if (right.getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
listExpr.setParent(right.getParent());
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setRight(listExpr);
}
} else if (pp.getLeft() instanceof SQLInSubQueryExpr) {
SQLInSubQueryExpr left = (SQLInSubQueryExpr) pp.getLeft();
if (left.getSubQuery().equals(sqlselect)) {
SQLExprImpl inlistExpr = null;
if (null == param || param.isEmpty()) {
inlistExpr = new SQLNullExpr();
} else {
inlistExpr = new SQLInListExpr();
((SQLInListExpr) inlistExpr).setTargetList(param);
((SQLInListExpr) inlistExpr).setExpr(pp.getRight());
((SQLInListExpr) inlistExpr).setNot(left.isNot());
((SQLInListExpr) inlistExpr).setParent(left.getParent());
}
pp.setLeft(inlistExpr);
}
} else if (pp.getRight() instanceof SQLInSubQueryExpr) {
SQLInSubQueryExpr right = (SQLInSubQueryExpr) pp.getRight();
if (right.getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setRight(listExpr);
}
}
return statement.toString();
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project dble by actiontech.
the class ItemFuncIn method toExpression.
@Override
public SQLExpr toExpression() {
SQLInListExpr in = new SQLInListExpr(args.get(0).toExpression(), this.negated);
List<SQLExpr> targetList = new ArrayList<>();
int index = 0;
for (Item item : args) {
if (index != 0) {
targetList.add(item.toExpression());
}
index++;
}
in.setTargetList(targetList);
return in;
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat-Server by MyCATApache.
the class JoinParser method parserWhere.
private void parserWhere(SQLExpr aexpr, String Operator) {
if (aexpr == null) {
return;
}
if (aexpr instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr expr = (SQLBinaryOpExpr) aexpr;
SQLExpr exprL = expr.getLeft();
if (!(exprL instanceof SQLBinaryOpExpr)) {
opSQLExpr((SQLBinaryOpExpr) aexpr, Operator);
} else {
// if (expr.getOperator().getName().equals("AND")) {
if (expr.getOperator() == SQLBinaryOperator.BooleanAnd) {
// parserWhere(exprL);
// parserWhere(expr.getRight());
andorWhere(exprL, expr.getOperator().getName(), expr.getRight());
} else if (expr.getOperator() == SQLBinaryOperator.BooleanOr) {
// .getName().equals("OR")) {
andorWhere(exprL, expr.getOperator().getName(), expr.getRight());
} else {
throw new RuntimeException("Can't identify the operation of of where");
}
}
} else if (aexpr instanceof SQLInListExpr) {
SQLInListExpr expr = (SQLInListExpr) aexpr;
SQLExpr exprL = expr.getExpr();
String field = exprL.toString();
tableFilter.addWhere(field, SQLUtils.toMySqlString(expr), Operator);
}
}
use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat-Server by MyCATApache.
the class BinaryOpResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
SQLBinaryOpExpr pp = (SQLBinaryOpExpr) parent;
if (pp.getLeft() instanceof SQLQueryExpr) {
SQLQueryExpr left = (SQLQueryExpr) pp.getLeft();
if (left.getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
listExpr.setParent(left.getParent());
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setLeft(listExpr);
}
} else if (pp.getRight() instanceof SQLQueryExpr) {
SQLQueryExpr right = (SQLQueryExpr) pp.getRight();
if (right.getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
listExpr.setParent(right.getParent());
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setRight(listExpr);
}
} else if (pp.getLeft() instanceof SQLInSubQueryExpr) {
SQLInSubQueryExpr left = (SQLInSubQueryExpr) pp.getLeft();
if (left.getSubQuery().equals(sqlselect)) {
SQLExprImpl inlistExpr = null;
if (null == param || param.isEmpty()) {
inlistExpr = new SQLNullExpr();
} else {
inlistExpr = new SQLInListExpr();
((SQLInListExpr) inlistExpr).setTargetList(param);
((SQLInListExpr) inlistExpr).setExpr(pp.getRight());
((SQLInListExpr) inlistExpr).setNot(left.isNot());
((SQLInListExpr) inlistExpr).setParent(left.getParent());
}
pp.setLeft(inlistExpr);
}
} else if (pp.getRight() instanceof SQLInSubQueryExpr) {
SQLInSubQueryExpr right = (SQLInSubQueryExpr) pp.getRight();
if (right.getSubQuery().equals(sqlselect)) {
SQLExprImpl listExpr = null;
if (null == param || param.isEmpty()) {
listExpr = new SQLNullExpr();
} else {
listExpr = new SQLListExpr();
((SQLListExpr) listExpr).getItems().addAll(param);
}
pp.setRight(listExpr);
}
}
return statement.toString();
}
Aggregations