[rql2sql] should not select a neged relation as principal + simplify code for sql generation for attribute relation stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Sun, 06 Feb 2011 11:33:04 +0100
branchstable
changeset 6940 1172c25655b7
parent 6939 8fa55cf2a8cb
child 6947 3d72028a6cd4
[rql2sql] should not select a neged relation as principal + simplify code for sql generation for attribute relation
server/rqlannotation.py
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- a/server/rqlannotation.py	Fri Feb 04 10:02:48 2011 +0100
+++ b/server/rqlannotation.py	Sun Feb 06 11:33:04 2011 +0100
@@ -195,7 +195,7 @@
     for rel in sorted(relations, key=lambda x: (x.children[0].name, x.r_type)):
         # only equality relation with a variable as rhs may be principal
         if rel.operator() not in ('=', 'IS') \
-               or not isinstance(rel.children[1].children[0], VariableRef):
+               or not isinstance(rel.children[1].children[0], VariableRef) or rel.neged(strict=True):
             continue
         if rel.scope is rel.stmt:
             return rel
--- a/server/sources/rql2sql.py	Fri Feb 04 10:02:48 2011 +0100
+++ b/server/sources/rql2sql.py	Sun Feb 06 11:33:04 2011 +0100
@@ -991,24 +991,21 @@
         unification (eg X attr1 A, Y attr2 A). In case of selection,
         nothing to do here.
         """
-        contextrels = {}
         for var in rhs_vars:
             if var.name in self._varmap:
                 # ensure table is added
                 self._var_info(var.variable)
             principal = var.variable.stinfo.get('principal')
             if principal is not None and principal is not relation:
-                contextrels[var.name] = relation
-        if not contextrels:
-            return ''
-        # we have to generate unification expression
-        lhssql = self._inlined_var_sql(relation.children[0].variable,
-                                       relation.r_type)
-        try:
-            self._state.ignore_varmap = True
-            return '%s%s' % (lhssql, relation.children[1].accept(self))
-        finally:
-            self._state.ignore_varmap = False
+                # we have to generate unification expression
+                lhssql = self._inlined_var_sql(relation.children[0].variable,
+                                               relation.r_type)
+                try:
+                    self._state.ignore_varmap = True
+                    return '%s%s' % (lhssql, relation.children[1].accept(self))
+                finally:
+                    self._state.ignore_varmap = False
+        return ''
 
     def _visit_attribute_relation(self, rel):
         """generate SQL for an attribute relation"""
--- a/server/test/unittest_rql2sql.py	Fri Feb 04 10:02:48 2011 +0100
+++ b/server/test/unittest_rql2sql.py	Sun Feb 06 11:33:04 2011 +0100
@@ -180,6 +180,10 @@
 FROM cw_Personne AS _X
 WHERE _X.cw_prenom=lulu AND NOT (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0, in_group_relation AS rel_in_group1, cw_CWGroup AS _G WHERE rel_owned_by0.eid_from=_X.cw_eid AND rel_in_group1.eid_from=rel_owned_by0.eid_to AND rel_in_group1.eid_to=_G.cw_eid AND ((_G.cw_name=lulufanclub) OR (_G.cw_name=managers))))'''),
 
+    ('Any X WHERE  X title V, NOT X wikiid V, NOT X title "parent", X is Card',
+     '''SELECT _X.cw_eid
+FROM cw_Card AS _X
+WHERE NOT (_X.cw_wikiid=_X.cw_title) AND NOT (_X.cw_title=parent)''')
 ]