mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser.
This commit is contained in:
@@ -21,7 +21,7 @@ import com.alibaba.druid.sql.ast.statement.SQLCommitStatement;
|
||||
public class PGCommitTest extends PGTest {
|
||||
public void testCommit() throws Exception {
|
||||
String sql = "commit;";
|
||||
String expected = "COMMIT";
|
||||
String expected = "COMMIT;";
|
||||
testParseSql(sql, expected, expected, SQLCommitStatement.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@ public class PGCreateTableTest_4 extends PGTest {
|
||||
+ "\n\tname text,"
|
||||
+ "\n\tprice numeric"
|
||||
+ "\n\t\tCHECK (price > 0)"
|
||||
+ "\n)", SQLUtils.toPGString(stmt));
|
||||
+ "\n);", SQLUtils.toPGString(stmt));
|
||||
|
||||
Assert.assertEquals("create table products ("
|
||||
+ "\n\tproduct_no integer,"
|
||||
+ "\n\tname text,"
|
||||
+ "\n\tprice numeric"
|
||||
+ "\n\t\tcheck (price > 0)"
|
||||
+ "\n)", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
+ "\n);", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ public class PGCreateTableTest_5 extends PGTest {
|
||||
|
||||
Assert.assertEquals("CREATE TABLE products ("
|
||||
+ "\n\tstate char(2)"
|
||||
+ "\n) INHERITS (cities)", SQLUtils.toPGString(stmt));
|
||||
+ "\n) INHERITS (cities);", SQLUtils.toPGString(stmt));
|
||||
|
||||
Assert.assertEquals("create table products ("
|
||||
+ "\n\tstate char(2)"
|
||||
+ "\n) inherits (cities)", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
+ "\n) inherits (cities);", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
|
||||
public class PGFromAsTest extends PGTest {
|
||||
public void testFromAs() throws Exception {
|
||||
String sql = "SELECT Count(*) FROM tb_abc AS t1 WHERE ((t1.a_id = 'global_a_id') AND (t1.owner = 'global_bc'));";
|
||||
String expectedSql = "SELECT COUNT(*)\nFROM tb_abc t1\nWHERE t1.a_id = 'global_a_id'\n\tAND t1.owner = 'global_bc'";
|
||||
String expectedSql = "SELECT COUNT(*)\nFROM tb_abc t1\nWHERE t1.a_id = 'global_a_id'\n\tAND t1.owner = 'global_bc';";
|
||||
String expectedPattern = "SELECT COUNT(*)\nFROM tb_abc t1\nWHERE t1.a_id = ?\n\tAND t1.owner = ?";
|
||||
testParseSql(sql, expectedSql, expectedPattern, PGSelectStatement.class);
|
||||
}
|
||||
|
||||
@@ -23,20 +23,20 @@ public class PGSetTest3 extends PGTest {
|
||||
Class<?> type = PGSetStatement.class;
|
||||
|
||||
String sql = "SET TIME ZONE 'Europe/Rome';";
|
||||
String expectedSql = "SET TIME ZONE 'Europe/Rome'";
|
||||
String expectedPattern = "SET TIME ZONE ?";
|
||||
String expectedSql = "SET TIME ZONE 'Europe/Rome';";
|
||||
String expectedPattern = "SET TIME ZONE ?;";
|
||||
testParseSql(sql, expectedSql, expectedPattern, type);
|
||||
|
||||
sql = "SET configuration_parameter TO DEFAULT;";
|
||||
expectedSql = "SET configuration_parameter TO DEFAULT";
|
||||
expectedSql = "SET configuration_parameter TO DEFAULT;";
|
||||
testParseSql(sql, expectedSql, expectedSql, type);
|
||||
|
||||
sql = "SET search_path TO my_schema, public;";
|
||||
expectedSql = "SET search_path TO my_schema, public";
|
||||
expectedSql = "SET search_path TO my_schema, public;";
|
||||
testParseSql(sql, expectedSql, expectedSql, type);
|
||||
|
||||
sql = "SET search_path = my_schema, public;";
|
||||
expectedSql = "SET search_path TO my_schema, public";
|
||||
expectedSql = "SET search_path TO my_schema, public;";
|
||||
testParseSql(sql, expectedSql, expectedSql, type);
|
||||
|
||||
sql = "SET a=1";
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGShowStatement;
|
||||
public class PGShowTest1 extends PGTest {
|
||||
public void testShowAll() throws Exception {
|
||||
String sql = "show all;";
|
||||
String expected = "SHOW ALL";
|
||||
String expected = "SHOW ALL;";
|
||||
testParseSql(sql, expected, expected, PGShowStatement.class);
|
||||
|
||||
sql = "show transaction_read_only;";
|
||||
expected = "SHOW transaction_read_only";
|
||||
expected = "SHOW transaction_read_only;";
|
||||
testParseSql(sql, expected, expected, PGShowStatement.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PGAlterTableDropDefault extends PGTest {
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals("ALTER TABLE products"
|
||||
+ "\n\tALTER COLUMN price DROP DEFAULT", stmt.toString());
|
||||
+ "\n\tALTER COLUMN price DROP DEFAULT;", stmt.toString());
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PGAlterTableDropNotNull extends PGTest {
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals("ALTER TABLE products"
|
||||
+ "\n\tALTER COLUMN product_no DROP NOT NULL", stmt.toString());
|
||||
+ "\n\tALTER COLUMN product_no DROP NOT NULL;", stmt.toString());
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PGAlterTableSetDefault extends PGTest {
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals("ALTER TABLE products"
|
||||
+ "\n\tALTER COLUMN price SET DEFAULT 7.77", stmt.toString());
|
||||
+ "\n\tALTER COLUMN price SET DEFAULT 7.77;", stmt.toString());
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PGAlterTableSetNotNull extends PGTest {
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals("ALTER TABLE products"
|
||||
+ "\n\tALTER COLUMN product_no SET NOT NULL", stmt.toString());
|
||||
+ "\n\tALTER COLUMN product_no SET NOT NULL;", stmt.toString());
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
|
||||
@@ -55,12 +55,12 @@ public class PGSelectIntoTest extends PGTest {
|
||||
Assert.assertEquals(result,"SELECT *" //
|
||||
+ "\nINTO films_recent" //
|
||||
+ "\nFROM films" //
|
||||
+ "\nWHERE date_prod >= '2002-01-01'");
|
||||
+ "\nWHERE date_prod >= '2002-01-01';");
|
||||
|
||||
String result_lcase = SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
Assert.assertEquals(result_lcase,"select *" //
|
||||
+ "\ninto films_recent" //
|
||||
+ "\nfrom films" //
|
||||
+ "\nwhere date_prod >= '2002-01-01'");
|
||||
+ "\nwhere date_prod >= '2002-01-01';");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PGSelectTest18 extends PGTest {
|
||||
+ "\n\t)"
|
||||
+ "\nSELECT n"
|
||||
+ "\nFROM t"
|
||||
+ "\nLIMIT 100", result);
|
||||
+ "\nLIMIT 100;", result);
|
||||
}
|
||||
{
|
||||
String result = SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
@@ -66,7 +66,7 @@ public class PGSelectTest18 extends PGTest {
|
||||
+ "\n\t)"
|
||||
+ "\nselect n"
|
||||
+ "\nfrom t"
|
||||
+ "\nlimit 100", result);
|
||||
+ "\nlimit 100;", result);
|
||||
}
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PGSelectTest49 extends TestCase {
|
||||
"UPDATE goods_detail\n" +
|
||||
"SET gd_number = gd_number - gdnumber\n" +
|
||||
"FROM sel\n" +
|
||||
"WHERE gd_id = gdid", SQLUtils.toPGString(stmt));
|
||||
"WHERE gd_id = gdid;", SQLUtils.toPGString(stmt));
|
||||
|
||||
assertEquals("with\n" +
|
||||
"\tsel\n" +
|
||||
@@ -57,7 +57,7 @@ public class PGSelectTest49 extends TestCase {
|
||||
"update goods_detail\n" +
|
||||
"set gd_number = gd_number - gdnumber\n" +
|
||||
"from sel\n" +
|
||||
"where gd_id = gdid", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
"where gd_id = gdid;", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
assertEquals(1, stmtList.size());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user