use of com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer in project cobar by alibaba.
the class MySQLDMLSelectParserTest method testSelectChinese.
public void testSelectChinese() throws SQLSyntaxErrorException {
String sql = "SELect t1.id , t2.* from t1, test.t2 where test.t1.id='中''‘文' and t1.id=test.t2.id";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDMLSelectParser parser = new MySQLDMLSelectParser(lexer, new MySQLExprParser(lexer));
DMLSelectStatement select = parser.select();
Assert.assertNotNull(select);
String output = output2MySQL(select, sql);
Assert.assertEquals("SELECT t1.id, t2.* FROM t1, test.t2 WHERE test.t1.id = '中\\'‘文' AND t1.id = test.t2.id", output);
}
use of com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer in project cobar by alibaba.
the class MySQLDMLUpdateParserTest method testUpdate.
/**
* nothing has been pre-consumed <code><pre>
* 'UPDATE' 'LOW_PRIORITY'? 'IGNORE'? table_reference
* 'SET' colName ('='|'=') (expr|'DEFAULT') (',' colName ('='|'=') (expr|'DEFAULT'))*
* ('WHERE' cond)?
* {singleTable}? => ('ORDER' 'BY' orderBy)? ('LIMIT' count)?
* </pre></code>
*/
public void testUpdate() throws SQLSyntaxErrorException {
String sql = "upDate LOw_PRIORITY IGNORE test.t1 sEt t1.col1=?, col2=DefaulT";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDMLUpdateParser parser = new MySQLDMLUpdateParser(lexer, new MySQLExprParser(lexer));
DMLUpdateStatement update = parser.update();
String output = output2MySQL(update, sql);
Assert.assertNotNull(update);
Assert.assertEquals("UPDATE LOW_PRIORITY IGNORE test.t1 SET t1.col1 = ?, col2 = DEFAULT", output);
sql = "upDate IGNORE (t1) set col2=DefaulT order bY t1.col2 ";
lexer = new MySQLLexer(sql);
parser = new MySQLDMLUpdateParser(lexer, new MySQLExprParser(lexer));
update = parser.update();
output = output2MySQL(update, sql);
Assert.assertEquals("UPDATE IGNORE t1 SET col2 = DEFAULT ORDER BY t1.col2", output);
sql = "upDate (test.t1) SET col2=DefaulT order bY t1.col2 limit ? offset 1";
lexer = new MySQLLexer(sql);
parser = new MySQLDMLUpdateParser(lexer, new MySQLExprParser(lexer));
update = parser.update();
output = output2MySQL(update, sql);
Assert.assertEquals("UPDATE test.t1 SET col2 = DEFAULT ORDER BY t1.col2 LIMIT 1, ?", output);
sql = "upDate LOW_PRIORITY t1, test.t2 SET col2=DefaulT , col2='123''4'";
lexer = new MySQLLexer(sql);
parser = new MySQLDMLUpdateParser(lexer, new MySQLExprParser(lexer));
update = parser.update();
output = output2MySQL(update, sql);
Assert.assertEquals("UPDATE LOW_PRIORITY t1, test.t2 SET col2 = DEFAULT, col2 = '123\\'4'", output);
sql = "upDate LOW_PRIORITY t1, test.t2 SET col2:=DefaulT , col2='123''4' where id='a'";
lexer = new MySQLLexer(sql);
parser = new MySQLDMLUpdateParser(lexer, new MySQLExprParser(lexer));
update = parser.update();
output = output2MySQL(update, sql);
Assert.assertEquals("UPDATE LOW_PRIORITY t1, test.t2 SET col2 = DEFAULT, col2 = '123\\'4' WHERE id = 'a'", output);
}
use of com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer in project cobar by alibaba.
the class LiteralHexadecimalTest method testUtf8.
public void testUtf8() throws Exception {
String sql = "x'E982B1E7A195275C73'";
LiteralHexadecimal hex = (LiteralHexadecimal) new MySQLExprParser(new MySQLLexer(sql), "utf-8").expression();
Assert.assertEquals("邱硕'\\s", hex.evaluation(null));
sql = "x'd0A'";
hex = (LiteralHexadecimal) new MySQLExprParser(new MySQLLexer(sql), "utf-8").expression();
Assert.assertEquals("\r\n", hex.evaluation(null));
}
use of com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer in project cobar by alibaba.
the class MySQLDALParserTest method testdesc.
public void testdesc() throws Exception {
String sql = "desc tb1";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDALParser parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
SQLStatement desc = (DescTableStatement) parser.desc();
parser.match(MySQLToken.EOF);
String output = output2MySQL(desc, sql);
Assert.assertEquals("DESC tb1", output);
sql = "desc db.tb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
desc = (DescTableStatement) parser.desc();
parser.match(MySQLToken.EOF);
output = output2MySQL(desc, sql);
Assert.assertEquals("DESC db.tb1", output);
sql = "describe db.tb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDALParser(lexer, new MySQLExprParser(lexer));
desc = (DescTableStatement) parser.desc();
parser.match(MySQLToken.EOF);
output = output2MySQL(desc, sql);
Assert.assertEquals("DESC db.tb1", output);
}
use of com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer in project cobar by alibaba.
the class MySQLDDLParserTest method testTruncate.
public void testTruncate() throws Exception {
String sql = "Truncate table tb1";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDDLParser parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
DDLStatement trun = (DDLTruncateStatement) parser.truncate();
parser.match(MySQLToken.EOF);
String output = output2MySQL(trun, sql);
Assert.assertEquals("TRUNCATE TABLE tb1", output);
sql = "Truncate tb1";
lexer = new MySQLLexer(sql);
parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
trun = (DDLTruncateStatement) parser.truncate();
parser.match(MySQLToken.EOF);
output = output2MySQL(trun, sql);
Assert.assertEquals("TRUNCATE TABLE tb1", output);
}
Aggregations