use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class MySqlSelectTest_102_orderBy method test_0.
public void test_0() throws Exception {
String sql = "\n" + "select a from a1 union select a from a2 union select a from a3 order by a desc;";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
assertEquals(1, statementList.size());
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
SQLUnionQuery union = (SQLUnionQuery) stmt.getSelect().getQuery();
assertNotNull(union.getOrderBy());
assertTrue(union.getLeft() instanceof SQLUnionQuery);
assertEquals("SELECT a\n" + "FROM a1\n" + "UNION\n" + "SELECT a\n" + "FROM a2\n" + "UNION\n" + "SELECT a\n" + "FROM a3\n" + "ORDER BY a DESC;", stmt.toString());
}
use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class MySqlSelectTest_104_union_orderBy method test_0.
public void test_0() throws Exception {
String sql = "\n" + "select a from a1 union select a from a2 union select a from a3 union select a from a4 union select a from a5 order by a desc";
MySqlStatementParser parser = new MySqlStatementParser(sql);
List<SQLStatement> statementList = parser.parseStatementList();
assertEquals(1, statementList.size());
SQLSelectStatement stmt = (SQLSelectStatement) statementList.get(0);
System.out.println(stmt);
SQLUnionQuery union = (SQLUnionQuery) stmt.getSelect().getQuery();
assertNotNull(union.getOrderBy());
assertTrue(union.getLeft() instanceof SQLUnionQuery);
assertFalse(union.getRight() instanceof SQLUnionQuery);
assertTrue(((SQLUnionQuery) union.getLeft()).getLeft() instanceof SQLUnionQuery);
assertFalse(((SQLUnionQuery) union.getLeft()).getRight() instanceof SQLUnionQuery);
assertEquals("SELECT a\n" + "FROM a1\n" + "UNION\n" + "SELECT a\n" + "FROM a2\n" + "UNION\n" + "SELECT a\n" + "FROM a3\n" + "UNION\n" + "SELECT a\n" + "FROM a4\n" + "UNION\n" + "SELECT a\n" + "FROM a5\n" + "ORDER BY a DESC", stmt.toString());
}
use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class MySqlSelectTest_233 method test_0.
public void test_0() throws Exception {
String sql = "select f1 \n" + "from t1\n" + "union all\n" + "select f2\n" + "from t2";
SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseSingleMysqlStatement(sql);
SQLUnionQuery query = (SQLUnionQuery) stmt.getSelect().getQuery();
SQLSelectQueryBlock left = (SQLSelectQueryBlock) query.getLeft();
left.addOrderBy(new SQLIdentifierExpr("f1"));
SQLSelectQueryBlock right = (SQLSelectQueryBlock) query.getRight();
right.addOrderBy(new SQLIdentifierExpr("f1"));
assertEquals("SELECT f1\n" + "FROM t1\n" + "ORDER BY f1\n" + "UNION ALL\n" + "(SELECT f2\n" + "FROM t2\n" + "ORDER BY f1)", stmt.toString());
}
use of com.alibaba.druid.sql.ast.statement.SQLUnionQuery in project druid by alibaba.
the class Issue2038 method test_for_demo.
public void test_for_demo() throws Exception {
String sql = "select * from (select * from t union all select * from t1 union all select * from t3) xx";
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, DbType.db2);
SQLASTVisitor visitor = new DB2ASTVisitorAdapter() {
public boolean visit(SQLUnionQuery x) {
System.out.println("union");
return true;
}
public boolean visit(DB2SelectQueryBlock x) {
System.out.println("select");
return true;
}
};
for (SQLStatement stmt : stmtList) {
stmt.accept(visitor);
}
}
Aggregations