[CalendarServer-changes] [7119] CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 7 19:00:40 PST 2011


Revision: 7119
          http://trac.macosforge.org/projects/calendarserver/changeset/7119
Author:   glyph at apple.com
Date:     2011-03-07 19:00:40 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
support for SELECT DISTINCT (not DISTINCT ON yet though)

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.py

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py	2011-03-08 03:00:28 UTC (rev 7118)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/syntax.py	2011-03-08 03:00:40 UTC (rev 7119)
@@ -517,9 +517,10 @@
 
     def __init__(self, columns=None, Where=None, From=None, OrderBy=None,
                  GroupBy=None, Limit=None, ForUpdate=False, Ascending=None,
-                 Having=None):
+                 Having=None, Distinct=False):
         self.From = From
         self.Where = Where
+        self.Distinct = Distinct
         if not isinstance(OrderBy, (list, tuple, type(None))):
             OrderBy = [OrderBy]
         self.OrderBy = OrderBy
@@ -556,6 +557,8 @@
         @rtype: L{SQLFragment}
         """
         stmt = SQLFragment(quote("select "))
+        if self.Distinct:
+            stmt.text += "distinct "
         allTables = self.From.tables()
         stmt.append(self.columns.subSQL(placeholder, quote, allTables))
         stmt.text += quote(" from ")

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.py	2011-03-08 03:00:28 UTC (rev 7118)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/dal/test/test_sqlsyntax.py	2011-03-08 03:00:40 UTC (rev 7119)
@@ -654,6 +654,19 @@
         )
 
 
+    def test_distinct(self):
+        """
+        A L{Select} object with a 'Disinct' keyword parameter with a value of
+        C{True} will generate a SQL statement with a 'distinct' keyword
+        preceding its list of columns.
+        """
+        self.assertEquals(
+            Select([self.schema.FOO.BAR], From=self.schema.FOO,
+                   Distinct=True).toSQL(),
+            SQLFragment("select distinct BAR from FOO")
+        )
+
+
     def test_nextSequenceValue(self):
         """
         When a sequence is used as a value in an expression, it renders as the
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/b267e600/attachment-0001.html>


More information about the calendarserver-changes mailing list