use of com.alibaba.druid.sql.ast.SQLExprImpl 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.SQLExprImpl in project Mycat_plus by coderczp.
the class SQLAllResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
if (parent.getParent() instanceof SQLBinaryOpExpr) {
SQLExprImpl inlistExpr = null;
if (null == param || param.isEmpty()) {
inlistExpr = new SQLNullExpr();
SQLBinaryOpExpr xp = (SQLBinaryOpExpr) parent.getParent();
xp.setOperator(SQLBinaryOperator.Is);
if (xp.getRight().equals(parent)) {
xp.setRight(inlistExpr);
} else if (xp.getLeft().equals(parent)) {
xp.setLeft(inlistExpr);
}
} else {
int len = param.size();
SQLBinaryOpExpr xp = (SQLBinaryOpExpr) parent.getParent();
SQLExpr left = null;
if (xp.getRight().equals(parent)) {
left = xp.getLeft();
} else if (xp.getLeft().equals(parent)) {
left = xp.getRight();
}
SQLBinaryOpExpr p = xp;
for (int i = 0; i < len; i++) {
if (i < (len - 1)) {
SQLBinaryOpExpr rightop = new SQLBinaryOpExpr();
rightop.setOperator(SQLBinaryOperator.Equality);
SQLValuableExpr expr = (SQLValuableExpr) param.get(i);
rightop.setRight(expr);
rightop.setParent(p);
rightop.setLeft(left);
p.setRight(rightop);
p.setOperator(SQLBinaryOperator.BooleanAnd);
SQLBinaryOpExpr lefeop = new SQLBinaryOpExpr();
lefeop.setParent(p);
lefeop.setOperator(SQLBinaryOperator.Equality);
p.setLeft(lefeop);
p = (SQLBinaryOpExpr) p.getLeft();
} else {
p.setLeft(left);
p.setOperator(SQLBinaryOperator.Equality);
SQLValuableExpr expr = (SQLValuableExpr) param.get(i);
p.setRight(expr);
}
}
}
}
return statement.toString();
}
use of com.alibaba.druid.sql.ast.SQLExprImpl 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.SQLExprImpl 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();
}
use of com.alibaba.druid.sql.ast.SQLExprImpl in project Mycat-Server by MyCATApache.
the class SQLAllResultHandler method dohandler.
@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
if (parent.getParent() instanceof SQLBinaryOpExpr) {
SQLExprImpl inlistExpr = null;
if (null == param || param.isEmpty()) {
inlistExpr = new SQLNullExpr();
SQLBinaryOpExpr xp = (SQLBinaryOpExpr) parent.getParent();
xp.setOperator(SQLBinaryOperator.Is);
if (xp.getRight().equals(parent)) {
xp.setRight(inlistExpr);
} else if (xp.getLeft().equals(parent)) {
xp.setLeft(inlistExpr);
}
} else {
int len = param.size();
SQLBinaryOpExpr xp = (SQLBinaryOpExpr) parent.getParent();
SQLExpr left = null;
if (xp.getRight().equals(parent)) {
left = xp.getLeft();
} else if (xp.getLeft().equals(parent)) {
left = xp.getRight();
}
SQLBinaryOpExpr p = xp;
for (int i = 0; i < len; i++) {
if (i < (len - 1)) {
SQLBinaryOpExpr rightop = new SQLBinaryOpExpr();
rightop.setOperator(SQLBinaryOperator.Equality);
SQLValuableExpr expr = (SQLValuableExpr) param.get(i);
rightop.setRight(expr);
rightop.setParent(p);
rightop.setLeft(left);
p.setRight(rightop);
p.setOperator(SQLBinaryOperator.BooleanAnd);
SQLBinaryOpExpr lefeop = new SQLBinaryOpExpr();
lefeop.setParent(p);
lefeop.setOperator(SQLBinaryOperator.Equality);
p.setLeft(lefeop);
p = (SQLBinaryOpExpr) p.getLeft();
} else {
p.setLeft(left);
p.setOperator(SQLBinaryOperator.Equality);
SQLValuableExpr expr = (SQLValuableExpr) param.get(i);
p.setRight(expr);
}
}
}
}
return statement.toString();
}
Aggregations