use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGShowTest method test_0.
public void test_0() throws Exception {
String sql = "SHOW max_identifier_length";
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());
{
WallProvider provider = new PGWallProvider();
Assert.assertTrue(provider.checkValid(sql));
}
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("reviews")));
//Assert.assertTrue(visitor.getTables().get(new TableStat.Name("reviews")).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 PGDeleteTest5 method test_0.
public void test_0() throws Exception {
String sql = "DELETE FROM films USING producers WHERE producer_id = producers.id AND producers.name = 'foo';";
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("films")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("producers")));
Assert.assertTrue(visitor.getColumns().size() == 3);
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "producer_id")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("producers", "id")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("producers", "name")));
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest7 method test_0.
public void test_0() throws Exception {
String sql = "WITH t AS (" + " DELETE FROM foo" + ")" + "DELETE FROM bar;";
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("foo")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("bar")));
Assert.assertTrue(visitor.getColumns().size() == 0);
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("products", "date")));
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest8 method test_0.
public void test_0() throws Exception {
String sql = "WITH RECURSIVE included_parts(sub_part, part) AS (" + " SELECT sub_part, part FROM parts WHERE part = 'our_product'" + " UNION ALL" + " SELECT p.sub_part, p.part" + " FROM included_parts pr, parts p" + " WHERE p.part = pr.sub_part" + " )" + "DELETE FROM parts\n" + " WHERE part IN (SELECT part FROM included_parts);";
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("parts")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("included_parts")));
Assert.assertTrue(visitor.getColumns().size() == 3);
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("parts", "sub_part")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("included_parts", "sub_part")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("parts", "part")));
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGInsertTest3 method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO films SELECT * FROM tmp_films WHERE date_prod < '2004-05-07';";
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("films")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("tmp_films")));
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("tmp_films", "date_prod")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("tmp_films", "*")));
}
Aggregations