Search in sources :

Example 6 with PGSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.

the class AliasTest_Type method test_timestamp.

public void test_timestamp() throws Exception {
    String sql = "select column1 as TYPE from table1 where xx=1";
    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);
    String mergedSql = ParameterizedOutputVisitorUtils.parameterize(sql, JdbcUtils.POSTGRESQL);
    System.out.println(mergedSql);
}
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 7 with PGSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.

the class PGSelectForUpdateTest method test_0.

public void test_0() throws Exception {
    String sql = "select pkvalue from dbtpktable where tablename = 'taturvisit' for update";
    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.assertEquals(2, visitor.getColumns().size());
    Assert.assertEquals(1, visitor.getTables().size());
}
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 8 with PGSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.

the class PGAlterTableDropColumnTest1 method test_0.

public void test_0() throws Exception {
    String sql = "ALTER TABLE products DROP COLUMN description CASCADE;";
    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);
}
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 9 with PGSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.

the class PGAlterTableDropConstraint method test_0.

public void test_0() throws Exception {
    String sql = "ALTER TABLE products DROP CONSTRAINT some_name;";
    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() == 0);
}
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 10 with PGSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.

the class PGAlterTableDropDefault method test_0.

public void test_0() throws Exception {
    String sql = "ALTER TABLE products ALTER COLUMN price DROP DEFAULT;";
    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 price DROP DEFAULT", 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);
}
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