use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class OracleListAggTest method test_0.
public void test_0() throws Exception {
String sql = //
"SELECT prod_id, LISTAGG(cust_first_name||' '||cust_last_name, '; ') \n" + //
" WITHIN GROUP (ORDER BY amount_sold DESC) cust_list\n" + //
"FROM sales, customers\n" + //
"WHERE sales.cust_id = customers.cust_id AND cust_gender = 'M' \n" + //
" AND cust_credit_limit = 15000 AND prod_id BETWEEN 15 AND 18 \n" + //
" AND channel_id = 2 AND time_id > '01-JAN-01'\n" + "GROUP BY prod_id;";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
Assert.assertEquals(//
"SELECT prod_id, LISTAGG(cust_first_name || ' ' || cust_last_name, '; ') WITHIN GROUP (ORDER BY amount_sold DESC) AS cust_list" + //
"\nFROM sales, customers" + //
"\nWHERE sales.cust_id = customers.cust_id" + //
"\n\tAND cust_gender = 'M'" + //
"\n\tAND cust_credit_limit = 15000" + //
"\n\tAND prod_id BETWEEN 15 AND 18" + //
"\n\tAND channel_id = 2" + //
"\n\tAND time_id > '01-JAN-01'" + //
"\nGROUP BY prod_id", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
Assert.assertEquals(2, visitor.getTables().size());
Assert.assertEquals(10, visitor.getColumns().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("sales")));
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("customers")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("sales", "cust_id")));
Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("customers", "cust_id")));
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class OracleFlashbackQueryTest2 method test_isEmpty.
public void test_isEmpty() throws Exception {
String sql = "SELECT salary FROM employees\n" + "VERSIONS BETWEEN TIMESTAMP SYSTIMESTAMP - INTERVAL '10' MINUTE AND SYSTIMESTAMP - INTERVAL '1' MINUTE\n" + "WHERE last_name = 'Chung';";
String expect = "SELECT salary\n" + "FROM employees\n" + "VERSIONS BETWEEN TIMESTAMP SYSTIMESTAMP - INTERVAL '10' MINUTE AND SYSTIMESTAMP - INTERVAL '1' MINUTE\n" + "WHERE last_name = 'Chung';\n";
OracleStatementParser parser = new OracleStatementParser(sql);
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
String text = TestUtils.outputOracle(stmt);
Assert.assertEquals(expect, text);
System.out.println(text);
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class OracleGrantTest method test_0.
public void test_0() throws Exception {
String sql = "grant all on p4p_pro";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement statemen = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
statemen.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(1, visitor.getTables().size());
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("p4p_pro")));
Assert.assertEquals(0, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("UNKNOWN", "location_id")));
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class OracleGrantTest_1 method test_0.
public void test_0() throws Exception {
String sql = "GRANT CREATE SESSION TO hr;";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
//
Assert.assertEquals(//
"GRANT CREATE SESSION TO hr", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(0, visitor.getTables().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("employees")));
Assert.assertEquals(0, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("UNKNOWN", "location_id")));
}
use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.
the class OracleGrantTest_3 method test_0.
public void test_0() throws Exception {
String sql = "GRANT INHERIT PRIVILEGES ON USER sh TO hr;";
OracleStatementParser parser = new OracleStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
SQLStatement stmt = statementList.get(0);
print(statementList);
Assert.assertEquals(1, statementList.size());
//
Assert.assertEquals(//
"GRANT INHERIT PRIVILEGES ON USER sh TO hr", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
stmt.accept(visitor);
System.out.println("Tables : " + visitor.getTables());
System.out.println("fields : " + visitor.getColumns());
System.out.println("coditions : " + visitor.getConditions());
System.out.println("relationships : " + visitor.getRelationships());
System.out.println("orderBy : " + visitor.getOrderByColumns());
Assert.assertEquals(0, visitor.getTables().size());
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("employees")));
Assert.assertEquals(0, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("UNKNOWN", "location_id")));
}
Aggregations