Search in sources :

Example 1 with SQLServerOutput

use of com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput 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)

Example 2 with SQLServerOutput

use of com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput in project druid by alibaba.

the class SQLServerExprParser method parserOutput.

protected SQLServerOutput parserOutput() {
    if (identifierEquals("OUTPUT")) {
        lexer.nextToken();
        SQLServerOutput output = new SQLServerOutput();
        final List<SQLSelectItem> selectList = output.getSelectList();
        for (; ; ) {
            final SQLSelectItem selectItem = parseSelectItem();
            selectList.add(selectItem);
            if (lexer.token() != Token.COMMA) {
                break;
            }
            lexer.nextToken();
        }
        if (lexer.token() == Token.INTO) {
            lexer.nextToken();
            output.setInto(new SQLExprTableSource(this.name()));
            if (lexer.token() == (Token.LPAREN)) {
                lexer.nextToken();
                this.exprList(output.getColumns(), output);
                accept(Token.RPAREN);
            }
        }
        return output;
    }
    return null;
}
Also used : SQLSelectItem(com.alibaba.druid.sql.ast.statement.SQLSelectItem) SQLServerOutput(com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource)

Example 3 with SQLServerOutput

use of com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput in project druid by alibaba.

the class SQLServerStatementParser method parseUpdateStatement.

public SQLUpdateStatement parseUpdateStatement() {
    SQLServerUpdateStatement udpateStatement = createUpdateStatement();
    accept(Token.UPDATE);
    SQLServerTop top = this.getExprParser().parseTop();
    if (top != null) {
        udpateStatement.setTop(top);
    }
    SQLTableSource tableSource = this.exprParser.createSelectParser().parseTableSource();
    udpateStatement.setTableSource(tableSource);
    parseUpdateSet(udpateStatement);
    SQLServerOutput output = this.getExprParser().parserOutput();
    if (output != null) {
        udpateStatement.setOutput(output);
    }
    if (lexer.token() == Token.FROM) {
        lexer.nextToken();
        SQLTableSource from = this.exprParser.createSelectParser().parseTableSource();
        udpateStatement.setFrom(from);
    }
    if (lexer.token() == (Token.WHERE)) {
        lexer.nextToken();
        udpateStatement.setWhere(this.exprParser.expr());
    }
    return udpateStatement;
}
Also used : SQLServerTop(com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop) SQLServerUpdateStatement(com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement) SQLServerOutput(com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput)

Aggregations

SQLServerOutput (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput)3 SQLServerTop (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop)2 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)1 SQLServerInsertStatement (com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement)1 SQLServerUpdateStatement (com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement)1