bug fixed for mysql 5.7 union.

This commit is contained in:
wenshao
2017-04-18 15:51:25 +08:00
parent 9e80c23b7b
commit 6fe79f5ec1
8 changed files with 58 additions and 86 deletions
@@ -126,15 +126,15 @@ public class TenantInsertTest extends TestCase {
public void testMySql6() throws Exception {
String insert_sql = "INSERT INTO orders (ID, NAME) SELECT ID, NAME FROM temp1 WHERE age = 18 UNION SELECT ID, NAME FROM temp2 UNION ALL SELECT ID, NAME FROM temp3";
String expect_sql = "INSERT INTO orders (ID, NAME, tenant)" + //
"\nSELECT ID, NAME, 123" + //
"\n(SELECT ID, NAME, 123" + //
"\nFROM temp1" + //
"\nWHERE age = 18" + //
"\nWHERE age = 18)" + //
"\nUNION" + //
"\nSELECT ID, NAME, 123" + //
"\nFROM temp2" + //
"\n(SELECT ID, NAME, 123" + //
"\nFROM temp2)" + //
"\nUNION ALL" + //
"\nSELECT ID, NAME, 123" + //
"\nFROM temp3";
"\n(SELECT ID, NAME, 123" + //
"\nFROM temp3)";
{
MySqlWallProvider provider = new MySqlWallProvider(config_callback);
@@ -51,11 +51,11 @@ public class PagerUtilsTest_Count_MySql_0 extends TestCase {
String sql = "select id, name from t1 union select id, name from t2 order by id";
String result = PagerUtils.count(sql, JdbcConstants.MYSQL);
Assert.assertEquals("SELECT COUNT(*)\n" + //
"FROM (SELECT id, name" + //
"\n\tFROM t1" + //
"FROM ((SELECT id, name" + //
"\n\tFROM t1)" + //
"\n\tUNION" + //
"\n\tSELECT id, name" + //
"\n\tFROM t2" + //
"\n\t(SELECT id, name" + //
"\n\tFROM t2)" + //
"\n\t) ALIAS_COUNT", result);
}
}
@@ -31,11 +31,11 @@ public class DMLSelectParserTest extends TestCase {
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SELECT id\n" + //
"FROM t1\n" + //
Assert.assertEquals("(SELECT id\n" + //
"FROM t1)\n" + //
"UNION ALL\n" + //
"SELECT id\n" + //
"FROM t2\n" + //
"(SELECT id\n" + //
"FROM t2)\n" + //
"UNION ALL\n" + //
"(SELECT id\n" + //
"FROM t3)\n" + //
@@ -49,8 +49,8 @@ public class DMLSelectParserTest extends TestCase {
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SELECT id\n" + //
"FROM t1\n" + //
Assert.assertEquals("(SELECT id\n" + //
"FROM t1)\n" + //
"UNION\n" + //
"(SELECT id\n" + //
"FROM t2\n" + //
@@ -67,7 +67,7 @@ public class DMLSelectParserTest extends TestCase {
SQLStatement stmt = parser.parseStatementList().get(0);
parser.match(Token.EOF);
String output = SQLUtils.toMySqlString(stmt);
Assert.assertEquals("SELECT id\nFROM t1\nUNION DISTINCT\nSELECT id\nFROM t2\nUNION\nSELECT id\nFROM t3", output);
Assert.assertEquals("(SELECT id\nFROM t1)\nUNION DISTINCT\n(SELECT id\nFROM t2)\nUNION\n(SELECT id\nFROM t3)", output);
}
public void test_select_0() throws Exception {
@@ -49,13 +49,13 @@ public class MySqlDeleteTest_3 extends MysqlTest {
+ "\n\t\t\tSELECT *"
+ "\n\t\t\tFROM t3"
+ "\n\t\t\tWHERE ROW(5 * t2.s1, 77) = ("
+ "\n\t\t\t\tSELECT 50, 11 * s1"
+ "\n\t\t\t\tFROM t4"
+ "\n\t\t\t\t(SELECT 50, 11 * s1"
+ "\n\t\t\t\tFROM t4)"
+ "\n\t\t\t\tUNION"
+ "\n\t\t\t\tSELECT 50, 77"
+ "\n\t\t\t\t(SELECT 50, 77"
+ "\n\t\t\t\tFROM (SELECT *"
+ "\n\t\t\t\t\tFROM t5"
+ "\n\t\t\t\t\t) t5"
+ "\n\t\t\t\t\t) t5)"
+ "\n\t\t\t\t)"
+ "\n\t\t\t))", SQLUtils.toMySqlString(stmt));
Assert.assertEquals("delete from t1"
@@ -65,13 +65,13 @@ public class MySqlDeleteTest_3 extends MysqlTest {
+ "\n\t\t\tselect *"
+ "\n\t\t\tfrom t3"
+ "\n\t\t\twhere ROW(5 * t2.s1, 77) = ("
+ "\n\t\t\t\tselect 50, 11 * s1"
+ "\n\t\t\t\tfrom t4"
+ "\n\t\t\t\t(select 50, 11 * s1"
+ "\n\t\t\t\tfrom t4)"
+ "\n\t\t\t\tunion"
+ "\n\t\t\t\tselect 50, 77"
+ "\n\t\t\t\t(select 50, 77"
+ "\n\t\t\t\tfrom (select *"
+ "\n\t\t\t\t\tfrom t5"
+ "\n\t\t\t\t\t) t5"
+ "\n\t\t\t\t\t) t5)"
+ "\n\t\t\t\t)"
+ "\n\t\t\t))", SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
@@ -40,11 +40,13 @@ public class SQLUtilsTest extends TestCase {
public void test_format_3() throws Exception {
String sql = "select lottery_notice_issue,lottery_notice_date,lottery_notice_result from tb_lottery_notice where lottery_type_id=8 and lottery_notice_issue<=2014066 UNION ALL SELECT NULL, NULL, NULL, NULL, NULL, NULL# and lottery_notice_issue>=2014062 order by lottery_notice_issue desc";
String formattedSql = SQLUtils.formatMySql(sql);
String expected = "SELECT lottery_notice_issue, lottery_notice_date, lottery_notice_result"
+ "\nFROM tb_lottery_notice" + "\nWHERE lottery_type_id = 8"
+ "\n\tAND lottery_notice_issue <= 2014066" + "\nUNION ALL"
+ "\nSELECT NULL, NULL, NULL, NULL, NULL" //
+ "\n\t, NULL# and lottery_notice_issue>=2014062 order by lottery_notice_issue desc";
String expected = "(SELECT lottery_notice_issue, lottery_notice_date, lottery_notice_result"
+ "\nFROM tb_lottery_notice"
+ "\nWHERE lottery_type_id = 8"
+ "\n\tAND lottery_notice_issue <= 2014066)"
+ "\nUNION ALL"
+ "\n(SELECT NULL, NULL, NULL, NULL, NULL" //
+ "\n\t, NULL)# and lottery_notice_issue>=2014062 order by lottery_notice_issue desc";
Assert.assertEquals(expected, formattedSql);
}
}