Search in sources :

Example 1 with MySqlSetPasswordStatement

use of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetPasswordStatement 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)

Aggregations

SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)1 MySqlSetCharSetStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetCharSetStatement)1 MySqlSetNamesStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetNamesStatement)1 MySqlSetPasswordStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetPasswordStatement)1 MySqlSetTransactionStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionStatement)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1