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;
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations