From: Michael Trier Date: Sun, 9 Nov 2008 01:27:25 +0000 (+0000) Subject: Corrected problems with reflection on mssql when dealing with schemas. Fixes #1217. X-Git-Tag: rel_0_5rc4~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8c308f34974befb02351d1788298c9b24f8265c;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Corrected problems with reflection on mssql when dealing with schemas. Fixes #1217. --- diff --git a/CHANGES b/CHANGES index 2b7095f285..512e9bdd92 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,10 @@ CHANGES - Fixed E Notation issue that prevented the ability to insert decimal values less than 1E-6. [ticket:1216] + - Corrected problems with reflection when dealing with + schemas, particularly when those schemas are the + default schema. [ticket:1217] + 0.5.0rc3 ======== - features diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 73c9137883..0ccad76ffa 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -682,10 +682,10 @@ class MSSQLDialect(default.DefaultDialect): rows = connection.execute(s).fetchall() def _gen_fkref(table, rschema, rtbl, rcol): - if table.schema and rschema != table.schema or rschema != current_schema: - return '.'.join([rschema, rtbl, rcol]) - else: + if rschema == current_schema and not table.schema: return '.'.join([rtbl, rcol]) + else: + return '.'.join([rschema, rtbl, rcol]) # group rows by constraint ID, to handle multi-column FKs fknm, scols, rcols = (None, [], []) @@ -693,7 +693,7 @@ class MSSQLDialect(default.DefaultDialect): scol, rschema, rtbl, rcol, rfknm, fkmatch, fkuprule, fkdelrule = r # if the reflected schema is the default schema then don't set it because this will # play into the metadata key causing duplicates. - if rschema == current_schema: + if rschema == current_schema and not table.schema: schema.Table(rtbl, table.metadata, autoload=True, autoload_with=connection) else: schema.Table(rtbl, table.metadata, schema=rschema, autoload=True, autoload_with=connection) diff --git a/test/engine/reflection.py b/test/engine/reflection.py index 7963cc0e4a..e478e7c7a6 100644 --- a/test/engine/reflection.py +++ b/test/engine/reflection.py @@ -677,7 +677,7 @@ class SchemaTest(TestBase): @testing.crashes('firebird', 'No schema support') @testing.fails_on('sqlite') # fixme: revisit these below. - @testing.fails_on('access', 'mssql', 'sybase') + @testing.fails_on('access', 'sybase') def test_explicit_default_schema(self): engine = testing.db