ms-sql fails during reflection

Issue #901 resolved
Former user created an issue

sp_columns is called during reflection of tables... right now it's called with the schema prepended, like 'dbo.mytable'. this is incorrect syntax (on 2005 at least). i've attached a patch which lets it work.

HTH, --craig

Index: lib/sqlalchemy/databases/mssql.py
===================================================================
--- lib/sqlalchemy/databases/mssql.py   (revision 3933)
+++ lib/sqlalchemy/databases/mssql.py   (working copy)
@@ -605,7 +605,10 @@
             raise exceptions.NoSuchTableError(table.name)

         # We also run an sp_columns to check for identity columns:
-        cursor = connection.execute("sp_columns %s" % self.identifier_preparer.format_table(table))
+        cursor = connection.execute(
+            "sp_columns @table_name = '%s', @table_owner = '%s'"
+            % (table.name, current_schema))
+        
         ic = None
         while True:
             row = cursor.fetchone()

Comments (4)

  1. Log in to comment