use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_11 method test_0.
public void test_0() throws Exception {
String sql = "CREATE TABLE KTV.KTV_FUNCTION_ROLE_20151211 (\n" + "\tURL VARCHAR(150),\n" + "\tFUNCTION VARCHAR(1002),\n" + "\tROLE VARCHAR(100),\n" + "\t\"COUNT\" VARCHAR(102)\n" + ")";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("CREATE TABLE KTV.KTV_FUNCTION_ROLE_20151211 (\n" + "\tURL VARCHAR(150),\n" + "\tFUNCTION VARCHAR(1002),\n" + "\tROLE VARCHAR(100),\n" + "\t\"COUNT\" VARCHAR(102)\n" + ")", SQLUtils.toPGString(stmt));
assertEquals("create table KTV.KTV_FUNCTION_ROLE_20151211 (\n" + "\tURL VARCHAR(150),\n" + "\tFUNCTION VARCHAR(1002),\n" + "\tROLE VARCHAR(100),\n" + "\t\"COUNT\" VARCHAR(102)\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.KTV_FUNCTION_ROLE_20151211")));
assertTrue(visitor.getTables().get(new TableStat.Name("KTV.KTV_FUNCTION_ROLE_20151211")).getCreateCount() == 1);
assertEquals(4, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor 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);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor 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);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor 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 stmt = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
{
SchemaStatVisitor v = new SchemaStatVisitor();
stmt.accept(v);
}
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
stmt.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);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSelectIntoTest method test_0.
public void test_0() throws Exception {
String sql = "SELECT * INTO films_recent FROM films WHERE date_prod >= '2002-01-01';";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
// print(statementList);
Assert.assertEquals(1, statementList.size());
PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
stmt.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_recent")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("films")));
Assert.assertTrue(visitor.getColumns().contains(new Column("films", "*")));
Assert.assertTrue(visitor.getColumns().contains(new Column("films", "date_prod")));
String result = SQLUtils.toPGString(stmt);
Assert.assertEquals(result, //
"SELECT *" + //
"\nINTO films_recent" + //
"\nFROM films" + "\nWHERE date_prod >= '2002-01-01';");
String result_lcase = SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals(result_lcase, //
"select *" + //
"\ninto films_recent" + //
"\nfrom films" + "\nwhere date_prod >= '2002-01-01';");
}
Aggregations