Search in sources :

Example 56 with PGSchemaStatVisitor

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

the class PGCreateTableTest_10 method test_0.

public void test_0() throws Exception {
    String sql = "CREATE TABLE KTV.ALI_KTV_LEADS_AREA_FIX_TBD (\n" + "\tID VARCHAR(200) NOT NULL,\n" + "\tTYPE VARCHAR(200),\n" + "\tCONSTRAINT idx_ALI_KTV_LEADS_AREA_FIX_TBD_PK0 PRIMARY KEY (ID)\n" + ")";
    PGSQLStatementParser parser = new PGSQLStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    assertEquals("CREATE TABLE KTV.ALI_KTV_LEADS_AREA_FIX_TBD (\n" + "\tID VARCHAR(200) NOT NULL,\n" + "\tTYPE VARCHAR(200),\n" + "\tCONSTRAINT idx_ALI_KTV_LEADS_AREA_FIX_TBD_PK0 PRIMARY KEY (ID)\n" + ")", SQLUtils.toPGString(stmt));
    assertEquals("create table KTV.ALI_KTV_LEADS_AREA_FIX_TBD (\n" + "\tID VARCHAR(200) not null,\n" + "\tTYPE VARCHAR(200),\n" + "\tconstraint idx_ALI_KTV_LEADS_AREA_FIX_TBD_PK0 primary key (ID)\n" + ")", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    assertEquals(1, statementList.size());
    PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
    stmt.accept(visitor);
    // System.out.println("Tables : " + visitor.getTables());
    // System.out.println("fields : " + visitor.getColumns());
    assertTrue(visitor.getTables().containsKey(new TableStat.Name("KTV.ALI_KTV_LEADS_AREA_FIX_TBD")));
    assertTrue(visitor.getTables().get(new TableStat.Name("KTV.ALI_KTV_LEADS_AREA_FIX_TBD")).getCreateCount() == 1);
    assertEquals(3, visitor.getColumns().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 57 with PGSchemaStatVisitor

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

the class PGCreateTableTest_12 method test_0.

public void test_0() throws Exception {
    String sql = "CREATE TABLE \"public\".\"city\" (\n" + "  \"id\" varchar(6) COLLATE \"default\" NOT NULL,\n" + "  \"name\" varchar(32) COLLATE \"default\" NOT NULL\n" + ") WITH (OIDS=FALSE);\n" + "COMMENT ON TABLE \"public\".\"city\" IS '城市';\n" + "COMMENT ON COLUMN \"public\".\"city\".\"name\" IS '城市名';";
    PGSQLStatementParser parser = new PGSQLStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    assertEquals("CREATE TABLE \"public\".\"city\" (\n" + "\t\"id\" varchar(6) NOT NULL,\n" + "\t\"name\" varchar(32) NOT NULL\n" + ")\n" + "WITH (OIDS = false);", SQLUtils.toPGString(stmt));
    assertEquals("create table \"public\".\"city\" (\n" + "\t\"id\" varchar(6) not null,\n" + "\t\"name\" varchar(32) not null\n" + ")\n" + "with (OIDS = false);", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    assertEquals(3, statementList.size());
    PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
    stmt.accept(visitor);
    // System.out.println("Tables : " + visitor.getTables());
    // System.out.println("fields : " + visitor.getColumns());
    assertTrue(visitor.getTables().containsKey(new TableStat.Name("public.city")));
    assertTrue(visitor.getTables().get(new TableStat.Name("public.city")).getCreateCount() == 1);
    assertEquals(2, visitor.getColumns().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 58 with PGSchemaStatVisitor

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

the class PGCreateTableTest_2 method test_0.

public void test_0() throws Exception {
    String sql = // 
    "CREATE TABLE products (" + // 
    "    product_no integer," + // 
    "    name text," + // 
    "    price numeric DEFAULT 9.99" + ");";
    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 59 with PGSchemaStatVisitor

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

the class PGCreateTableTest_4 method test_0.

public void test_0() throws Exception {
    String sql = // 
    "CREATE TABLE products (" + // 
    "    product_no integer," + // 
    "    name text," + // 
    "    price numeric CHECK (price > 0)" + ");";
    PGSQLStatementParser parser = new PGSQLStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals("CREATE TABLE products (" + "\n\tproduct_no integer," + "\n\tname text," + "\n\tprice numeric" + "\n\t\tCHECK (price > 0)" + "\n);", SQLUtils.toPGString(stmt));
    Assert.assertEquals("create table products (" + "\n\tproduct_no integer," + "\n\tname text," + "\n\tprice numeric" + "\n\t\tcheck (price > 0)" + "\n);", 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() == 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 60 with PGSchemaStatVisitor

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

the class PGCreateTableTest_6 method test_0.

public void test_0() throws Exception {
    String sql = "create table xxx as select * from xxx";
    PGSQLStatementParser parser = new PGSQLStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    assertEquals("CREATE TABLE xxx\n" + "AS\n" + "SELECT *\n" + "FROM xxx", SQLUtils.toPGString(stmt));
    assertEquals("create table xxx\n" + "as\n" + "select *\n" + "from xxx", SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
    assertEquals(1, statementList.size());
    PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
    stmt.accept(visitor);
    // System.out.println("Tables : " + visitor.getTables());
    // System.out.println("fields : " + visitor.getColumns());
    assertTrue(visitor.getTables().containsKey(new TableStat.Name("xxx")));
    assertTrue(visitor.getTables().get(new TableStat.Name("xxx")).getCreateCount() == 1);
    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)132 PGSchemaStatVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor)132 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)127 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)1 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