[rql2sql] fix special 'X relation NULL' case (used by security insertion), broken by recent removal of IS operator in RQL stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 10 Jun 2010 10:15:26 +0200
branchstable
changeset 5706 c2e8290bc7b7
parent 5704 924ea48326c4
child 5707 3586d36d2a45
child 5709 5606c01d68b2
[rql2sql] fix special 'X relation NULL' case (used by security insertion), broken by recent removal of IS operator in RQL
server/sources/rql2sql.py
--- a/server/sources/rql2sql.py	Wed Jun 09 14:51:00 2010 +0200
+++ b/server/sources/rql2sql.py	Thu Jun 10 10:15:26 2010 +0200
@@ -742,29 +742,29 @@
                 else:
                     # no variables in the RHS
                     sql = self._visit_attribute_relation(relation)
+        elif (rtype == 'is' and isinstance(rhs.children[0], Constant)
+              and rhs.children[0].eval(self._args) is None):
+            # special case "C is NULL"
+            if lhs.name in self._varmap:
+                lhssql = self._varmap[lhs.name]
+            else:
+                lhssql = lhs.accept(self)
+            return '%s%s' % (lhssql, rhs.accept(self))
+        elif '%s.%s' % (lhs, relation.r_type) in self._varmap:
+            # relation has already been processed by a previous step
+            return ''
+        elif relation.optional:
+            # check it has not already been treaten (to get necessary
+            # information to add an outer join condition)
+            if relation in self._state.done:
+                return ''
+            # OPTIONAL relation, generate a left|right outer join
+            sql = self._visit_outer_join_relation(relation, rschema)
+        elif rschema.inlined:
+            sql = self._visit_inlined_relation(relation)
         else:
-            if rtype == 'is' and rhs.operator == 'IS':
-                # special case "C is NULL"
-                if lhs.name in self._varmap:
-                    lhssql = self._varmap[lhs.name]
-                else:
-                    lhssql = lhs.accept(self)
-                return '%s%s' % (lhssql, rhs.accept(self))
-            if '%s.%s' % (lhs, relation.r_type) in self._varmap:
-                # relation has already been processed by a previous step
-                return
-            if relation.optional:
-                # check it has not already been treaten (to get necessary
-                # information to add an outer join condition)
-                if relation in self._state.done:
-                    return
-                # OPTIONAL relation, generate a left|right outer join
-                sql = self._visit_outer_join_relation(relation, rschema)
-            elif rschema.inlined:
-                sql = self._visit_inlined_relation(relation)
-            else:
-                # regular (non final) relation
-                sql = self._visit_relation(relation, rschema)
+            # regular (non final) relation
+            sql = self._visit_relation(relation, rschema)
         return sql
 
     def _visit_inlined_relation(self, relation):