[CalendarServer-changes] [7648] CalendarServer/trunk/twext/enterprise/dal
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 22 13:52:09 PDT 2011
Revision: 7648
http://trac.macosforge.org/projects/calendarserver/changeset/7648
Author: cdaboo at apple.com
Date: 2011-06-22 13:52:09 -0700 (Wed, 22 Jun 2011)
Log Message:
-----------
Added "like" comparison operations.
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-06-22 19:56:35 UTC (rev 7647)
+++ CalendarServer/trunk/twext/enterprise/dal/syntax.py 2011-06-22 20:52:09 UTC (rev 7648)
@@ -298,7 +298,18 @@
return CompoundComparison(self, 'in', subselect)
+ def StartsWith(self, other):
+ return CompoundComparison(self, "like", CompoundComparison(Constant(other), '||', Constant('%')))
+
+ def EndsWith(self, other):
+ return CompoundComparison(self, "like", CompoundComparison(Constant('%'), '||', Constant(other)))
+
+
+ def Contains(self, other):
+ return CompoundComparison(self, "like", CompoundComparison(Constant('%'), '||', CompoundComparison(Constant(other), '||', Constant('%'))))
+
+
class FunctionInvocation(ExpressionSyntax):
def __init__(self, function, *args):
self.function = function
Modified: CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2011-06-22 19:56:35 UTC (rev 7647)
+++ CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2011-06-22 20:52:09 UTC (rev 7648)
@@ -461,6 +461,63 @@
"select character_length(MYTEXT) from TEXTUAL"))
+ def test_startswith(self):
+ """
+ Test for the string starts with comparison.
+ (Note that this should be updated to use different techniques
+ as necessary in different databases.)
+ """
+ self.assertEquals(
+ Select([
+ self.schema.TEXTUAL.MYTEXT],
+ From=self.schema.TEXTUAL,
+ Where=self.schema.TEXTUAL.MYTEXT.StartsWith("test"),
+ ).toSQL(),
+ SQLFragment(
+ "select MYTEXT from TEXTUAL where MYTEXT like (? || ?)",
+ ["test", "%"]
+ )
+ )
+
+
+ def test_endswith(self):
+ """
+ Test for the string starts with comparison.
+ (Note that this should be updated to use different techniques
+ as necessary in different databases.)
+ """
+ self.assertEquals(
+ Select([
+ self.schema.TEXTUAL.MYTEXT],
+ From=self.schema.TEXTUAL,
+ Where=self.schema.TEXTUAL.MYTEXT.EndsWith("test"),
+ ).toSQL(),
+ SQLFragment(
+ "select MYTEXT from TEXTUAL where MYTEXT like (? || ?)",
+ ["%", "test"]
+ )
+ )
+
+
+ def test_contains(self):
+ """
+ Test for the string starts with comparison.
+ (Note that this should be updated to use different techniques
+ as necessary in different databases.)
+ """
+ self.assertEquals(
+ Select([
+ self.schema.TEXTUAL.MYTEXT],
+ From=self.schema.TEXTUAL,
+ Where=self.schema.TEXTUAL.MYTEXT.Contains("test"),
+ ).toSQL(),
+ SQLFragment(
+ "select MYTEXT from TEXTUAL where MYTEXT like (? || (? || ?))",
+ ["%", "test", "%"]
+ )
+ )
+
+
def test_insert(self):
"""
L{Insert.toSQL} generates an 'insert' statement with all the relevant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110622/abef5dc7/attachment.html>
More information about the calendarserver-changes
mailing list