SQL Server port: temporary table handling stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Tue, 06 Apr 2010 19:42:37 +0200
branchstable
changeset 5168 1ab032df5ca3
parent 5167 529861a73ec8
child 5169 240e21b94a28
child 5205 8b48add93b7e
SQL Server port: temporary table handling Together with support from logilab.database, handle temp tables for SQLServer (which are denoted by a name starting with '#', just don't ask) Note updated dependency on logilab.database 1.0.2
debian/control
server/msplanner.py
server/querier.py
server/sources/native.py
--- a/debian/control	Tue Apr 06 19:27:47 2010 +0200
+++ b/debian/control	Tue Apr 06 19:42:37 2010 +0200
@@ -33,7 +33,7 @@
 Conflicts: cubicweb-multisources
 Replaces: cubicweb-multisources
 Provides: cubicweb-multisources
-Depends: ${python:Depends}, cubicweb-common (= ${source:Version}), cubicweb-ctl (= ${source:Version}), python-logilab-database, cubicweb-postgresql-support | cubicweb-mysql-support | python-pysqlite2
+Depends: ${python:Depends}, cubicweb-common (= ${source:Version}), cubicweb-ctl (= ${source:Version}), python-logilab-database (=> 1.0.2), cubicweb-postgresql-support | cubicweb-mysql-support | python-pysqlite2
 Recommends: pyro, cubicweb-documentation (= ${source:Version})
 Description: server part of the CubicWeb framework
  CubicWeb is a semantic web application framework.
--- a/server/msplanner.py	Tue Apr 06 19:27:47 2010 +0200
+++ b/server/msplanner.py	Tue Apr 06 19:42:37 2010 +0200
@@ -1042,7 +1042,7 @@
                      for select in subquery.query.children]
             for sppi in sppis:
                 if sppi.needsplit or sppi.part_sources != ppi.part_sources:
-                    temptable = 'T%s' % make_uid(id(subquery))
+                    temptable = plan.make_temp_table_name('T%s' % make_uid(id(subquery)))
                     sstep = self._union_plan(plan, sppis, temptable)[0]
                     break
             else:
@@ -1075,7 +1075,7 @@
                 inputmap = self._ppi_subqueries(ppi)
                 aggrstep = need_aggr_step(select, sources)
                 if aggrstep:
-                    atemptable = 'T%s' % make_uid(id(select))
+                    atemptable = plan.make_temp_table_name('T%s' % make_uid(id(select)))
                     sunion = Union()
                     sunion.append(select)
                     selected = select.selection[:]
@@ -1119,7 +1119,7 @@
         subinputmap = self._ppi_subqueries(ppi)
         stepdefs = ppi.part_steps()
         if need_aggr_step(select, ppi.part_sources, stepdefs):
-            atemptable = 'T%s' % make_uid(id(select))
+            atemptable = plan.make_temp_table_name('T%s' % make_uid(id(select)))
             selection = select.selection[:]
             select_group_sort(select)
         else:
@@ -1169,6 +1169,7 @@
                 else:
                     table = '_T%s%s' % (''.join(sorted(v._ms_table_key() for v in terms)),
                                         ''.join(sorted(str(i) for i in solindices)))
+                    table = plan.make_temp_table_name(table)
                     ppi.build_non_final_part(minrqlst, solindices, sources,
                                              insertedvars, table)
         # finally: join parts, deal with aggregat/group/sorts if necessary
--- a/server/querier.py	Tue Apr 06 19:27:47 2010 +0200
+++ b/server/querier.py	Tue Apr 06 19:42:37 2010 +0200
@@ -164,6 +164,13 @@
         finally:
             self.clean()
 
+    def make_temp_table_name(self, table):
+        """
+        return a temp table name according to db backend
+        """
+        return self.syssource.make_temp_table_name(table)
+
+
     def init_temp_table(self, table, selected, sol):
         """initialize sql schema and variable map for a temporary table which
         will be used to store result for the given rqlst
--- a/server/sources/native.py	Tue Apr 06 19:27:47 2010 +0200
+++ b/server/sources/native.py	Tue Apr 06 19:42:37 2010 +0200
@@ -669,6 +669,15 @@
             pass
         return None
 
+    def make_temp_table_name(self, table):
+        try: # XXX remove this once 
+            return self.dbhelper.temporary_table_name(table)
+        except AttributeError:
+            import warnings
+            warnings.warn('Please hg up logilab.database')
+            return table
+
+
     def temp_table_def(self, selected, sol, table):
         return make_schema(selected, sol, table, self.dbhelper.TYPE_MAPPING)