self.use_labels = kwargs.pop('use_labels', False)
self.oid_column = selects[0].oid_column
for s in self.selects:
- s.order_by(None)
s.group_by(None)
+ s.order_by(None)
self.clauses = []
- order_by = kwargs.get('order_by', None)
- if order_by:
- self.order_by(*order_by)
group_by = kwargs.get('group_by', None)
if group_by:
self.group_by(*group_by)
+ order_by = kwargs.get('order_by', None)
+ if order_by:
+ self.order_by(*order_by)
def hash_key(self):
return "CompoundSelect(%s)" % string.join(
[util.hash_key(s) for s in self.selects] +
for f in from_obj:
self.append_from(f)
- if order_by:
- self.order_by(*order_by)
if group_by:
self.group_by(*group_by)
+ if order_by:
+ self.order_by(*order_by)
class CorrelatedVisitor(ClauseVisitor):
"""visits a clause, locates any Select clauses, and tells them that they should
table2.select(order_by = [table2.c.id, asc(table2.c.name)]),
"SELECT myothertable.otherid, myothertable.othername FROM myothertable ORDER BY myothertable.otherid, myothertable.othername ASC"
)
+ def testgroupby(self):
+ self.runtest(
+ select([table2.c.name, func.count(table2.c.id)], group_by = [table2.c.name]),
+ "SELECT myothertable.othername, count(myothertable.otherid) FROM myothertable GROUP BY myothertable.othername"
+ )
+ def testgroupby_and_orderby(self):
+ self.runtest(
+ select([table2.c.name, func.count(table2.c.id)], group_by = [table2.c.name], order_by = [table2.c.name]),
+ "SELECT myothertable.othername, count(myothertable.otherid) FROM myothertable GROUP BY myothertable.othername ORDER BY myothertable.othername"
+ )
def testalias(self):
# test the alias for a table. column names stay the same, table name "changes" to "foo".
self.runtest(