summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Trier <mtrier@gmail.com>2008-10-11 16:14:07 +0000
committerMichael Trier <mtrier@gmail.com>2008-10-11 16:14:07 +0000
commitb3c39decc1b992bcb7c1bb7cad452dcea5991f20 (patch)
tree80023d0e3017bb8f449bd5e62f3ac2441412403d
parent188a990e221c7a84c350886dd699ce3f01932b8c (diff)
downloadsqlalchemy-b3c39decc1b992bcb7c1bb7cad452dcea5991f20.tar.gz
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.
-rw-r--r--lib/sqlalchemy/databases/mssql.py8
-rw-r--r--test/sql/select.py1
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py
index 5f4f5a374..8bf8144cf 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 3b6964e7d..a1414da71 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")