/** * Processes an AST node that describes a ORDER clause. * * @param node an AST node to process */ public void processOrderClause(AST node) { AST ast = node; do { addOrderBy(processNewAbstractValue(ast)); ast = ast.getNextSibling(); } while (ast != null); }
/** * Processes an AST node that describes a ORDER clause. * * @param node an AST node to process */ public void processOrderClause(AST node) { AST ast = node; do { addOrderBy(processNewAbstractValue(ast)); ast = ast.getNextSibling(); } while (ast != null); }
public void testOrderByTwoFields() throws Exception { q1 = new Query("select table1.field1 from table1 order by table1.field1, table1.field2"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); Field f2 = new Field("field2", t1); SelectValue sv1 = new SelectValue(f1, null); q2.addSelect(sv1); q2.addFrom(t1); q2.addOrderBy(f1); q2.addOrderBy(f2); assertEquals(q2, q1); }
public void testOrderByAlias() throws Exception { // referring to an alias in the order by should sort by the field q1 = new Query("SELECT field1 AS alias1 FROM table1 ORDER BY alias1"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); SelectValue sv1 = new SelectValue(f1, "alias1"); q2.addSelect(sv1); q2.addFrom(t1); q2.addOrderBy(f1); assertEquals(q2, q1); }
public void testOrderByUnaliasedFieldSingleTable() throws Exception { // if a field (not an alias) appears in order by without a table name and there's only one // table then we can set a table name q1 = new Query("SELECT field1 FROM table1 ORDER BY field1"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); q2.addSelect(new SelectValue(f1, null)); q2.addFrom(t1); q2.addOrderBy(f1); assertEquals(q2, q1); }
public void testOrderBySingleField() throws Exception { q1 = new Query("select table1.field1 from table1 order by table1.field1"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); SelectValue sv1 = new SelectValue(f1, null); q2.addSelect(sv1); q2.addFrom(t1); q2.addOrderBy(f1); assertEquals(q2, q1); }
public void setUp() throws Exception { database = DatabaseFactory.getDatabase("db.unittest"); Query q1 = new Query(); Table t = new Table("tabletest"); Constant c = new Constant("50"); Field f1 = new Field("col1", t); Field f2 = new Field("col2", t); SelectValue sv1 = new SelectValue(f1, null); SelectValue sv2 = new SelectValue(f2, null); q1.addFrom(t); q1.addSelect(sv1); q1.addSelect(sv2); q1.addWhere(new Constraint(f1, Constraint.LT, c)); q1.addOrderBy(f1); Connection con = database.getConnection(); con.setAutoCommit(false); pt1 = new PrecomputedTable(q1, q1.getSQLString(), "precompA", "test", con); con.close(); }
public void testOrderByAliasedFunction() throws Exception { // count(*) in select is aliased, we are sorting by count(*) but referring to it by alias in order by q1 = new Query("SELECT field1 AS alias1, COUNT(*) as alias2 FROM table1 GROUP BY field1 ORDER BY alias2"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); Function func1 = new Function(Function.COUNT); SelectValue sv1 = new SelectValue(f1, "alias1"); SelectValue sv2 = new SelectValue(func1, "alias2"); q2.addSelect(sv1); q2.addSelect(sv2); q2.addFrom(t1); q2.addGroupBy(f1); q2.addOrderBy(func1); assertEquals(q2, q1); }
public void testOrderByFunction() throws Exception { q1 = new Query("select table1.field1 from table1 order by table1.field1 + table1.field2"); q2 = new Query(); Table t1 = new Table("table1"); Field f1 = new Field("field1", t1); Field f2 = new Field("field2", t1); Function func1 = new Function(Function.PLUS); func1.add(f1); func1.add(f2); SelectValue sv1 = new SelectValue(f1, null); q2.addSelect(sv1); q2.addFrom(t1); q2.addOrderBy(func1); assertEquals(q2, q1); }
q2.addOrderBy(t1f1); q2.addOrderBy(t2f1);