use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class DMLSelectParserTest method test_select_15.
public void test_select_15() throws Exception {
String sql = "SELect distinct high_priority straight_join sql_big_result sql_cache tb1.id,tb2.id " + "from tb1,tb2 where tb1.id2=tb2.id2";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SELECT DISTINCT HIGH_PRIORITY STRAIGHT_JOIN SQL_BIG_RESULT" + " SQL_CACHE tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class DMLSelectParserTest method test_union_0.
public void test_union_0() throws Exception {
String sql = "(select id from t1) union all (select id from t2) union all (select id from t3) ordeR By d desC limit 1 offset ?";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"SELECT id\n" + //
"FROM t1\n" + //
"UNION ALL\n" + //
"SELECT id\n" + //
"FROM t2\n" + //
"UNION ALL\n" + //
"(SELECT id\n" + //
"FROM t3)\n" + //
"ORDER BY d DESC\n" + "LIMIT ?, 1", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class DMLSelectParserTest method test_union_1.
public void test_union_1() throws Exception {
String sql = "(select id from t1) union select id from t2 order by id union aLl (select id from t3) ordeR By d asC";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"SELECT id\n" + //
"FROM t1\n" + //
"UNION\n" + //
"(SELECT id\n" + //
"FROM t2\n" + //
"ORDER BY id)\n" + //
"UNION ALL\n" + //
"(SELECT id\n" + //
"FROM t3)\n" + "ORDER BY d ASC", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class DMLSelectParserTest method test_select_0.
public void test_select_0() throws Exception {
String sql = "SELect t1.id , t2.* from t1, test.t2 where test.t1.id=1 and t1.id=test.t2.id";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals(//
"SELECT t1.id, t2.*\n" + //
"FROM t1, test.t2\n" + //
"WHERE test.t1.id = 1\n" + "\tAND t1.id = test.t2.id", output);
}
use of com.alibaba.druid.sql.ast.SQLStatement in project druid by alibaba.
the class DMLSelectParserTest method test_select_3.
public void test_select_3() throws Exception {
String sql = "SELect distinct high_priority tb1.id,tb2.id from tb1,tb2 where tb1.id2=tb2.id2";
MySqlStatementParser parser = new MySqlStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SELECT DISTINCT HIGH_PRIORITY tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2", output);
}
Aggregations