use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_1 method test_0.
public void test_0() throws Exception {
String sql = //
"CREATE TABLE products (" + //
" product_no integer," + //
" name text," + //
" price numeric" + ");";
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_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);
}
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);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest3 method test_0.
public void test_0() throws Exception {
String sql = "DELETE FROM tasks WHERE status = 'DONE' RETURNING *;";
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("tasks")));
Assert.assertTrue(visitor.getColumns().size() == 1);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest4 method test_0.
public void test_0() throws Exception {
String sql = "DELETE FROM films WHERE producer_id IN (SELECT id FROM producers WHERE 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());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("films")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("producers")));
// System.out.println("coditions : " + visitor.getConditions());
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")));
}
Aggregations