Search in sources :

Example 96 with PGSQLStatementParser

use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.

the class PGAlterTableAddColumnTest0 method test_0.

public void test_0() throws Exception {
    String sql = "ALTER TABLE products ADD COLUMN description text;";
    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 97 with PGSQLStatementParser

use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.

the class PGAlterTableAddColumnTest1 method test_0.

public void test_0() throws Exception {
    String sql = "ALTER TABLE products ADD COLUMN description text CHECK (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);
}
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 98 with PGSQLStatementParser

use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.

the class PGCreateTableTest_3 method test_0.

public void test_0() throws Exception {
    String sql = //
    "CREATE TABLE products (" + //
    "    product_no integer," + //
    "    name text," + //
    "    price numeric DEFAULT nextval('products_product_no_seq')" + ");";
    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")).getCreateCount() == 1);
    Assert.assertTrue(visitor.getColumns().size() == 3);
}
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 99 with PGSQLStatementParser

use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.

the class PGCreateTableTest_5 method test_0.

public void test_0() throws Exception {
    String sql = //
    "CREATE TABLE products (" + //
    "  state           char(2)" + ") INHERITS (cities);";
    PGSQLStatementParser parser = new PGSQLStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals("CREATE TABLE products (" + "\n\tstate char(2)" + "\n) INHERITS (cities)", SQLUtils.toPGString(stmt));
    Assert.assertEquals("create table products (" + "\n\tstate char(2)" + "\n) inherits (cities)", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    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")).getCreateCount() == 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 100 with PGSQLStatementParser

use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.

the class PGDeleteTest 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.getFields().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)

Aggregations

PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)113 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)109 PGSchemaStatVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor)102 PGSelectStatement (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement)3 PGExportParameterVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGExportParameterVisitor)2 ParserException (com.alibaba.druid.sql.parser.ParserException)2 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)1 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)1 SQLUnionQuery (com.alibaba.druid.sql.ast.statement.SQLUnionQuery)1 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)1 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)1 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)1 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)1 PGDeleteStatement (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGDeleteStatement)1 PGInsertStatement (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement)1 PGSelectQueryBlock (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock)1 PGOutputVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor)1 SQLServerSelectQueryBlock (com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock)1 SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)1 Column (com.alibaba.druid.stat.TableStat.Column)1