Search in sources :

Example 96 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class WallVisitorUtils method checkReadOnly.

public static void checkReadOnly(WallVisitor visitor, SQLTableSource tableSource) {
    if (tableSource instanceof SQLExprTableSource) {
        String tableName = null;
        SQLExpr tableNameExpr = ((SQLExprTableSource) tableSource).getExpr();
        if (tableNameExpr instanceof SQLName) {
            tableName = ((SQLName) tableNameExpr).getSimpleName();
        }
        boolean readOnlyValid = visitor.getProvider().checkReadOnlyTable(tableName);
        if (!readOnlyValid) {
            addViolation(visitor, ErrorCode.READ_ONLY, "table readonly : " + tableName, tableSource);
        }
    } else if (tableSource instanceof SQLJoinTableSource) {
        SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
        checkReadOnly(visitor, join.getLeft());
        checkReadOnly(visitor, join.getRight());
    }
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 97 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class WallVisitorUtils method check.

public static void check(WallVisitor visitor, SQLCreateTableStatement x) {
    String tableName = ((SQLName) x.getName()).getSimpleName();
    WallContext context = WallContext.current();
    if (context != null) {
        WallSqlTableStat tableStat = context.getTableStat(tableName);
        if (tableStat != null) {
            tableStat.incrementCreateCount();
        }
    }
}
Also used : WallSqlTableStat(com.alibaba.druid.wall.WallSqlTableStat) SQLName(com.alibaba.druid.sql.ast.SQLName) WallContext(com.alibaba.druid.wall.WallContext)

Example 98 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class WallVisitorUtils method check.

public static void check(WallVisitor visitor, SQLDropTableStatement x) {
    for (SQLTableSource item : x.getTableSources()) {
        if (item instanceof SQLExprTableSource) {
            SQLExpr expr = ((SQLExprTableSource) item).getExpr();
            String tableName = ((SQLName) expr).getSimpleName();
            WallContext context = WallContext.current();
            if (context != null) {
                WallSqlTableStat tableStat = context.getTableStat(tableName);
                if (tableStat != null) {
                    tableStat.incrementDropCount();
                }
            }
        }
    }
}
Also used : WallSqlTableStat(com.alibaba.druid.wall.WallSqlTableStat) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) WallContext(com.alibaba.druid.wall.WallContext)

Example 99 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class WallVisitorUtils method hasTableSource.

private static boolean hasTableSource(SQLTableSource x) {
    if (x == null) {
        return false;
    }
    if (x instanceof SQLExprTableSource) {
        SQLExpr fromExpr = ((SQLExprTableSource) x).getExpr();
        if (fromExpr instanceof SQLName) {
            String name = fromExpr.toString();
            name = form(name);
            if (name.equalsIgnoreCase("DUAL")) {
                return false;
            }
        }
        return true;
    } else if (x instanceof SQLJoinTableSource) {
        SQLJoinTableSource join = (SQLJoinTableSource) x;
        return hasTableSource(join.getLeft()) || hasTableSource(join.getRight());
    } else if (x instanceof SQLSubqueryTableSource) {
        return hasTableSource(((SQLSubqueryTableSource) x).getSelect().getQuery());
    }
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 100 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class WallVisitorUtils method isTopFromDenySchema.

private static boolean isTopFromDenySchema(WallVisitor visitor, SQLMethodInvokeExpr x) {
    SQLObject parent = x.getParent();
    for (; ; ) {
        if (parent instanceof SQLExpr || parent instanceof Item || parent instanceof SQLSelectItem) {
            parent = parent.getParent();
        } else {
            break;
        }
    }
    if (parent instanceof SQLSelectQueryBlock) {
        SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) parent;
        if (!(queryBlock.getParent() instanceof SQLSelect)) {
            return false;
        }
        SQLSelect select = (SQLSelect) queryBlock.getParent();
        if (!(select.getParent() instanceof SQLSelectStatement)) {
            return false;
        }
        SQLSelectStatement stmt = (SQLSelectStatement) select.getParent();
        if (stmt.getParent() != null) {
            return false;
        }
        SQLTableSource from = queryBlock.getFrom();
        if (from instanceof SQLExprTableSource) {
            SQLExpr fromExpr = ((SQLExprTableSource) from).getExpr();
            if (fromExpr instanceof SQLName) {
                String fromTableName = fromExpr.toString();
                return visitor.isDenyTable(fromTableName);
            }
        }
        return false;
    }
    return false;
}
Also used : Item(com.alibaba.druid.sql.ast.expr.SQLCaseExpr.Item) SQLObject(com.alibaba.druid.sql.ast.SQLObject) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

SQLName (com.alibaba.druid.sql.ast.SQLName)102 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)33 TableStat (com.alibaba.druid.stat.TableStat)20 ParserException (com.alibaba.druid.sql.parser.ParserException)17 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)8 SQLObject (com.alibaba.druid.sql.ast.SQLObject)6 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)6 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)6 WallContext (com.alibaba.druid.wall.WallContext)6 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)5 WallSqlTableStat (com.alibaba.druid.wall.WallSqlTableStat)5 SQLPartition (com.alibaba.druid.sql.ast.SQLPartition)4 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)4 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)4 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)4 SQLTableElement (com.alibaba.druid.sql.ast.statement.SQLTableElement)4 SQLSubPartition (com.alibaba.druid.sql.ast.SQLSubPartition)3 SQLLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLLiteralExpr)3 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)3