use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGInsertTest9 method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO distributors (did, dname) VALUES (10, 'Conrad International')\n" + " ON CONFLICT (did) WHERE is_active DO NOTHING;";
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("distributors")));
Assert.assertEquals(2, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "did")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("distributors", "dname")));
assertEquals("INSERT INTO distributors (did, dname)\n" + "VALUES (10, 'Conrad International')\n" + "ON CONFLICT (did) WHERE is_active DO NOTHING;", stmt.toString());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSetTest method test_0.
public void test_0() throws Exception {
String sql = "SET standard_conforming_strings=on";
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.assertEquals(0, visitor.getColumns().size());
String mergedSql = ParameterizedOutputVisitorUtils.parameterize(sql, JdbcUtils.POSTGRESQL);
System.out.println(mergedSql);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGDeleteTest9 method test_0.
public void test_0() throws Exception {
String sql = "DELETE FROM ecc_cpr.ccg_gts_Boardlw i\n" + "WHERE i.contract_header_id = ?";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
assertEquals("DELETE FROM ecc_cpr.ccg_gts_Boardlw AS i\n" + "WHERE i.contract_header_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("ecc_cpr.ccg_gts_Boardlw")));
assertEquals(1, visitor.getColumns().size());
assertTrue(visitor.containsColumn("ecc_cpr.ccg_gts_Boardlw", "contract_header_id"));
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class TruncateTest method test_1.
public void test_1() throws Exception {
String sql = "TRUNCATE bigtable, fattable RESTART IDENTITY;";
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("bigtable")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("fattable")));
Assert.assertTrue(visitor.getColumns().size() == 0);
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class TruncateTest method test_2.
public void test_2() throws Exception {
String sql = "TRUNCATE othertable CASCADE;";
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("othertable")));
Assert.assertTrue(visitor.getColumns().size() == 0);
}
Aggregations