]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Correction of mssql schema reflection in reflectable. Still a problem since the assum...
authorMichael Trier <mtrier@gmail.com>
Sat, 11 Oct 2008 16:14:07 +0000 (16:14 +0000)
committerMichael Trier <mtrier@gmail.com>
Sat, 11 Oct 2008 16:14:07 +0000 (16:14 +0000)
lib/sqlalchemy/databases/mssql.py
test/sql/select.py

index 5f4f5a37426c7a29bd2c391ef61f50cf85134711..8bf8144cfe2a10b65d18463a3efa44c0748c3708 100644 (file)
@@ -545,7 +545,6 @@ class MSSQLDialect(default.DefaultDialect):
 
     def reflecttable(self, connection, table, include_columns):
         import sqlalchemy.databases.information_schema as ischema
-
         # Get base columns
         if table.schema is not None:
             current_schema = table.schema
@@ -669,7 +668,12 @@ class MSSQLDialect(default.DefaultDialect):
         fknm, scols, rcols = (None, [], [])
         for r in rows:
             scol, rschema, rtbl, rcol, rfknm, fkmatch, fkuprule, fkdelrule = r
-            schema.Table(rtbl, table.metadata, schema=rschema, autoload=True, autoload_with=connection)               
+            # 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:
+                schema.Table(rtbl, table.metadata, autoload=True, autoload_with=connection)
+            else:
+                schema.Table(rtbl, table.metadata, schema=rschema, autoload=True, autoload_with=connection)
             if rfknm != fknm:
                 if fknm:
                     table.append_constraint(schema.ForeignKeyConstraint(scols, [_gen_fkref(table, s, t, c) for s, t, c in rcols], fknm))
index 3b6964e7db2bac62811a64d854f8f3c54ea510fa..a1414da715085330ffa7977985a611bbd0e2ba5d 100644 (file)
@@ -1444,7 +1444,6 @@ class InlineDefaultTest(TestBase, AssertsCompiledSQL):
         self.assert_compile(t.update(inline=True, values={'col3':'foo'}), "UPDATE test SET col1=foo(:foo_1), col2=(SELECT coalesce(max(foo.id)) AS coalesce_1 FROM foo), col3=:col3")
 
 class SchemaTest(TestBase, AssertsCompiledSQL):
-    @testing.fails_on('mssql')
     def test_select(self):
         # these tests will fail with the MS-SQL compiler since it will alias schema-qualified tables
         self.assert_compile(table4.select(), "SELECT remote_owner.remotetable.rem_id, remote_owner.remotetable.datatype_id, remote_owner.remotetable.value FROM remote_owner.remotetable")