Search in sources :

Example 61 with SQLName

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

the class OracleSchemaStatVisitor method visit.

public boolean visit(OracleUpdateStatement x) {
    setAliasMap();
    setMode(x, Mode.Update);
    SQLTableSource tableSource = x.getTableSource();
    SQLExpr tableExpr = null;
    if (tableSource instanceof SQLExprTableSource) {
        tableExpr = ((SQLExprTableSource) tableSource).getExpr();
    }
    if (tableExpr instanceof SQLName) {
        String ident = tableExpr.toString();
        setCurrentTable(ident);
        TableStat stat = getTableStat(ident);
        stat.incrementUpdateCount();
        Map<String, String> aliasMap = getAliasMap();
        aliasMap.put(ident, ident);
        aliasMap.put(tableSource.getAlias(), ident);
    } else {
        tableSource.accept(this);
    }
    accept(x.getItems());
    accept(x.getWhere());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) SQLTableSource(com.alibaba.druid.sql.ast.statement.SQLTableSource) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 62 with SQLName

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

the class SQLStatementParser method parseDropTable.

protected SQLDropTableStatement parseDropTable(boolean acceptDrop) {
    if (acceptDrop) {
        accept(Token.DROP);
    }
    SQLDropTableStatement stmt = new SQLDropTableStatement(getDbType());
    if (identifierEquals("TEMPORARY")) {
        lexer.nextToken();
        stmt.setTemporary(true);
    }
    accept(Token.TABLE);
    if (lexer.token() == Token.IF) {
        lexer.nextToken();
        accept(Token.EXISTS);
        stmt.setIfExists(true);
    }
    for (; ; ) {
        SQLName name = this.exprParser.name();
        stmt.addPartition(new SQLExprTableSource(name));
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        }
        break;
    }
    for (; ; ) {
        if (identifierEquals("RESTRICT")) {
            lexer.nextToken();
            stmt.setRestrict(true);
            continue;
        }
        if (identifierEquals("CASCADE")) {
            lexer.nextToken();
            stmt.setCascade(true);
            if (identifierEquals("CONSTRAINTS")) {
                // for oracle
                lexer.nextToken();
            }
            continue;
        }
        if (lexer.token() == Token.PURGE || identifierEquals("PURGE")) {
            lexer.nextToken();
            stmt.setPurge(true);
            continue;
        }
        break;
    }
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 63 with SQLName

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

the class SQLStatementParser method parseAlterDrop.

public void parseAlterDrop(SQLAlterTableStatement stmt) {
    lexer.nextToken();
    boolean ifExists = false;
    if (lexer.token() == Token.IF) {
        lexer.nextToken();
        accept(Token.EXISTS);
        ifExists = true;
    }
    if (lexer.token() == Token.CONSTRAINT) {
        lexer.nextToken();
        SQLAlterTableDropConstraint item = new SQLAlterTableDropConstraint();
        item.setConstraintName(this.exprParser.name());
        stmt.addItem(item);
    } else if (lexer.token() == Token.COLUMN) {
        lexer.nextToken();
        SQLAlterTableDropColumnItem item = new SQLAlterTableDropColumnItem();
        this.exprParser.names(item.getColumns());
        if (lexer.token == Token.CASCADE) {
            item.setCascade(true);
            lexer.nextToken();
        }
        stmt.addItem(item);
    } else if (lexer.token() == Token.LITERAL_ALIAS) {
        SQLAlterTableDropColumnItem item = new SQLAlterTableDropColumnItem();
        this.exprParser.names(item.getColumns());
        if (lexer.token == Token.CASCADE) {
            item.setCascade(true);
            lexer.nextToken();
        }
        stmt.addItem(item);
    } else if (lexer.token() == Token.PARTITION) {
        SQLAlterTableDropPartition dropPartition = parseAlterTableDropPartition(ifExists);
        stmt.addItem(dropPartition);
    } else if (lexer.token() == Token.INDEX) {
        lexer.nextToken();
        SQLName indexName = this.exprParser.name();
        SQLAlterTableDropIndex item = new SQLAlterTableDropIndex();
        item.setIndexName(indexName);
        stmt.addItem(item);
    } else {
        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
    }
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 64 with SQLName

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

the class SQLStatementParser method parseDeleteStatement.

public SQLDeleteStatement parseDeleteStatement() {
    SQLDeleteStatement deleteStatement = new SQLDeleteStatement(getDbType());
    if (lexer.token() == Token.DELETE) {
        lexer.nextToken();
        if (lexer.token() == (Token.FROM)) {
            lexer.nextToken();
        }
        if (lexer.token() == Token.COMMENT) {
            lexer.nextToken();
        }
        SQLName tableName = exprParser.name();
        deleteStatement.setTableName(tableName);
        if (lexer.token() == Token.FROM) {
            lexer.nextToken();
            SQLTableSource tableSource = createSQLSelectParser().parseTableSource();
            deleteStatement.setFrom(tableSource);
        }
    }
    if (lexer.token() == (Token.WHERE)) {
        lexer.nextToken();
        SQLExpr where = this.exprParser.expr();
        deleteStatement.setWhere(where);
    }
    return deleteStatement;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 65 with SQLName

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

the class SQLStatementParser method parseInsert0.

protected void parseInsert0(SQLInsertInto insertStatement, boolean acceptSubQuery) {
    if (lexer.token() == Token.INTO) {
        lexer.nextToken();
        SQLName tableName = this.exprParser.name();
        insertStatement.setTableName(tableName);
        if (lexer.token() == Token.LITERAL_ALIAS) {
            insertStatement.setAlias(as());
        }
        parseInsert0_hinits(insertStatement);
        if (lexer.token() == Token.IDENTIFIER) {
            insertStatement.setAlias(lexer.stringVal());
            lexer.nextToken();
        }
    }
    if (lexer.token() == (Token.LPAREN)) {
        lexer.nextToken();
        parseInsertColumns(insertStatement);
        accept(Token.RPAREN);
    }
    if (lexer.token() == Token.VALUES) {
        lexer.nextToken();
        for (; ; ) {
            accept(Token.LPAREN);
            SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
            this.exprParser.exprList(values.getValues(), values);
            insertStatement.getValuesList().add(values);
            accept(Token.RPAREN);
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            } else {
                break;
            }
        }
    } else if (acceptSubQuery && (lexer.token() == Token.SELECT || lexer.token() == Token.LPAREN)) {
        SQLSelect select = this.createSQLSelectParser().select();
        insertStatement.setQuery(select);
    }
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

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