[rql2sql] properly compute scope for variable from temporary tables stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 26 May 2010 15:45:22 +0200
branchstable
changeset 5593 f6c55bec9326
parent 5592 41ad8ca3047e
child 5594 fe7d84363d23
child 5596 d66a5d98db5b
[rql2sql] properly compute scope for variable from temporary tables
server/sources/rql2sql.py
--- a/server/sources/rql2sql.py	Wed May 26 14:59:05 2010 +0200
+++ b/server/sources/rql2sql.py	Wed May 26 15:45:22 2010 +0200
@@ -1177,13 +1177,26 @@
             pass
         return ''
 
+    def _temp_table_scope(self, select, table):
+        scope = 9999
+        for var, sql in self._varmap.iteritems():
+            if table == sql.split('.', 1)[0]:
+                try:
+                    scope = min(scope, self._state.scopes[select.defined_vars[var].scope])
+                except KeyError:
+                    scope = 0 # XXX
+                if scope == 0:
+                    return 0
+        return 0
+
     def _var_info(self, var):
-        scope = self._state.scopes[var.scope]
         try:
             sql = self._varmap[var.name]
             tablealias = sql.split('.', 1)[0]
+            scope = self._temp_table_scope(var.stmt, tablealias)
             self.add_table(tablealias, scope=scope)
         except KeyError:
+            scope = self._state.scopes[var.scope]
             etype = self._state.solution[var.name]
             # XXX this check should be moved in rql.stcheck
             if self.schema.eschema(etype).final: