--- a/server/sources/rql2sql.py Tue May 19 11:18:05 2009 +0200
+++ b/server/sources/rql2sql.py Tue May 19 13:08:51 2009 +0200
@@ -901,6 +901,7 @@
def visit_comparison(self, cmp, contextrels=None):
"""generate SQL for a comparaison"""
if len(cmp.children) == 2:
+ # XXX occurs ?
lhs, rhs = cmp.children
else:
lhs = None
@@ -911,6 +912,11 @@
operator = ' LIKE '
else:
operator = ' %s ' % operator
+ elif (operator == '=' and isinstance(rhs, Constant)
+ and rhs.eval(self._args) is None):
+ if lhs is None:
+ return ' IS NULL'
+ return '%s IS NULL' % lhs.accept(self, contextrels)
elif isinstance(rhs, Function) and rhs.name == 'IN':
assert operator == '='
operator = ' '
--- a/server/test/unittest_rql2sql.py Tue May 19 11:18:05 2009 +0200
+++ b/server/test/unittest_rql2sql.py Tue May 19 13:08:51 2009 +0200
@@ -1,3 +1,4 @@
+
"""unit tests for module cubicweb.server.sources.rql2sql"""
import sys
@@ -1211,6 +1212,14 @@
WHERE rel_in_group0.eid_from=T00.x AND rel_in_group0.eid_to=G.cw_eid''',
varmap={'X': 'T00.x', 'X.login': 'T00.l'})
+ def test_is_null_transform(self):
+ union = self._prepare('Any X WHERE X login %(login)s')
+ r, args = self.o.generate(union, {'login': None})
+ self.assertLinesEquals((r % args).strip(),
+ '''SELECT X.cw_eid
+FROM cw_CWUser AS X
+WHERE X.cw_login IS NULL''')
+
def test_parser_parse(self):
for t in self._parse(PARSER):
yield t