Search in sources :

Example 31 with SQLName

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

the class OracleSchemaStatVisitor method visit.

@Override
public boolean visit(InsertIntoClause x) {
    if (x.getTableName() instanceof SQLName) {
        String ident = ((SQLName) x.getTableName()).toString();
        setCurrentTable(x, ident);
        TableStat stat = getTableStat(ident);
        stat.incrementInsertCount();
        Map<String, String> aliasMap = getAliasMap();
        if (aliasMap != null) {
            if (x.getAlias() != null) {
                putAliasMap(aliasMap, x.getAlias(), ident);
            }
            putAliasMap(aliasMap, ident, ident);
        }
    }
    accept(x.getColumns());
    accept(x.getQuery());
    accept(x.getReturning());
    accept(x.getErrorLogging());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 32 with SQLName

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

the class OracleSchemaStatVisitor method visit.

@Override
public boolean visit(OracleForStatement x) {
    x.getRange().setParent(x);
    SQLName index = x.getIndex();
    this.getVariants().put(index.toString(), x);
    x.getRange().accept(this);
    accept(x.getStatements());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 33 with SQLName

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

the class OracleSchemaStatVisitor method visit.

public boolean visit(OracleSelectQueryBlock x) {
    if (x.getWhere() != null) {
        x.getWhere().setParent(x);
    }
    if (x.getInto() instanceof SQLName) {
        String tableName = x.getInto().toString();
        TableStat stat = getTableStat(tableName);
        if (stat != null) {
            stat.incrementInsertCount();
        }
    }
    visit((SQLSelectQueryBlock) x);
    return true;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 34 with SQLName

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

the class SQLServerStatementParser method parseBlock.

public SQLStatement parseBlock() {
    accept(Token.BEGIN);
    if (identifierEquals("TRANSACTION") || identifierEquals("TRAN")) {
        lexer.nextToken();
        SQLStartTransactionStatement startTrans = new SQLStartTransactionStatement();
        if (lexer.token() == Token.IDENTIFIER) {
            SQLName name = this.exprParser.name();
            startTrans.setName(name);
        }
        return startTrans;
    }
    SQLBlockStatement block = new SQLBlockStatement();
    parseStatementList(block.getStatementList());
    accept(Token.END);
    return block;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 35 with SQLName

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

the class SQLServerStatementParser method parseInsert0.

protected void parseInsert0(SQLInsertInto insert, boolean acceptSubQuery) {
    SQLServerInsertStatement insertStatement = (SQLServerInsertStatement) insert;
    SQLServerTop top = this.getExprParser().parseTop();
    if (top != null) {
        insertStatement.setTop(top);
    }
    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 && !lexer.stringVal().equalsIgnoreCase("OUTPUT")) {
        insertStatement.setAlias(lexer.stringVal());
        lexer.nextToken();
    }
    if (lexer.token() == (Token.LPAREN)) {
        lexer.nextToken();
        this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
        accept(Token.RPAREN);
    }
    SQLServerOutput output = this.getExprParser().parserOutput();
    if (output != null) {
        insertStatement.setOutput(output);
    }
    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 (!parseCompleteValues && insertStatement.getValuesList().size() >= parseValuesSize) {
                lexer.skipToEOF();
                break;
            }
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            } else {
                break;
            }
        }
    } else if (acceptSubQuery && (lexer.token() == Token.SELECT || lexer.token() == Token.LPAREN)) {
        SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr();
        insertStatement.setQuery(queryExpr.getSubQuery());
    } else if (lexer.token() == Token.DEFAULT) {
        lexer.nextToken();
        accept(Token.VALUES);
        insertStatement.setDefaultValues(true);
    }
}
Also used : SQLServerInsertStatement(com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement) SQLServerTop(com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop) SQLQueryExpr(com.alibaba.druid.sql.ast.expr.SQLQueryExpr) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLServerOutput(com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput)

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