use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateIndexTest_0 method test_0.
public void test_0() throws Exception {
String sql = "CREATE UNIQUE INDEX \"test_idx\" ON \"public\".\"city\" USING btree (\"name\");";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("CREATE UNIQUE INDEX \"test_idx\" ON \"public\".\"city\" USING btree (\"name\");", SQLUtils.toPGString(stmt));
assertEquals("create UNIQUE index \"test_idx\" on \"public\".\"city\" using btree (\"name\");", 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("public.city")));
assertTrue(visitor.getTables().get(new TableStat.Name("public.city")).getCreateIndexCount() == 1);
assertEquals(1, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_9 method test_0.
public void test_0() throws Exception {
String sql = "create table test(id bigint, TYPE varchar(20))";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("CREATE TABLE test (\n" + "\tid bigint,\n" + "\tTYPE varchar(20)\n" + ")", SQLUtils.toPGString(stmt));
assertEquals("create table test (\n" + "\tid bigint,\n" + "\tTYPE varchar(20)\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("test")));
assertTrue(visitor.getTables().get(new TableStat.Name("test")).getCreateCount() == 1);
assertEquals(2, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGInsertTest0 method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO films VALUES ('UA502', 'Bananas', 105, '1971-07-13', 'Comedy', '82 minutes');";
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.assertEquals(0, visitor.getColumns().size());
// Assert.assertTrue(visitor.getFields().contains(new TableStat.Column("films", "producer_id")));
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest2 method test_0.
public void test_0() throws Exception {
String sql = "DELETE FROM tasks WHERE CURRENT OF c_tasks;";
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() == 0);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest6 method test_0.
public void test_0() throws Exception {
String sql = "WITH moved_rows AS (" + " DELETE FROM products" + " WHERE" + " \"date\" >= '2010-10-01' AND" + " \"date\" < '2010-11-01'" + " RETURNING *" + ")" + "INSERT INTO products_log\n" + "SELECT * FROM moved_rows;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
// print(statementList);
System.out.println(stmt);
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("products")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products_log")));
Assert.assertTrue(visitor.getColumns().size() == 1);
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("products", "date")));
}
Aggregations