use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGExportParameterVisitorTest1 method test_pg.
public void test_pg() throws Exception {
String sql = "select fname, count(*) from t where fid = 1 group by fname order by 1";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
SQLStatement stmt = parser.parseStatementList().get(0);
PGExportParameterVisitor visitor = new PGExportParameterVisitor();
stmt.accept(visitor);
List<Object> parameters = visitor.getParameters();
Assert.assertEquals(1, parameters.size());
Assert.assertEquals(1, parameters.get(0));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser 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.parser.PGSQLStatementParser in project druid by alibaba.
the class PGInsertTest1 method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO films (code, title, did, date_prod, kind) VALUES ('T_601', 'Yojimbo', 106, '1961-06-16', 'Drama');";
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(5, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "kind")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "code")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "date_prod")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "title")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "did")));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGInsertTest2 method test_0.
public void test_0() throws Exception {
String sql = "INSERT INTO films (code, title, did, date_prod, kind) VALUES" + " ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'), " + "('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');";
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.assertEquals(5, visitor.getColumns().size());
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "kind")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "code")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "date_prod")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "title")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("films", "did")));
}
use of com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser in project druid by alibaba.
the class PGSelectTest15 method test_0.
public void test_0() throws Exception {
String sql = "WITH RECURSIVE search_graph(id, link, data, depth) AS (" + " SELECT g.id, g.link, g.data, 1" + " FROM graph g" + " UNION ALL" + " SELECT g.id, g.link, g.data, sg.depth + 1" + " FROM graph g, search_graph sg" + " WHERE g.id = sg.link" + ")" + "SELECT * FROM search_graph;";
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(7, visitor.getColumns().size());
Assert.assertEquals(2, visitor.getTables().size());
}
Aggregations