[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 08 Jun 2011 15:11:45 +0200
branchstable
changeset 7472 9833c09460f1
parent 7468 c202aaf71489
child 7473 a164fdf3de5d
child 7475 a70456bbb4bd
[rql2sql] fix missing sql restriction w/ attribute restriction where value comes from a subquery
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- a/server/sources/rql2sql.py	Tue Jun 07 10:17:36 2011 +0200
+++ b/server/sources/rql2sql.py	Wed Jun 08 15:11:45 2011 +0200
@@ -1258,11 +1258,16 @@
         unification (eg X attr1 A, Y attr2 A). In case of selection,
         nothing to do here.
         """
-        for var in rhs_vars:
+        for vref in rhs_vars:
+            var = vref.variable
             if var.name in self._varmap:
                 # ensure table is added
-                self._var_info(var.variable)
-            principal = var.variable.stinfo.get('principal')
+                self._var_info(var)
+            if isinstance(var, ColumnAlias):
+                # force sql generation whatever the computed principal
+                principal = 1
+            else:
+                principal = var.stinfo.get('principal')
             if principal is not None and principal is not relation:
                 # we have to generate unification expression
                 lhssql = self._inlined_var_sql(relation.children[0].variable,
--- a/server/test/unittest_rql2sql.py	Tue Jun 07 10:17:36 2011 +0200
+++ b/server/test/unittest_rql2sql.py	Wed Jun 08 15:11:45 2011 +0200
@@ -1453,6 +1453,12 @@
 WHERE ((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_X.cw_eid AND rel_owned_by0.eid_to=1)) OR (((EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by2, cw_Affaire AS _D LEFT OUTER JOIN concerne_relation AS rel_concerne1 ON (rel_concerne1.eid_from=_D.cw_eid) LEFT OUTER JOIN cw_Note AS _B ON (rel_concerne1.eid_to=_B.cw_eid) WHERE rel_owned_by2.eid_from=_B.cw_eid AND rel_owned_by2.eid_to=1 AND _X.cw_eid=_D.cw_eid)) OR (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by4, cw_Affaire AS _F LEFT OUTER JOIN concerne_relation AS rel_concerne3 ON (rel_concerne3.eid_from=_F.cw_eid) LEFT OUTER JOIN cw_Societe AS _E ON (rel_concerne3.eid_to=_E.cw_eid) WHERE rel_owned_by4.eid_from=_E.cw_eid AND rel_owned_by4.eid_to=1 AND _X.cw_eid=_F.cw_eid))))))) AS _T0, cw_CWEType AS _ET, is_relation AS rel_is0
 WHERE rel_is0.eid_from=_T0.C0 AND rel_is0.eid_to=_ET.cw_eid
 GROUP BY _ET.cw_name'''),
+
+            ('Any A WHERE A ordernum O, A is CWAttribute WITH O BEING (Any MAX(O) WHERE A ordernum O, A is CWAttribute)',
+             '''SELECT _A.cw_eid
+FROM (SELECT MAX(_A.cw_ordernum) AS C0
+FROM cw_CWAttribute AS _A) AS _T0, cw_CWAttribute AS _A
+WHERE _A.cw_ordernum=_T0.C0'''),
             )):
             yield t