Search in sources :

Example 6 with MySqlUpdateStatement

use of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement in project druid by alibaba.

the class MySqlSelectParser method parseUpdateStatment.

protected MySqlUpdateStatement parseUpdateStatment() {
    MySqlUpdateStatement update = new MySqlUpdateStatement();
    lexer.nextToken();
    if (identifierEquals("LOW_PRIORITY")) {
        lexer.nextToken();
        update.setLowPriority(true);
    }
    if (identifierEquals("IGNORE")) {
        lexer.nextToken();
        update.setIgnore(true);
    }
    if (identifierEquals("COMMIT_ON_SUCCESS")) {
        lexer.nextToken();
        update.setCommitOnSuccess(true);
    }
    if (identifierEquals("ROLLBACK_ON_FAIL")) {
        lexer.nextToken();
        update.setRollBackOnFail(true);
    }
    if (identifierEquals("QUEUE_ON_PK")) {
        lexer.nextToken();
        update.setQueryOnPk(true);
    }
    if (identifierEquals("TARGET_AFFECT_ROW")) {
        lexer.nextToken();
        SQLExpr targetAffectRow = this.exprParser.expr();
        update.setTargetAffectRow(targetAffectRow);
    }
    SQLTableSource updateTableSource = this.exprParser.createSelectParser().parseTableSource();
    update.setTableSource(updateTableSource);
    accept(Token.SET);
    for (; ; ) {
        SQLUpdateSetItem item = this.exprParser.parseUpdateSetItem();
        update.addItem(item);
        if (lexer.token() != Token.COMMA) {
            break;
        }
        lexer.nextToken();
    }
    if (lexer.token() == (Token.WHERE)) {
        lexer.nextToken();
        update.setWhere(this.exprParser.expr());
    }
    update.setOrderBy(this.exprParser.parseOrderBy());
    update.setLimit(this.exprParser.parseLimit());
    return update;
}
Also used : SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) MySqlUpdateStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement)

Aggregations

MySqlUpdateStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement)6 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)2 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)2 SQLLimit (com.alibaba.druid.sql.ast.SQLLimit)1 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)1 SQLOrderingSpecification (com.alibaba.druid.sql.ast.SQLOrderingSpecification)1 SQLBinaryExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryExpr)1 SQLBooleanExpr (com.alibaba.druid.sql.ast.expr.SQLBooleanExpr)1 SQLInSubQueryExpr (com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)1 SQLConstraint (com.alibaba.druid.sql.ast.statement.SQLConstraint)1 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)1 SQLStartTransactionStatement (com.alibaba.druid.sql.ast.statement.SQLStartTransactionStatement)1 SQLTableSource (com.alibaba.druid.sql.ast.statement.SQLTableSource)1 SQLUpdateSetItem (com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem)1 MySqlForceIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint)1 MySqlIgnoreIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)1 MySqlKey (com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey)1 MySqlPrimaryKey (com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey)1 MySqlUnique (com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique)1