From: Mike Bayer Date: Wed, 20 Oct 2010 20:15:54 +0000 (-0400) Subject: - Fixed bug where aliasing of tables with "schema" would X-Git-Tag: rel_0_6_5~14^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db318240d12becdf183af869b5b863979c55b050;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug where aliasing of tables with "schema" would fail to compile properly. [ticket:1943] --- diff --git a/CHANGES b/CHANGES index 7f055ea7af..63761d6234 100644 --- 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 diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 52b51a0ffa..222737dbe2 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -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): diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index c6d8d3f28d..e840f9c0c9 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -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,