Search in sources :

Example 1 with SQLExprImpl

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();
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) MySqlSelectQueryBlock(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)

Example 2 with SQLExprImpl

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();
}
Also used : SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLValuableExpr(com.alibaba.druid.sql.ast.expr.SQLValuableExpr)

Example 3 with SQLExprImpl

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();
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLQueryExpr(com.alibaba.druid.sql.ast.expr.SQLQueryExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLListExpr(com.alibaba.druid.sql.ast.expr.SQLListExpr) SQLInSubQueryExpr(com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)

Example 4 with SQLExprImpl

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();
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLQueryExpr(com.alibaba.druid.sql.ast.expr.SQLQueryExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLListExpr(com.alibaba.druid.sql.ast.expr.SQLListExpr) SQLInSubQueryExpr(com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)

Example 5 with SQLExprImpl

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();
}
Also used : SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLValuableExpr(com.alibaba.druid.sql.ast.expr.SQLValuableExpr)

Aggregations

SQLExprImpl (com.alibaba.druid.sql.ast.SQLExprImpl)8 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)8 SQLNullExpr (com.alibaba.druid.sql.ast.expr.SQLNullExpr)8 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 SQLInListExpr (com.alibaba.druid.sql.ast.expr.SQLInListExpr)4 SQLListExpr (com.alibaba.druid.sql.ast.expr.SQLListExpr)4 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)4 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)4 SQLInSubQueryExpr (com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)2 SQLValuableExpr (com.alibaba.druid.sql.ast.expr.SQLValuableExpr)2 SQLSelectGroupByClause (com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause)2 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)2 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)2