use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor 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.visitor.PGSchemaStatVisitor 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);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGAlterTableAddUnique0 method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no);";
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);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGAlterTableDropColumnTest0 method test_0.
public void test_0() throws Exception {
String sql = "ALTER TABLE products DROP COLUMN description;";
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);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_0 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE my_first_table (" + //
" first_column text," + //
" second_column integer" + ");";
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("my_first_table")));
Assert.assertTrue(visitor.getTables().get(new TableStat.Name("my_first_table")).getCreateCount() == 1);
Assert.assertTrue(visitor.getColumns().size() == 2);
}
Aggregations