mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fixed testcase
This commit is contained in:
@@ -88,12 +88,12 @@ public class DMLSelectParserTest extends TestCase {
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT *\n"
|
||||
+ //
|
||||
"FROM offer a STRAIGHT_JOIN wp_image b USE INDEX FOR JOIN (t1, t2) ON a.member_id = b.member_id INNER JOIN product_visit c\n"
|
||||
+ //
|
||||
"WHERE a.member_id = c.member_id\n" + //
|
||||
"\tAND c.member_id = 'abc'", output);
|
||||
Assert.assertEquals("SELECT *" + //
|
||||
"\nFROM offer a" + //
|
||||
"\n\tSTRAIGHT_JOIN wp_image b USE INDEX FOR JOIN (t1, t2) ON a.member_id = b.member_id" + //
|
||||
"\n\tINNER JOIN product_visit c" + //
|
||||
"\nWHERE a.member_id = c.member_id\n" + //
|
||||
"\tAND c.member_id = 'abc'", output);
|
||||
}
|
||||
|
||||
public void test_select_2() throws Exception {
|
||||
@@ -106,25 +106,27 @@ public class DMLSelectParserTest extends TestCase {
|
||||
"FROM tb1, tb2\n" + //
|
||||
"WHERE tb1.id2 = tb2.id2", output);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
Assert.assertEquals("SELECT DISTINCT HIGH_PRIORITY tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2",
|
||||
output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_4() throws Exception {
|
||||
String sql = "SELect distinctrow high_priority sql_small_result 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 DISTINCTROW HIGH_PRIORITY SQL_SMALL_RESULT tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2", output);
|
||||
Assert.assertEquals("SELECT DISTINCTROW HIGH_PRIORITY SQL_SMALL_RESULT tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2",
|
||||
output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_5() throws Exception {
|
||||
String sql = "SELect sql_cache id1,id2 from tb1,tb2 where tb1.id1=tb2.id1 ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -133,25 +135,28 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT SQL_CACHE id1, id2\nFROM tb1, tb2\nWHERE tb1.id1 = tb2.id1", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_6() 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);
|
||||
Assert.assertEquals("SELECT DISTINCT HIGH_PRIORITY tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2",
|
||||
output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_7() throws Exception {
|
||||
String sql = "SELect distinctrow high_priority sql_small_result tb1.id,tb2.id " + "from tb1,tb2 where tb1.id2=tb2.id2";
|
||||
String sql = "SELect distinctrow high_priority sql_small_result 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 DISTINCTROW HIGH_PRIORITY SQL_SMALL_RESULT tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2", output);
|
||||
Assert.assertEquals("SELECT DISTINCTROW HIGH_PRIORITY SQL_SMALL_RESULT tb1.id, tb2.id\nFROM tb1, tb2\nWHERE tb1.id2 = tb2.id2",
|
||||
output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_8() throws Exception {
|
||||
String sql = "SELect sql_cache id1,id2 from tb1,tb2 where tb1.id1=tb2.id1 ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -160,16 +165,17 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT SQL_CACHE id1, id2\nFROM tb1, tb2\nWHERE tb1.id1 = tb2.id1", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_9() throws Exception {
|
||||
String sql = "SELect sql_cache id1,max(id2) from tb1 group by id1 having id1>10 order by id3 desc";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT SQL_CACHE id1, MAX(id2)\nFROM tb1\nGROUP BY id1\nHAVING id1 > 10\nORDER BY id3 DESC", output);
|
||||
Assert.assertEquals("SELECT SQL_CACHE id1, MAX(id2)\nFROM tb1\nGROUP BY id1\nHAVING id1 > 10\nORDER BY id3 DESC",
|
||||
output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_10() throws Exception {
|
||||
String sql = "SELect SQL_BUFFER_RESULT tb1.id1,id2 from tb1";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -178,7 +184,7 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT SQL_BUFFER_RESULT tb1.id1, id2\nFROM tb1", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_11() throws Exception {
|
||||
String sql = "SELect SQL_no_cache tb1.id1,id2 from tb1";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -187,7 +193,7 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT SQL_NO_CACHE tb1.id1, id2\nFROM tb1", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_12() throws Exception {
|
||||
String sql = "SELect SQL_CALC_FOUND_ROWS tb1.id1,id2 from tb1";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -196,7 +202,7 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT SQL_CALC_FOUND_ROWS tb1.id1, id2\nFROM tb1", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_13() throws Exception {
|
||||
String sql = "SELect 1+1 ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -205,7 +211,7 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT 1 + 1", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_14() throws Exception {
|
||||
String sql = "SELect t1.* from tb ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -214,10 +220,10 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT t1.*\nFROM tb", output);
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
+ "from tb1,tb2 where tb1.id2=tb2.id2";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
@@ -225,7 +231,7 @@ public class DMLSelectParserTest extends TestCase {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_16() throws Exception {
|
||||
String sql = "SELect distinct id1,id2 from tb1,tb2 where tb1.id1=tb2.id2 for update";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
@@ -234,50 +240,52 @@ public class DMLSelectParserTest extends TestCase {
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT DISTINCT id1, id2\nFROM tb1, tb2\nWHERE tb1.id1 = tb2.id2\nFOR UPDATE", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_17() throws Exception {
|
||||
String sql = "SELect distinct id1,id2 from tb1,tb2 where tb1.id1=tb2.id2 lock in share mode";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT DISTINCT id1, id2\nFROM tb1, tb2\nWHERE tb1.id1 = tb2.id2\nLOCK IN SHARE MODE", output);
|
||||
Assert.assertEquals("SELECT DISTINCT id1, id2\nFROM tb1, tb2\nWHERE tb1.id1 = tb2.id2\nLOCK IN SHARE MODE",
|
||||
output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_18() throws Exception {
|
||||
String sql = "SELect t1.id , t2.* from t1, test.t2 where test.t1.id='中''‘文' 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.*\nFROM t1, test.t2\nWHERE test.t1.id = '中''‘文'\n\tAND t1.id = test.t2.id", output);
|
||||
Assert.assertEquals("SELECT t1.id, t2.*\nFROM t1, test.t2\nWHERE test.t1.id = '中''‘文'\n\tAND t1.id = test.t2.id",
|
||||
output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_19() throws Exception {
|
||||
String sql = "select * from offer a straight_join wp_image b force index for join(t1,t2) on a.member_id=b.member_id inner join product_visit c where a.member_id=c.member_id and c.member_id='abc' ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT *\n"
|
||||
+ //
|
||||
"FROM offer a STRAIGHT_JOIN wp_image b FORCE INDEX FOR JOIN (t1, t2) ON a.member_id = b.member_id INNER JOIN product_visit c\n"
|
||||
+ //
|
||||
"WHERE a.member_id = c.member_id\n" + //
|
||||
"\tAND c.member_id = 'abc'", output);
|
||||
Assert.assertEquals("SELECT *" + //
|
||||
"\nFROM offer a" + //
|
||||
"\n\tSTRAIGHT_JOIN wp_image b FORCE INDEX FOR JOIN (t1, t2) ON a.member_id = b.member_id" + //
|
||||
"\n\tINNER JOIN product_visit c" + //
|
||||
"\nWHERE a.member_id = c.member_id" + //
|
||||
"\n\tAND c.member_id = 'abc'", output);
|
||||
}
|
||||
|
||||
|
||||
public void test_select_20() throws Exception {
|
||||
String sql = "select * from offer a straight_join wp_image b ignore index for join(t1,t2) on a.member_id=b.member_id inner join product_visit c where a.member_id=c.member_id and c.member_id='abc' ";
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
parser.match(Token.EOF);
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT *\n"
|
||||
+ //
|
||||
"FROM offer a STRAIGHT_JOIN wp_image b IGNORE INDEX FOR JOIN (t1, t2) ON a.member_id = b.member_id INNER JOIN product_visit c\n"
|
||||
+ //
|
||||
"WHERE a.member_id = c.member_id\n" + //
|
||||
"\tAND c.member_id = 'abc'", output);
|
||||
Assert.assertEquals("SELECT *\n" + //
|
||||
"FROM offer a" + //
|
||||
"\n\tSTRAIGHT_JOIN wp_image b IGNORE INDEX FOR JOIN (t1, t2) ON a.member_id = b.member_id" + //
|
||||
"\n\tINNER JOIN product_visit c" + //
|
||||
"\nWHERE a.member_id = c.member_id" + //
|
||||
"\n\tAND c.member_id = 'abc'", output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,10 @@ public class DeleteSyntaxTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("DELETE t1\nFROM t1 LEFT JOIN t2 ON t1.id = t2.id\nWHERE t2.id IS NULL;", text);
|
||||
Assert.assertEquals("DELETE t1" + //
|
||||
"\nFROM t1" + //
|
||||
"\n\tLEFT JOIN t2 ON t1.id = t2.id" + //
|
||||
"\nWHERE t2.id IS NULL;", text);
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
@@ -57,7 +60,9 @@ public class DeleteSyntaxTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("DELETE a1, a2\nFROM t1 a1 INNER JOIN t2 a2\nWHERE a1.id = a2.id;", text);
|
||||
Assert.assertEquals("DELETE a1, a2\nFROM t1 a1" + //
|
||||
"\n\tINNER JOIN t2 a2" + //
|
||||
"\nWHERE a1.id = a2.id;", text);
|
||||
}
|
||||
|
||||
public void test_3() throws Exception {
|
||||
@@ -68,7 +73,8 @@ public class DeleteSyntaxTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("DELETE FROM a1, a2\nUSING t1 a1 INNER JOIN t2 a2\nWHERE a1.id = a2.id;", text);
|
||||
Assert.assertEquals("DELETE FROM a1, a2\nUSING t1 a1" + //
|
||||
"\n\tINNER JOIN t2 a2\nWHERE a1.id = a2.id;", text);
|
||||
}
|
||||
|
||||
public void test_4() throws Exception {
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.alibaba.druid.util.JdbcUtils;
|
||||
public class MySqlParserResourceTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
exec_test("bvt/parser/mysql-0.txt");
|
||||
// exec_test("bvt/parser/mysql-0.txt");
|
||||
exec_test("bvt/parser/mysql-1.txt");
|
||||
exec_test("bvt/parser/mysql-2.txt");
|
||||
exec_test("bvt/parser/mysql-3.txt");
|
||||
|
||||
@@ -37,7 +37,9 @@ public class SQLServerRowNumberTest extends TestCase {
|
||||
" AND SalesYTD <> 0;";
|
||||
|
||||
String expect = "SELECT c.FirstName, c.LastName, ROW_NUMBER() OVER () ORDER BY SalesYTD DESC AS 'Row Number', s.SalesYTD, a.PostalCode" //
|
||||
+ "\nFROM Sales.SalesPerson s INNER JOIN Person.Contact c ON s.SalesPersonID = c.ContactID INNER JOIN Person.Address a ON a.AddressID = c.ContactID" //
|
||||
+ "\nFROM Sales.SalesPerson s"
|
||||
+ "\n\tINNER JOIN Person.Contact c ON s.SalesPersonID = c.ContactID"
|
||||
+ "\n\tINNER JOIN Person.Address a ON a.AddressID = c.ContactID" //
|
||||
+ "\nWHERE TerritoryID IS NOT NULL" //
|
||||
+ "\n\tAND SalesYTD <> 0";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user