From: Michael Trier Date: Sat, 11 Oct 2008 16:14:07 +0000 (+0000) Subject: Correction of mssql schema reflection in reflectable. Still a problem since the assum... X-Git-Tag: rel_0_5rc2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b3c39decc1b992bcb7c1bb7cad452dcea5991f20;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Correction of mssql schema reflection in reflectable. Still a problem since the assumed default is dbo, whereas it could be modified by the connection. Allows SchemaTest.test_select to pass now. --- diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 5f4f5a3742..8bf8144cfe 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -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)) diff --git a/test/sql/select.py b/test/sql/select.py index 3b6964e7db..a1414da715 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -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")