]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
some fixes to the MS-SQL aliasing so that result_map is properly populated
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Apr 2008 16:35:06 +0000 (16:35 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 2 Apr 2008 16:35:06 +0000 (16:35 +0000)
lib/sqlalchemy/databases/mssql.py
test/dialect/mssql.py

index 1c4a2c286e6a707d226d7cc99c2992aa8989fdf4..849d5850716be06645cde1e85f476015060a98cd 100644 (file)
@@ -938,13 +938,19 @@ class MSSQLCompiler(compiler.DefaultCompiler):
         kwargs['mssql_aliased'] = True
         return super(MSSQLCompiler, self).visit_alias(alias, **kwargs)
 
-    def visit_column(self, column, **kwargs):
+    def visit_column(self, column, result_map=None, **kwargs):
         if column.table is not None and not self.isupdate and not self.isdelete:
             # translate for schema-qualified table aliases
             t = self._schema_aliased_table(column.table)
             if t is not None:
-                return self.process(expression._corresponding_column_or_error(t, column))
-        return super(MSSQLCompiler, self).visit_column(column, **kwargs)
+                converted = expression._corresponding_column_or_error(t, column)
+
+                if result_map is not None:
+                    result_map[column.name.lower()] = (column.name, (column, ), column.type)
+                    
+                return super(MSSQLCompiler, self).visit_column(converted, result_map=None, **kwargs)
+                
+        return super(MSSQLCompiler, self).visit_column(column, result_map=result_map, **kwargs)
 
     def visit_binary(self, binary, **kwargs):
         """Move bind parameters to the right-hand side of an operator, where possible."""
index 2adbca6b8f92c6f769af27bca8b829cd250fb901..857aa2b5b8b836e64abecfc392c57d6085c5ec3a 100755 (executable)
@@ -52,7 +52,18 @@ class CompileTest(TestBase, AssertsCompiledSQL):
             schema = 'remote_owner'
         )
 
+        s = table4.select()
+        c = s.compile(dialect=self.__dialect__)
+        assert table4.c.rem_id in set(c.result_map['rem_id'][1])
+
+        s = table4.select(use_labels=True)
+        c = s.compile(dialect=self.__dialect__)
+        print c.result_map
+        assert table4.c.rem_id in set(c.result_map['remote_owner_remotetable_rem_id'][1])
+
         self.assert_compile(table4.select(), "SELECT remotetable_1.rem_id, remotetable_1.datatype_id, remotetable_1.value FROM remote_owner.remotetable AS remotetable_1")
+        
+        self.assert_compile(table4.select(use_labels=True), "SELECT remotetable_1.rem_id AS remote_owner_remotetable_rem_id, remotetable_1.datatype_id AS remote_owner_remotetable_datatype_id, remotetable_1.value AS remote_owner_remotetable_value FROM remote_owner.remotetable AS remotetable_1")
 
         self.assert_compile(table1.join(table4, table1.c.myid==table4.c.rem_id).select(), "SELECT mytable.myid, mytable.name, mytable.description, remotetable_1.rem_id, remotetable_1.datatype_id, remotetable_1.value FROM mytable JOIN remote_owner.remotetable AS remotetable_1 ON remotetable_1.rem_id = mytable.myid")