]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where aliasing of tables with "schema" would
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 20 Oct 2010 20:15:54 +0000 (16:15 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 20 Oct 2010 20:15:54 +0000 (16:15 -0400)
fail to compile properly.  [ticket:1943]

CHANGES
lib/sqlalchemy/dialects/mssql/base.py
test/dialect/test_mssql.py

diff --git a/CHANGES b/CHANGES
index 7f055ea7afebd0d7b2734ead709d6eeb3c5fe847..63761d6234baa48a8d437d38cbaefb6b3fcc7bba 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -197,6 +197,9 @@ CHANGES
 - mssql
    - Fixed reflection bug which did not properly handle
      reflection of unknown types.  [ticket:1946]
+    
+   - Fixed bug where aliasing of tables with "schema" would
+     fail to compile properly.  [ticket:1943]
      
 - informix
    - *Major* cleanup / modernization of the Informix 
index 52b51a0ffa8af51d53087636646a96d8cc762619..222737dbe2604df68ea562ca9a2c46873cbf3c64 100644 (file)
@@ -755,20 +755,20 @@ class MSSQLCompiler(compiler.SQLCompiler):
             return None
 
     def visit_table(self, table, mssql_aliased=False, **kwargs):
-        if mssql_aliased:
+        if mssql_aliased is table:
             return super(MSSQLCompiler, self).visit_table(table, **kwargs)
 
         # alias schema-qualified tables
         alias = self._schema_aliased_table(table)
         if alias is not None:
-            return self.process(alias, mssql_aliased=True, **kwargs)
+            return self.process(alias, mssql_aliased=table, **kwargs)
         else:
             return super(MSSQLCompiler, self).visit_table(table, **kwargs)
 
     def visit_alias(self, alias, **kwargs):
         # translate for schema-qualified table aliases
         self.tablealiases[alias.original] = alias
-        kwargs['mssql_aliased'] = True
+        kwargs['mssql_aliased'] = alias.original
         return super(MSSQLCompiler, self).visit_alias(alias, **kwargs)
 
     def visit_extract(self, extract, **kw):
index c6d8d3f28de2667506923aa18f7b0f77e26d68ac..e840f9c0c975b56595ffa1f187b196ea971f938b 100644 (file)
@@ -127,7 +127,6 @@ class CompileTest(TestBase, AssertsCompiledSQL):
 
         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(),
@@ -151,7 +150,20 @@ class CompileTest(TestBase, AssertsCompiledSQL):
                             'remotetable_1.value FROM mytable JOIN '
                             'remote_owner.remotetable AS remotetable_1 '
                             'ON remotetable_1.rem_id = mytable.myid')
-
+        
+        self.assert_compile(select([table4.c.rem_id,
+                table4.c.value]).apply_labels().union(select([table1.c.myid,
+                table1.c.description]).apply_labels()).alias().select(),
+                "SELECT anon_1.remote_owner_remotetable_rem_id, "
+                "anon_1.remote_owner_remotetable_value FROM "
+                "(SELECT remotetable_1.rem_id AS remote_owner_remotetable_rem_id, "
+                "remotetable_1.value AS remote_owner_remotetable_value "
+                "FROM remote_owner.remotetable AS remotetable_1 UNION "
+                "SELECT mytable.myid AS mytable_myid, mytable.description "
+                "AS mytable_description FROM mytable) AS anon_1"
+            )
+        
+        
     def test_delete_schema(self):
         metadata = MetaData()
         tbl = Table('test', metadata, Column('id', Integer,