# HG changeset patch # User Sylvain Thénault # Date 1317716145 -7200 # Node ID 2ada3052e626a11d27204de4a51d43874b8cce8d # Parent e9b79f5c35719b6ca60ef8f53330c77fccc9579b [rql2sql] support for outer join on column alias (closes #1979645) diff -r e9b79f5c3571 -r 2ada3052e626 server/sources/rql2sql.py --- a/server/sources/rql2sql.py Fri Sep 30 18:08:00 2011 +0200 +++ b/server/sources/rql2sql.py Tue Oct 04 10:15:45 2011 +0200 @@ -1426,10 +1426,18 @@ return sql leftvars = cmp.children[0].get_nodes(VariableRef) assert len(leftvars) == 1 - leftalias = self._var_table(leftvars[0].variable.stinfo['attrvar']) + if leftvars[0].variable.stinfo['attrvar'] is None: + assert isinstance(leftvars[0].variable, ColumnAlias) + leftalias = leftvars[0].variable._q_sqltable + else: + leftalias = self._var_table(leftvars[0].variable.stinfo['attrvar']) rightvars = cmp.children[1].get_nodes(VariableRef) assert len(rightvars) == 1 - rightalias = self._var_table(rightvars[0].variable.stinfo['attrvar']) + if rightvars[0].variable.stinfo['attrvar'] is None: + assert isinstance(rightvars[0].variable, ColumnAlias) + rightalias = rightvars[0].variable._q_sqltable + else: + rightalias = self._var_table(rightvars[0].variable.stinfo['attrvar']) if optional == 'right': self._state.replace_tables_by_outer_join( leftalias, rightalias, 'LEFT', sql) diff -r e9b79f5c3571 -r 2ada3052e626 server/test/unittest_rql2sql.py --- a/server/test/unittest_rql2sql.py Fri Sep 30 18:08:00 2011 +0200 +++ b/server/test/unittest_rql2sql.py Tue Oct 04 10:15:45 2011 +0200 @@ -1524,6 +1524,12 @@ 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'''), + + ('Any O1 HAVING O1=O2? WITH O1 BEING (Any MAX(O) WHERE A ordernum O, A is CWAttribute), O2 BEING (Any MAX(O) WHERE A ordernum O, A is CWRelation)', + '''SELECT _T0.C0 +FROM (SELECT MAX(_A.cw_ordernum) AS C0 +FROM cw_CWAttribute AS _A) AS _T0 LEFT OUTER JOIN (SELECT MAX(_A.cw_ordernum) AS C0 +FROM cw_CWRelation AS _A) AS _T1 ON (_T0.C0=_T1.C0)'''), )): yield t