]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use schema_name() for SQL Server default schema
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Oct 2016 15:32:20 +0000 (11:32 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Oct 2016 15:32:20 +0000 (11:32 -0400)
Changed the query used to get "default schema name", from one that
queries the database principals table to using the
"schema_name()" function, as issues have been reported that the
former system was unavailable on the Azure Data Warehouse edition.
It is hoped that this will finally work across all SQL Server
versions and authentication styles.

Change-Id: Ic11bd4162c0d6a60432ae44876e86512703c1f81
Fixes: #3810
doc/build/changelog/changelog_10.rst
lib/sqlalchemy/dialects/mssql/base.py

index 0ea3633b7a1fe2e8a1a1d98e778516bd0fc34671..8fd6b1dca2a618f2ff201d245a7596bde0cf9bc2 100644 (file)
 .. changelog::
     :version: 1.0.16
 
+    .. change::
+        :tags: bug, mssql
+        :tickets: 3810
+        :versions: 1.1.0
+
+        Changed the query used to get "default schema name", from one that
+        queries the database principals table to using the
+        "schema_name()" function, as issues have been reported that the
+        former system was unavailable on the Azure Data Warehouse edition.
+        It is hoped that this will finally work across all SQL Server
+        versions and authentication styles.
+
     .. change::
         :tags: bug, mssql
         :tickets: 3814
index 9db025df788a507418547ee73a3fc80354bdf631..19558a2d6aa82f42858dbfef7e49474df61c33dd 100644 (file)
@@ -1730,17 +1730,13 @@ class MSDialect(default.DefaultDialect):
     def _get_default_schema_name(self, connection):
         if self.server_version_info < MS_2005_VERSION:
             return self.schema_name
-
-        query = sql.text("""
-            SELECT default_schema_name FROM
-            sys.database_principals
-            WHERE principal_id=database_principal_id()
-        """)
-        default_schema_name = connection.scalar(query)
-        if default_schema_name is not None:
-            return util.text_type(default_schema_name)
         else:
-            return self.schema_name
+            query = sql.text("SELECT schema_name()")
+            default_schema_name = connection.scalar(query)
+            if default_schema_name is not None:
+                return util.text_type(default_schema_name)
+            else:
+                return self.schema_name
 
     @_db_plus_owner
     def has_table(self, connection, tablename, dbname, owner, schema):