Search in sources :

Example 1 with SQLServerSetTransactionIsolationLevelStatement

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

the class SQLServerStatementParser method parseSet.

public SQLStatement parseSet() {
    accept(Token.SET);
    if (identifierEquals("TRANSACTION")) {
        lexer.nextToken();
        acceptIdentifier("ISOLATION");
        acceptIdentifier("LEVEL");
        SQLServerSetTransactionIsolationLevelStatement stmt = new SQLServerSetTransactionIsolationLevelStatement();
        if (identifierEquals("READ")) {
            lexer.nextToken();
            if (identifierEquals("UNCOMMITTED")) {
                stmt.setLevel("READ UNCOMMITTED");
                lexer.nextToken();
            } else if (identifierEquals("COMMITTED")) {
                stmt.setLevel("READ COMMITTED");
                lexer.nextToken();
            } else {
                throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
            }
        } else if (identifierEquals("SERIALIZABLE")) {
            stmt.setLevel("SERIALIZABLE");
            lexer.nextToken();
        } else if (identifierEquals("SNAPSHOT")) {
            stmt.setLevel("SNAPSHOT");
            lexer.nextToken();
        } else if (identifierEquals("REPEATABLE")) {
            lexer.nextToken();
            if (identifierEquals("READ")) {
                stmt.setLevel("REPEATABLE READ");
                lexer.nextToken();
            } else {
                throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
            }
        } else {
            throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
        }
        return stmt;
    }
    if (identifierEquals("STATISTICS")) {
        lexer.nextToken();
        SQLServerSetStatement stmt = new SQLServerSetStatement();
        if (identifierEquals("IO") || identifierEquals("XML") || identifierEquals("PROFILE") || identifierEquals("TIME")) {
            stmt.getItem().setTarget(new SQLIdentifierExpr("STATISTICS " + lexer.stringVal().toUpperCase()));
            lexer.nextToken();
            if (lexer.token() == Token.ON) {
                stmt.getItem().setValue(new SQLIdentifierExpr("ON"));
                lexer.nextToken();
            } else if (identifierEquals("OFF")) {
                stmt.getItem().setValue(new SQLIdentifierExpr("OFF"));
                lexer.nextToken();
            }
        }
        return stmt;
    }
    if (lexer.token() == Token.VARIANT) {
        SQLSetStatement stmt = new SQLSetStatement(getDbType());
        parseAssignItems(stmt.getItems(), stmt);
        return stmt;
    } else {
        SQLServerSetStatement stmt = new SQLServerSetStatement();
        stmt.getItem().setTarget(this.exprParser.expr());
        if (lexer.token() == Token.ON) {
            stmt.getItem().setValue(new SQLIdentifierExpr("ON"));
            lexer.nextToken();
        } else if (identifierEquals("OFF")) {
            stmt.getItem().setValue(new SQLIdentifierExpr("OFF"));
            lexer.nextToken();
        } else {
            stmt.getItem().setValue(this.exprParser.expr());
        }
        return stmt;
    }
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLServerSetTransactionIsolationLevelStatement(com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionIsolationLevelStatement) SQLServerSetStatement(com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)

Aggregations

SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 SQLServerSetStatement (com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement)1 SQLServerSetTransactionIsolationLevelStatement (com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionIsolationLevelStatement)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1