[CalendarServer-changes] [8123] CalendarServer/trunk/twext/enterprise/dal
source_changes at macosforge.org
source_changes at macosforge.org
Mon Sep 26 22:54:33 PDT 2011
Revision: 8123
http://trac.macosforge.org/projects/calendarserver/changeset/8123
Author: glyph at apple.com
Date: 2011-09-26 22:54:33 -0700 (Mon, 26 Sep 2011)
Log Message:
-----------
empty string / NULL comparisons in Oracle
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-09-27 02:49:59 UTC (rev 8122)
+++ CalendarServer/trunk/twext/enterprise/dal/syntax.py 2011-09-27 05:54:33 UTC (rev 8123)
@@ -658,16 +658,22 @@
def subSQL(self, metadata, allTables):
+ if ( metadata.dialect == ORACLE_DIALECT
+ and isinstance(self.b, Constant) and self.b.value == ''
+ and self.op in ('=', '!=') ):
+ return NullComparison(self.a, self.op).subSQL(metadata, allTables)
stmt = SQLFragment()
result = self._subexpression(self.a, metadata, allTables)
- if isinstance(self.a, CompoundComparison) and self.a.op == 'or' and self.op == 'and':
+ if (isinstance(self.a, CompoundComparison)
+ and self.a.op == 'or' and self.op == 'and'):
result = _inParens(result)
stmt.append(result)
stmt.text += ' %s ' % (self.op,)
result = self._subexpression(self.b, metadata, allTables)
- if isinstance(self.b, CompoundComparison) and self.b.op == 'or' and self.op == 'and':
+ if (isinstance(self.b, CompoundComparison)
+ and self.b.op == 'or' and self.op == 'and'):
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 2011-09-27 02:49:59 UTC (rev 8122)
+++ CalendarServer/trunk/twext/enterprise/dal/test/test_sqlsyntax.py 2011-09-27 05:54:33 UTC (rev 8123)
@@ -164,6 +164,36 @@
"select * from FOO where BAR is not null", []))
+ def test_compareWithEmptyStringOracleSpecialCase(self):
+ """
+ Oracle considers the empty string to be a NULL value, so comparisons
+ with the empty string should be 'is NULL' comparisons.
+ """
+ # Sanity check: let's make sure that the non-oracle case looks normal.
+ self.assertEquals(Select(
+ From=self.schema.FOO,
+ Where=self.schema.FOO.BAR == '').toSQL(),
+ SQLFragment(
+ "select * from FOO where BAR = ?", [""]))
+ self.assertEquals(Select(
+ From=self.schema.FOO,
+ Where=self.schema.FOO.BAR != '').toSQL(),
+ SQLFragment(
+ "select * from FOO where BAR != ?", [""]))
+ self.assertEquals(Select(
+ From=self.schema.FOO,
+ Where=self.schema.FOO.BAR == ''
+ ).toSQL(NumericPlaceholder(ORACLE_DIALECT)),
+ SQLFragment(
+ "select * from FOO where BAR is null", []))
+ self.assertEquals(Select(
+ From=self.schema.FOO,
+ Where=self.schema.FOO.BAR != ''
+ ).toSQL(NumericPlaceholder(ORACLE_DIALECT)),
+ SQLFragment(
+ "select * from FOO where BAR is not null", []))
+
+
def test_compoundWhere(self):
"""
L{Select.And} and L{Select.Or} will return compound columns.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110926/7cd08930/attachment.html>
More information about the calendarserver-changes
mailing list