[CalendarServer-changes] [9857] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Sep 25 17:12:48 PDT 2012
Revision: 9857
http://trac.calendarserver.org//changeset/9857
Author: glyph at apple.com
Date: 2012-09-25 17:12:48 -0700 (Tue, 25 Sep 2012)
Log Message:
-----------
Double-parens for expression lists on the right hand side of equality conditions.
Modified Paths:
--------------
CalendarServer/trunk/twext/enterprise/dal/syntax.py
CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
Property Changed:
----------------
CalendarServer/trunk/
Modified: CalendarServer/trunk/twext/enterprise/dal/syntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/syntax.py 2012-09-25 22:00:33 UTC (rev 9856)
+++ CalendarServer/trunk/twext/enterprise/dal/syntax.py 2012-09-26 00:12:48 UTC (rev 9857)
@@ -313,10 +313,18 @@
class ExpressionSyntax(Syntax):
__eq__ = comparison('=')
__ne__ = comparison('!=')
+
+ # NB: these operators "cannot be used with lists" (see ORA-01796)
__gt__ = comparison('>')
__ge__ = comparison('>=')
__lt__ = comparison('<')
__le__ = comparison('<=')
+
+ # TODO: operators aren't really comparisons; these should behave slightly
+ # differently. (For example; in Oracle, 'select 3 = 4 from dual' doesn't
+ # work, but 'select 3 + 4 from dual' does; similarly, you can't do 'select *
+ # from foo where 3 + 4', but you can do 'select * from foo where 3 + 4 >
+ # 0'.)
__add__ = comparison("+")
__sub__ = comparison("-")
__div__= comparison("/")
@@ -907,6 +915,12 @@
if (isinstance(self.b, CompoundComparison)
and self.b.op == 'or' and self.op == 'and'):
result = _inParens(result)
+ if isinstance(self.b, Tuple):
+ # If the right-hand side of the comparison is a Tuple, it needs to
+ # be double-parenthesized in Oracle, as per
+ # http://docs.oracle.com/cd/B28359_01/server.111/b28286/expressions015.htm#i1033664
+ # because it is an expression list.
+ result = _inParens(result)
stmt.append(result)
return stmt
Modified: CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py
===================================================================
--- CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2012-09-25 22:00:33 UTC (rev 9856)
+++ CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2012-09-26 00:12:48 UTC (rev 9857)
@@ -38,6 +38,7 @@
from twisted.internet.defer import succeed
from twisted.trial.unittest import TestCase
from twext.enterprise.dal.syntax import Tuple
+from twext.enterprise.dal.syntax import Constant
@@ -1595,6 +1596,23 @@
)
+ def test_tupleOfConstantsComparison(self):
+ """
+ For some reason Oracle requires multiple parentheses for comparisons.
+ """
+ self.assertEquals(
+ Select(
+ [self.schema.FOO.BAR],
+ From=self.schema.FOO,
+ Where=(Tuple([self.schema.FOO.BAR, self.schema.FOO.BAZ]) ==
+ Tuple([Constant(7), Constant(9)]))
+ ).toSQL(),
+ SQLFragment(
+ "select BAR from FOO where (BAR, BAZ) = ((?, ?))", [7, 9]
+ )
+ )
+
+
def test_oracleTableTruncation(self):
"""
L{Table}'s SQL generation logic will truncate table names if the dialect
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120925/a2a617ad/attachment-0001.html>
More information about the calendarserver-changes
mailing list