1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
1282 return '' |
1282 return '' |
1283 |
1283 |
1284 def _visit_var_attr_relation(self, relation, rhs_vars): |
1284 def _visit_var_attr_relation(self, relation, rhs_vars): |
1285 """visit an attribute relation with variable(s) in the RHS |
1285 """visit an attribute relation with variable(s) in the RHS |
1286 |
1286 |
1287 attribute variables are used either in the selection or for |
1287 attribute variables are used either in the selection or for unification |
1288 unification (eg X attr1 A, Y attr2 A). In case of selection, |
1288 (eg X attr1 A, Y attr2 A). In case of selection, nothing to do here. |
1289 nothing to do here. |
|
1290 """ |
1289 """ |
|
1290 ored = relation.ored() |
1291 for vref in rhs_vars: |
1291 for vref in rhs_vars: |
1292 var = vref.variable |
1292 var = vref.variable |
1293 if var.name in self._varmap: |
1293 if var.name in self._varmap: |
1294 # ensure table is added |
1294 # ensure table is added |
1295 self._var_info(var) |
1295 self._var_info(var) |
1296 if isinstance(var, ColumnAlias): |
1296 if isinstance(var, ColumnAlias): |
1297 # force sql generation whatever the computed principal |
1297 # force sql generation whatever the computed principal |
1298 principal = 1 |
1298 principal = 1 |
1299 else: |
1299 else: |
1300 principal = var.stinfo.get('principal') |
1300 principal = var.stinfo.get('principal') |
1301 if principal is not None and principal is not relation: |
1301 print relation, principal |
|
1302 # we've to return some sql if: |
|
1303 # 1. visited relation is ored |
|
1304 # 2. variable's principal is not this relation and not 1. |
|
1305 if ored or (principal is not None and principal is not relation |
|
1306 and not principal.ored()): |
1302 # we have to generate unification expression |
1307 # we have to generate unification expression |
1303 lhssql = self._inlined_var_sql(relation.children[0].variable, |
1308 if principal is relation: |
1304 relation.r_type) |
1309 # take care if ored case and principal is the relation to |
|
1310 # use the right relation in the unification term |
|
1311 _rel = [rel for rel in var.stinfo['rhsrelations'] |
|
1312 if not rel is principal][0] |
|
1313 else: |
|
1314 _rel = relation |
|
1315 lhssql = self._inlined_var_sql(_rel.children[0].variable, |
|
1316 _rel.r_type) |
1305 try: |
1317 try: |
1306 self._state.ignore_varmap = True |
1318 self._state.ignore_varmap = True |
1307 sql = lhssql + relation.children[1].accept(self) |
1319 sql = lhssql + relation.children[1].accept(self) |
1308 finally: |
1320 finally: |
1309 self._state.ignore_varmap = False |
1321 self._state.ignore_varmap = False |