Search in sources :

Example 1 with MySqlSetTransactionStatement

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

the class MySqlStatementParser method parseSet.

public SQLStatement parseSet() {
    accept(Token.SET);
    if (identifierEquals("PASSWORD")) {
        lexer.nextToken();
        MySqlSetPasswordStatement stmt = new MySqlSetPasswordStatement();
        if (lexer.token() == Token.FOR) {
            lexer.nextToken();
            stmt.setUser(this.exprParser.name());
        }
        accept(Token.EQ);
        stmt.setPassword(this.exprParser.expr());
        return stmt;
    }
    Boolean global = null;
    if (identifierEquals(GLOBAL)) {
        global = Boolean.TRUE;
        lexer.nextToken();
    } else if (identifierEquals(SESSION)) {
        global = Boolean.FALSE;
        lexer.nextToken();
    }
    if (identifierEquals("TRANSACTION")) {
        MySqlSetTransactionStatement stmt = new MySqlSetTransactionStatement();
        stmt.setGlobal(global);
        lexer.nextToken();
        if (identifierEquals("ISOLATION")) {
            lexer.nextToken();
            acceptIdentifier("LEVEL");
            if (identifierEquals(READ)) {
                lexer.nextToken();
                if (identifierEquals("UNCOMMITTED")) {
                    stmt.setIsolationLevel("READ UNCOMMITTED");
                    lexer.nextToken();
                } else if (identifierEquals(WRITE)) {
                    stmt.setIsolationLevel("READ WRITE");
                    lexer.nextToken();
                } else if (identifierEquals("ONLY")) {
                    stmt.setIsolationLevel("READ ONLY");
                    lexer.nextToken();
                } else if (identifierEquals("COMMITTED")) {
                    stmt.setIsolationLevel("READ COMMITTED");
                    lexer.nextToken();
                } else {
                    throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
                }
            } else if (identifierEquals("SERIALIZABLE")) {
                stmt.setIsolationLevel("SERIALIZABLE");
                lexer.nextToken();
            } else if (identifierEquals("REPEATABLE")) {
                lexer.nextToken();
                if (identifierEquals(READ)) {
                    stmt.setIsolationLevel("REPEATABLE READ");
                    lexer.nextToken();
                } else {
                    throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
                }
            } else {
                throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
            }
        } else if (identifierEquals(READ)) {
            lexer.nextToken();
            if (identifierEquals("ONLY")) {
                stmt.setAccessModel("ONLY");
                lexer.nextToken();
            } else if (identifierEquals("WRITE")) {
                stmt.setAccessModel("WRITE");
                lexer.nextToken();
            } else {
                throw new ParserException("UNKOWN ACCESS MODEL : " + lexer.stringVal());
            }
        }
        return stmt;
    } else if (identifierEquals("NAMES")) {
        lexer.nextToken();
        MySqlSetNamesStatement stmt = new MySqlSetNamesStatement();
        if (lexer.token() == Token.DEFAULT) {
            lexer.nextToken();
            stmt.setDefault(true);
        } else {
            String charSet = lexer.stringVal();
            stmt.setCharSet(charSet);
            lexer.nextToken();
            if (identifierEquals(COLLATE2)) {
                lexer.nextToken();
                String collate = lexer.stringVal();
                stmt.setCollate(collate);
                lexer.nextToken();
            }
        }
        return stmt;
    } else if (identifierEquals(CHARACTER)) {
        lexer.nextToken();
        accept(Token.SET);
        MySqlSetCharSetStatement stmt = new MySqlSetCharSetStatement();
        if (lexer.token() == Token.DEFAULT) {
            lexer.nextToken();
            stmt.setDefault(true);
        } else {
            String charSet = lexer.stringVal();
            stmt.setCharSet(charSet);
            lexer.nextToken();
            if (identifierEquals(COLLATE2)) {
                lexer.nextToken();
                String collate = lexer.stringVal();
                stmt.setCollate(collate);
                lexer.nextToken();
            }
        }
        return stmt;
    } else {
        SQLSetStatement stmt = new SQLSetStatement(getDbType());
        parseAssignItems(stmt.getItems(), stmt);
        if (global != null && global.booleanValue()) {
            SQLVariantRefExpr varRef = (SQLVariantRefExpr) stmt.getItems().get(0).getTarget();
            varRef.setGlobal(true);
        }
        if (lexer.token() == Token.HINT) {
            stmt.setHints(this.exprParser.parseHints());
        }
        return stmt;
    }
}
Also used : MySqlSetNamesStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetNamesStatement) MySqlSetTransactionStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement) ParserException(com.alibaba.druid.sql.parser.ParserException) MySqlSetCharSetStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetCharSetStatement) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) MySqlSetPasswordStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetPasswordStatement)

Example 2 with MySqlSetTransactionStatement

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

the class DALParserTest method testSetTxn_1.

public void testSetTxn_1() throws Exception {
    String sql = "SET global transaction ISOLATION LEVEL READ COMMITTED";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    MySqlSetTransactionStatement set = (MySqlSetTransactionStatement) parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(set);
    Assert.assertEquals("SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED", output);
}
Also used : MySqlSetTransactionStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)

Example 3 with MySqlSetTransactionStatement

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

the class DALParserTest method testSetTxn_0.

public void testSetTxn_0() throws Exception {
    String sql = "SET transaction ISOLATION LEVEL READ UNCOMMITTED";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    MySqlSetTransactionStatement set = (MySqlSetTransactionStatement) parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(set);
    Assert.assertEquals("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED", output);
}
Also used : MySqlSetTransactionStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)

Example 4 with MySqlSetTransactionStatement

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

the class DALParserTest method testSetTxn_3.

public void testSetTxn_3() throws Exception {
    String sql = "SET session transaction ISOLATION LEVEL SERIALIZABLE";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    MySqlSetTransactionStatement set = (MySqlSetTransactionStatement) parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(set);
    Assert.assertEquals("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE", output);
}
Also used : MySqlSetTransactionStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)

Example 5 with MySqlSetTransactionStatement

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

the class DALParserTest method testSetTxn_2.

public void testSetTxn_2() throws Exception {
    String sql = "SET transaction ISOLATION LEVEL REPEATABLE READ ";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    MySqlSetTransactionStatement set = (MySqlSetTransactionStatement) parser.parseStatementList().get(0);
    parser.match(Token.EOF);
    String output = SQLUtils.toMySqlString(set);
    Assert.assertEquals("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ", output);
}
Also used : MySqlSetTransactionStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)

Aggregations

MySqlSetTransactionStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement)6 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)3 MySqlSetCharSetStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetCharSetStatement)2 MySqlSetNamesStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetNamesStatement)2 SQLLimit (com.alibaba.druid.sql.ast.SQLLimit)1 SQLBinaryExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryExpr)1 SQLBooleanExpr (com.alibaba.druid.sql.ast.expr.SQLBooleanExpr)1 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)1 SQLStartTransactionStatement (com.alibaba.druid.sql.ast.statement.SQLStartTransactionStatement)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 MySqlUseIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint)1 MySqlCharExpr (com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr)1 MySqlIntervalExpr (com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr)1 MySqlOutFileExpr (com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr)1 MySqlUserName (com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName)1 CobarShowStatus (com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus)1