Search in sources :

Example 41 with SQLName

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

the class SQLStatementParser method parseTruncate.

public SQLStatement parseTruncate() {
    accept(Token.TRUNCATE);
    if (lexer.token() == Token.TABLE) {
        lexer.nextToken();
    }
    SQLTruncateStatement stmt = new SQLTruncateStatement(getDbType());
    if (lexer.token() == Token.ONLY) {
        lexer.nextToken();
        stmt.setOnly(true);
    }
    for (; ; ) {
        SQLName name = this.exprParser.name();
        stmt.addTableSource(name);
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        }
        break;
    }
    for (; ; ) {
        if (lexer.token() == Token.PURGE) {
            lexer.nextToken();
            if (identifierEquals("SNAPSHOT")) {
                lexer.nextToken();
                acceptIdentifier("LOG");
                stmt.setPurgeSnapshotLog(true);
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
            continue;
        }
        if (lexer.token() == Token.RESTART) {
            lexer.nextToken();
            accept(Token.IDENTITY);
            stmt.setRestartIdentity(Boolean.TRUE);
            continue;
        } else if (lexer.token() == Token.SHARE) {
            lexer.nextToken();
            accept(Token.IDENTITY);
            stmt.setRestartIdentity(Boolean.FALSE);
            continue;
        }
        if (lexer.token() == Token.CASCADE) {
            lexer.nextToken();
            stmt.setCascade(Boolean.TRUE);
            continue;
        } else if (lexer.token() == Token.RESTRICT) {
            lexer.nextToken();
            stmt.setCascade(Boolean.FALSE);
            continue;
        }
        if (lexer.token() == Token.DROP) {
            lexer.nextToken();
            acceptIdentifier("STORAGE");
            stmt.setDropStorage(true);
            continue;
        }
        if (identifierEquals("REUSE")) {
            lexer.nextToken();
            acceptIdentifier("STORAGE");
            stmt.setReuseStorage(true);
            continue;
        }
        if (identifierEquals("IGNORE")) {
            lexer.nextToken();
            accept(Token.DELETE);
            acceptIdentifier("TRIGGERS");
            stmt.setIgnoreDeleteTriggers(true);
            continue;
        }
        if (identifierEquals("RESTRICT")) {
            lexer.nextToken();
            accept(Token.WHEN);
            accept(Token.DELETE);
            acceptIdentifier("TRIGGERS");
            stmt.setRestrictWhenDeleteTriggers(true);
            continue;
        }
        if (lexer.token() == Token.CONTINUE) {
            lexer.nextToken();
            accept(Token.IDENTITY);
            continue;
        }
        if (identifierEquals("IMMEDIATE")) {
            lexer.nextToken();
            stmt.setImmediate(true);
            continue;
        }
        break;
    }
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 42 with SQLName

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

the class SQLStatementParser method parseDropFunction.

protected SQLDropFunctionStatement parseDropFunction(boolean acceptDrop) {
    if (acceptDrop) {
        accept(Token.DROP);
    }
    SQLDropFunctionStatement stmt = new SQLDropFunctionStatement(getDbType());
    accept(Token.FUNCTION);
    if (lexer.token() == Token.IF) {
        lexer.nextToken();
        accept(Token.EXISTS);
        stmt.setIfExists(true);
    }
    SQLName name = this.exprParser.name();
    stmt.setName(name);
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 43 with SQLName

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

the class SchemaStatVisitor method visit.

@Override
public boolean visit(SQLDropTableStatement x) {
    setMode(x, Mode.Insert);
    setAliasMap();
    String originalTable = getCurrentTable();
    for (SQLExprTableSource tableSource : x.getTableSources()) {
        SQLName name = (SQLName) tableSource.getExpr();
        String ident = name.toString();
        setCurrentTable(ident);
        x.putAttribute("_old_local_", originalTable);
        TableStat stat = getTableStat(ident);
        stat.incrementDropCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, ident, ident);
    }
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 44 with SQLName

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

the class PGSchemaStatVisitor method visit.

@Override
public boolean visit(PGDeleteStatement x) {
    if (x.getWith() != null) {
        x.getWith().accept(this);
    }
    setAliasMap();
    for (SQLName name : x.getUsing()) {
        String ident = name.toString();
        TableStat stat = getTableStat(ident);
        stat.incrementSelectCount();
        Map<String, String> aliasMap = getAliasMap();
        if (aliasMap != null) {
            aliasMap.put(ident, ident);
        }
    }
    x.putAttribute("_original_use_mode", getMode());
    setMode(x, Mode.Delete);
    String ident = ((SQLIdentifierExpr) x.getTableName()).getName();
    setCurrentTable(ident);
    TableStat stat = getTableStat(ident, x.getAlias());
    stat.incrementDeleteCount();
    accept(x.getWhere());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)

Example 45 with SQLName

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

the class PGSchemaStatVisitor method visit.

@Override
public boolean visit(PGInsertStatement x) {
    setAliasMap();
    if (x.getWith() != null) {
        x.getWith().accept(this);
    }
    x.putAttribute("_original_use_mode", getMode());
    setMode(x, Mode.Insert);
    String originalTable = getCurrentTable();
    if (x.getTableName() instanceof SQLName) {
        String ident = ((SQLName) x.getTableName()).toString();
        setCurrentTable(ident);
        x.putAttribute("_old_local_", originalTable);
        TableStat stat = getTableStat(ident);
        stat.incrementInsertCount();
        Map<String, String> aliasMap = getAliasMap();
        if (aliasMap != null) {
            if (x.getAlias() != null) {
                aliasMap.put(x.getAlias(), ident);
            }
            aliasMap.put(ident, ident);
        }
    }
    accept(x.getColumns());
    accept(x.getQuery());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

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