use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSelectTest18 method test_0.
public void test_0() throws Exception {
String sql = "WITH RECURSIVE t(n) AS (" + " SELECT 1" + " UNION ALL" + " SELECT n+1 FROM t" + ")" + "SELECT n FROM t LIMIT 100;";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
{
String result = SQLUtils.toPGString(stmt);
Assert.assertEquals("WITH RECURSIVE " + "\n\tt (n)" + "\n\tAS" + "\n\t(" + "\n\t\tSELECT 1" + "\n\t\tUNION ALL" + "\n\t\tSELECT n + 1" + "\n\t\tFROM t" + "\n\t)" + "\nSELECT n" + "\nFROM t" + "\nLIMIT 100", result);
}
{
String result = SQLUtils.toPGString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
Assert.assertEquals("with recursive " + "\n\tt (n)" + "\n\tas" + "\n\t(" + "\n\t\tselect 1" + "\n\t\tunion all" + "\n\t\tselect n + 1" + "\n\t\tfrom t" + "\n\t)" + "\nselect n" + "\nfrom t" + "\nlimit 100", result);
}
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.assertEquals(1, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getTables().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSelectTest19 method test_0.
public void test_0() throws Exception {
String sql = "WITH t AS (" + " UPDATE products SET price = price * 1.05" + " RETURNING *" + ")" + "SELECT * FROM products;";
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(2, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getTables().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSelectTest2 method test_0.
public void test_0() throws Exception {
String sql = "SELECT * FROM t1 NATURAL INNER JOIN t2;";
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());
Assert.assertEquals(2, visitor.getTables().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSelectTest20 method test_0.
public void test_0() throws Exception {
String sql = "WITH t AS (" + " UPDATE products SET price = price * 1.05" + " RETURNING *" + ")" + "SELECT * FROM t;";
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(1, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getTables().size());
}
use of com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor in project druid by alibaba.
the class PGSelectTest21 method test_0.
public void test_0() throws Exception {
String sql = "SELECT DISTINCT(type) FROM dbmis2_databases";
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
// print(statementList);
Assert.assertEquals("SELECT DISTINCT type\nFROM dbmis2_databases", output(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(1, visitor.getColumns().size());
Assert.assertEquals(1, visitor.getTables().size());
}
Aggregations