Search in sources :

Example 21 with PGSchemaStatVisitor

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);
}
Also used : WallProvider(com.alibaba.druid.wall.WallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) PGSchemaStatVisitor(com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) PGSQLStatementParser(com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)

Example 22 with PGSchemaStatVisitor

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")));
}
Also used : PGSchemaStatVisitor(com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) PGSQLStatementParser(com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)

Example 23 with PGSchemaStatVisitor

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")));
}
Also used : PGSchemaStatVisitor(com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) PGSQLStatementParser(com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)

Example 24 with PGSchemaStatVisitor

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")));
}
Also used : PGSchemaStatVisitor(com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) PGSQLStatementParser(com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)

Example 25 with PGSchemaStatVisitor

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", "*")));
}
Also used : PGSchemaStatVisitor(com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) PGSQLStatementParser(com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)107 PGSchemaStatVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor)107 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)102 Column (com.alibaba.druid.stat.TableStat.Column)1 WallProvider (com.alibaba.druid.wall.WallProvider)1 PGWallProvider (com.alibaba.druid.wall.spi.PGWallProvider)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1