Search in sources :

Example 6 with SQLInSubQueryExpr

use of com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr in project druid by alibaba.

the class WallVisitorUtils method isFirstSelectTableSource.

private static boolean isFirstSelectTableSource(SQLObject x) {
    for (; ; ) {
        if (x instanceof SQLExpr) {
            x = x.getParent();
        } else {
            break;
        }
    }
    if (!(x instanceof SQLExprTableSource)) {
        return false;
    }
    SQLSelectQueryBlock queryBlock = null;
    SQLObject parent = x.getParent();
    while (parent != null) {
        if (parent instanceof SQLSelectQueryBlock) {
            queryBlock = (SQLSelectQueryBlock) parent;
            break;
        }
        x = parent;
        parent = x.getParent();
    }
    if (queryBlock == null) {
        return false;
    }
    boolean isWhereQueryExpr = false;
    boolean isSelectItem = false;
    do {
        x = parent;
        parent = parent.getParent();
        if (parent instanceof SQLUnionQuery) {
            SQLUnionQuery union = (SQLUnionQuery) parent;
            if (union.getRight() == x && hasTableSource(union.getLeft())) {
                return false;
            }
        } else if (parent instanceof SQLQueryExpr || parent instanceof SQLInSubQueryExpr || parent instanceof SQLExistsExpr) {
            isWhereQueryExpr = isWhereOrHaving(parent);
        } else if (parent instanceof SQLSelectItem) {
            isSelectItem = true;
        } else if ((isWhereQueryExpr || isSelectItem) && parent instanceof SQLSelectQueryBlock) {
            if (hasTableSource((SQLSelectQueryBlock) parent)) {
                return false;
            }
        }
    } while (parent != null);
    return true;
}
Also used : SQLObject(com.alibaba.druid.sql.ast.SQLObject) SQLQueryExpr(com.alibaba.druid.sql.ast.expr.SQLQueryExpr) SQLExistsExpr(com.alibaba.druid.sql.ast.expr.SQLExistsExpr) SQLInSubQueryExpr(com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

SQLInSubQueryExpr (com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)6 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)3 SQLObject (com.alibaba.druid.sql.ast.SQLObject)2 SQLExprParser (com.alibaba.druid.sql.parser.SQLExprParser)2 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)1 SQLOrderingSpecification (com.alibaba.druid.sql.ast.SQLOrderingSpecification)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLExistsExpr (com.alibaba.druid.sql.ast.expr.SQLExistsExpr)1 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)1 SQLConstraint (com.alibaba.druid.sql.ast.statement.SQLConstraint)1 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)1 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)1 SQLUpdateSetItem (com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem)1 Limit (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit)1 MySqlUpdateStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement)1 MySqlExprParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser)1 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)1 OracleExprParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser)1