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

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 16 07:02:26 PDT 2014


Revision: 13297
          http://trac.calendarserver.org//changeset/13297
Author:   cdaboo at apple.com
Date:     2014-04-16 07:02:26 -0700 (Wed, 16 Apr 2014)
Log Message:
-----------
Add SQL Coalesce function.

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

Modified: twext/trunk/twext/enterprise/dal/syntax.py
===================================================================
--- twext/trunk/twext/enterprise/dal/syntax.py	2014-04-16 13:57:57 UTC (rev 13296)
+++ twext/trunk/twext/enterprise/dal/syntax.py	2014-04-16 14:02:26 UTC (rev 13297)
@@ -604,6 +604,8 @@
 Len = Function("character_length", "length")
 Upper = Function("upper")
 Lower = Function("lower")
+Coalesce = Function("coalesce")
+
 _sqliteLastInsertRowID = Function("last_insert_rowid")
 
 # Use a specific value here for "the convention for case-insensitive values in

Modified: twext/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- twext/trunk/twext/enterprise/dal/test/test_sqlsyntax.py	2014-04-16 13:57:57 UTC (rev 13296)
+++ twext/trunk/twext/enterprise/dal/test/test_sqlsyntax.py	2014-04-16 14:02:26 UTC (rev 13297)
@@ -33,7 +33,7 @@
     Savepoint, RollbackToSavepoint, ReleaseSavepoint, SavepointAction,
     Union, Intersect, Except, SetExpression, DALError,
     ResultAliasSyntax, Count, QueryGenerator, ALL_COLUMNS,
-    DatabaseLock, DatabaseUnlock, Not)
+    DatabaseLock, DatabaseUnlock, Not, Coalesce)
 from twext.enterprise.dal.syntax import FixedPlaceholder, NumericPlaceholder
 from twext.enterprise.dal.syntax import Function
 from twext.enterprise.dal.syntax import SchemaSyntax
@@ -1030,6 +1030,21 @@
         )
 
 
+    def test_coalesce(self):
+        """
+        L{Coalesce}C{(column)} produces an object in the C{columns} clause that
+        renders the C{coalesce} conditional in SQL.
+        """
+        self.assertEquals(
+            Select(
+                [self.schema.BOZ.QUX],
+                From=self.schema.BOZ,
+                Where=Coalesce(self.schema.BOZ.QUX, self.schema.BOZ.QUUX) == 1
+            ).toSQL(),
+            SQLFragment("select QUX from BOZ where coalesce(QUX, QUUX) = ?", [1])
+        )
+
+
     def test_countAllCoumns(self):
         """
         L{Count}C{(ALL_COLUMNS)} produces an object in the C{columns} clause
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140416/6939c498/attachment.html>


More information about the calendarserver-changes mailing list