use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGAlterTableDropNotNull method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products ALTER COLUMN product_no DROP NOT NULL;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals("ALTER TABLE products" + "\n\tALTER COLUMN product_no DROP NOT NULL;", stmt.toString());
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getDropCount() == 0);
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 1);
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGAlterTableRenameTest1 method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products RENAME COLUMN product_no TO product_number;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
statemen.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getDropCount() == 0);
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 2);
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PostgresqlResourceTest method mergValidate.
void mergValidate(String sql, String expect) {
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
Assert.assertEquals(1, statementList.size());
StringBuilder out = new StringBuilder();
PGOutputVisitor visitor = new PGOutputVisitor(out);
statemen.accept(visitor);
System.out.println(out.toString());
Assert.assertEquals(expect, out.toString());
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class BooleanTest method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO test1 VALUES (TRUE, 'sic est');";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
statemen.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test1")));
Assert.assertEquals(0, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "kind")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "code")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "date_prod")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "title")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "did")));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGAlterTableAddFk0 method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
statemen.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getDropCount() == 0);
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getAlterCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 1);
}
Aggregations