imported patch rql2sqlfix.diff stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 06 Jul 2010 09:42:13 +0200
branchstable
changeset 5898 5630bd8f98d9
parent 5889 014ea69e5200
child 5899 11cecbaeb731
imported patch rql2sqlfix.diff
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- a/server/sources/rql2sql.py	Mon Jul 05 17:56:02 2010 +0200
+++ b/server/sources/rql2sql.py	Tue Jul 06 09:42:13 2010 +0200
@@ -818,7 +818,7 @@
         assert lhsvar is not None
         if isinstance(relation.parent, Not) \
                and len(lhsvar.stinfo['relations']) > 1 \
-               and (rhsvar is None or rhsvar._q_invariant):
+               and (rhsvar is not None and rhsvar._q_invariant):
             self._state.done.add(relation.parent)
             return '%s IS NULL' % self._inlined_var_sql(lhsvar, relation.r_type)
         lhssql = self._inlined_var_sql(lhsvar, relation.r_type)
--- a/server/test/unittest_rql2sql.py	Mon Jul 05 17:56:02 2010 +0200
+++ b/server/test/unittest_rql2sql.py	Tue Jul 06 09:42:13 2010 +0200
@@ -1031,9 +1031,16 @@
 
     ('Any X WHERE NOT Y for_user X, X eid 123',
      '''SELECT 123
-WHERE NOT (EXISTS(SELECT 1 FROM cw_CWProperty AS _Y WHERE _Y.cw_for_user=123))
-'''),
+WHERE NOT (EXISTS(SELECT 1 FROM cw_CWProperty AS _Y WHERE _Y.cw_for_user=123))'''),
 
+    ('DISTINCT Any X WHERE X from_entity OET, NOT X from_entity NET, OET name "Image", NET eid 1',
+     '''SELECT DISTINCT _X.cw_eid
+FROM cw_CWAttribute AS _X, cw_CWEType AS _OET
+WHERE _X.cw_from_entity=_OET.cw_eid AND NOT (_X.cw_from_entity=1) AND _OET.cw_name=Image
+UNION
+SELECT DISTINCT _X.cw_eid
+FROM cw_CWEType AS _OET, cw_CWRelation AS _X
+WHERE _X.cw_from_entity=_OET.cw_eid AND NOT (_X.cw_from_entity=1) AND _OET.cw_name=Image'''),
     ]
 
 INTERSECT = [