[CalendarServer-changes] [6887] CalendarServer/trunk/twext/enterprise/dal

source_changes at macosforge.org source_changes at macosforge.org
Fri Feb 4 17:40:19 PST 2011


Revision: 6887
          http://trac.macosforge.org/projects/calendarserver/changeset/6887
Author:   glyph at apple.com
Date:     2011-02-04 17:40:19 -0800 (Fri, 04 Feb 2011)
Log Message:
-----------
tuple group-by/order-by

Modified Paths:
--------------
    CalendarServer/trunk/twext/enterprise/dal/syntax.py
    CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py

Modified: CalendarServer/trunk/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/syntax.py	2011-02-05 01:14:09 UTC (rev 6886)
+++ CalendarServer/trunk/twext/enterprise/dal/syntax.py	2011-02-05 01:40:19 UTC (rev 6887)
@@ -409,7 +409,11 @@
                  GroupBy=None, Limit=None):
         self.From = From
         self.Where = Where
+        if not isinstance(OrderBy, (list, tuple, type(None))):
+            OrderBy = [OrderBy]
         self.OrderBy = OrderBy
+        if not isinstance(GroupBy, (list, tuple, type(None))):
+            GroupBy = [GroupBy]
         self.GroupBy = GroupBy
         self.Limit = Limit
         if columns is None:
@@ -440,7 +444,14 @@
         for bywhat, expr in [('group', self.GroupBy), ('order', self.OrderBy)]:
             if expr is not None:
                 stmt.text += quote(" " + bywhat + " by ")
-                stmt.append(expr.subSQL(placeholder, quote, allTables))
+                fst = True
+                for subthing in expr:
+                    if fst:
+                        fst = False
+                    else:
+                        stmt.text += ', '
+                    stmt.append(subthing.subSQL(placeholder, quote, allTables))
+
         if self.Limit is not None:
             stmt.text += quote(" limit ")
             stmt.text += placeholder

Modified: CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py	2011-02-05 01:14:09 UTC (rev 6886)
+++ CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py	2011-02-05 01:40:19 UTC (rev 6887)
@@ -149,6 +149,18 @@
         )
 
 
+    def test_groupByMulti(self):
+        """
+        L{Select}'s L{GroupBy} parameter can accept multiple columns in a list.
+        """
+        self.assertEquals(
+            Select(From=self.schema.FOO,
+                   GroupBy=[self.schema.FOO.BAR,
+                            self.schema.FOO.BAZ]).toSQL(),
+            SQLFragment("select * from FOO group by BAR, BAZ")
+        )
+
+
     def test_joinClause(self):
         """
         A table's .join() method returns a join statement in a SELECT.
@@ -293,6 +305,21 @@
                           SQLFragment("select max(QUX) + ? from BOZ", [12]))
 
 
+    def test_multiColumnExpression(self):
+        """
+        Multiple columns may be provided in an expression in the 'columns'
+        portion of a Select() statement.  All arithmetic operators are
+        supported.
+        """
+        self.assertEquals(
+            Select([((self.schema.FOO.BAR + self.schema.FOO.BAZ) / 3) * 7],
+                   From=self.schema.FOO).toSQL(),
+            SQLFragment("select ((BAR + BAZ) / ?) * ? from FOO", [3, 7])
+        )
+
+    test_multiColumnExpression.todo = 'not implemented yet'
+
+
     def test_len(self):
         """
         Test for the 'Len' function for determining character length of a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110204/013aa486/attachment.html>


More information about the calendarserver-changes mailing list