use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGCreateTableTest_8 method test_0.
public void test_0() throws Exception {
String sql = "create table if not exists test_site_data_select_111 AS select * from postman_trace_info_one where lng>0 and lat>0 and site_id='17814' ;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("CREATE TABLE IF NOT EXISTS test_site_data_select_111\n" + "AS\n" + "SELECT *\n" + "FROM postman_trace_info_one\n" + "WHERE lng > 0\n" + "\tAND lat > 0\n" + "\tAND site_id = '17814';", SQLUtils.toPGString(stmt));
assertEquals("create table if not exists test_site_data_select_111\n" + "as\n" + "select *\n" + "from postman_trace_info_one\n" + "where lng > 0\n" + "\tand lat > 0\n" + "\tand site_id = '17814';", 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_site_data_select_111")));
assertTrue(visitor.getTables().get(new TableStat.Name("test_site_data_select_111")).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_7 method test_0.
public void test_0() throws Exception {
String sql = "create table test_site_data_select_111 AS select * from postman_trace_info_one where lng>0 and lat>0 and site_id='17814' ;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("CREATE TABLE test_site_data_select_111\n" + "AS\n" + "SELECT *\n" + "FROM postman_trace_info_one\n" + "WHERE lng > 0\n" + "\tAND lat > 0\n" + "\tAND site_id = '17814';", SQLUtils.toPGString(stmt));
assertEquals("create table test_site_data_select_111\n" + "as\n" + "select *\n" + "from postman_trace_info_one\n" + "where lng > 0\n" + "\tand lat > 0\n" + "\tand site_id = '17814';", 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_site_data_select_111")));
assertTrue(visitor.getTables().get(new TableStat.Name("test_site_data_select_111")).getCreateCount() == 1);
assertEquals(4, visitor.getColumns().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest10 method test_0.
public void test_0() throws Exception {
String sql = "delete from account a using (values (1), (7)) as tmp(id) WHERE a.id = tmp.id";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("DELETE FROM account AS a\n" + "USING (VALUES (1), (7)) AS tmp (id)\n" + "WHERE a.id = tmp.id", stmt.toString());
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());
assertTrue(visitor.getTables().containsKey(new TableStat.Name("account")));
assertEquals(1, visitor.getColumns().size());
assertTrue(visitor.containsColumn("account", "id"));
}
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 PGDeleteTest5 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);
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("films")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("producers")));
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