use of com.alibaba.druid.sql.ast.statement.SQLSelectStatement in project druid by alibaba.
the class LargeOrTest method test_largeOr.
public void test_largeOr() throws Exception {
StringBuffer buf = new StringBuffer();
buf.append("SELECT 1 FROM T WHERE ID = ?");
for (int i = 0; i < 10000; ++i) {
buf.append(" OR ID = ?");
}
String sql = buf.toString();
OracleStatementParser parser = new OracleStatementParser(sql);
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
SQLSelectQueryBlock select = (SQLSelectQueryBlock) stmt.getSelect().getQuery();
SQLBinaryOpExpr where = (SQLBinaryOpExpr) select.getWhere();
SQLBinaryOpExpr last = (SQLBinaryOpExpr) where.getRight();
Assert.assertEquals(SQLBinaryOperator.Equality, last.getOperator());
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectStatement in project druid by alibaba.
the class OracleLiteralTest method test_oracle.
public void test_oracle() throws Exception {
String sql = "SELECT FROM_TZ(TIMESTAMP '2007-11-20 08:00:00', '3:00') FROM DUAL;";
String expect = "SELECT FROM_TZ(TIMESTAMP '2007-11-20 08:00:00', '3:00')\n" + "FROM DUAL;\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.ast.statement.SQLSelectStatement in project druid by alibaba.
the class OracleLiteralTest method test_date.
public void test_date() throws Exception {
String sql = "SELECT DATE '1998-12-25' FROM DUAL;";
String expect = "SELECT DATE '1998-12-25'\n" + "FROM DUAL;\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.ast.statement.SQLSelectStatement in project druid by alibaba.
the class OracleSubqueryFactoringTest method test_interval.
public void test_interval() throws Exception {
String sql = "WITH dept_costs AS (\n" + "SELECT department_name, SUM(salary) dept_total\n" + "FROM employees e, departments d\n" + "WHERE e.department_id = d.department_id\n" + "GROUP BY department_name), " + "avg_cost AS (SELECT SUM(dept_total)/COUNT(*) avg FROM dept_costs)\n" + "SELECT * FROM dept_costs WHERE dept_total > (SELECT avg FROM avg_cost) ORDER BY department_name;";
String expected = //
"WITH\n" + //
"\tdept_costs\n" + //
"\tAS\n" + //
"\t(\n" + //
"\t\tSELECT department_name, SUM(salary) AS dept_total\n" + //
"\t\tFROM employees e, departments d\n" + //
"\t\tWHERE e.department_id = d.department_id\n" + //
"\t\tGROUP BY department_name\n" + //
"\t), \n" + //
"\tavg_cost\n" + //
"\tAS\n" + //
"\t(\n" + //
"\t\tSELECT SUM(dept_total) / COUNT(*) AS avg\n" + //
"\t\tFROM dept_costs\n" + //
"\t)\n" + //
"SELECT *\n" + //
"FROM dept_costs\n" + //
"WHERE dept_total > (\n" + //
"\tSELECT avg\n" + //
"\tFROM avg_cost\n" + //
"\t)\n" + "ORDER BY department_name;\n";
OracleStatementParser parser = new OracleStatementParser(sql);
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
String text = TestUtils.outputOracle(stmt);
Assert.assertEquals(expected, text);
System.out.println(text);
}
use of com.alibaba.druid.sql.ast.statement.SQLSelectStatement in project druid by alibaba.
the class OracleSubqueryFactoringTest2 method test_interval.
public void test_interval() throws Exception {
String sql = "WITH org_chart (eid, emp_last, mgr_id, reportLevel, salary, job_id) AS\n" + "(\n" + "SELECT employee_id, last_name, manager_id, 0 reportLevel, salary, job_id\n" + "FROM employees\n" + "WHERE manager_id is null\n" + "UNION ALL\n" + "SELECT e.employee_id, e.last_name, e.manager_id, r.reportLevel+1 reportLevel, e.salary, e.job_id\n" + "FROM org_chart r, employees e\n" + "WHERE r.eid = e.manager_id\n" + ")\n" + "SEARCH DEPTH FIRST BY emp_last SET order1\n" + "CYCLE hire_date SET is_cycle TO 'Y' DEFAULT 'N'" + "SELECT lpad(' ',2*reportLevel)||emp_last emp_name, eid, mgr_id, salary, job_id\n" + "FROM org_chart\n" + "ORDER BY order1;\n";
String expected = "WITH\n" + "\torg_chart (eid, emp_last, mgr_id, reportLevel, salary, job_id)\n" + "\tAS\n" + "\t(\n" + "\t\tSELECT employee_id, last_name, manager_id, 0 AS reportLevel, salary\n" + "\t\t\t, job_id\n" + "\t\tFROM employees\n" + "\t\tWHERE manager_id IS NULL\n" + "\t\tUNION ALL\n" + "\t\tSELECT e.employee_id, e.last_name, e.manager_id, r.reportLevel + 1 AS reportLevel, e.salary\n" + "\t\t\t, e.job_id\n" + "\t\tFROM org_chart r, employees e\n" + "\t\tWHERE r.eid = e.manager_id\n" + "\t)\n" + "\tSEARCH DEPTH FIRST BY emp_last SET order1\n" + "\tCYCLE hire_date SET is_cycle TO 'Y' DEFAULT 'N'\n" + "SELECT lpad(' ', 2 * reportLevel) || emp_last AS emp_name, eid, mgr_id, salary, job_id\n" + "FROM org_chart\n" + "ORDER BY order1;\n";
OracleStatementParser parser = new OracleStatementParser(sql);
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
String text = TestUtils.outputOracle(stmt);
Assert.assertEquals(expected, text);
System.out.println(text);
}
Aggregations