From: Mike Bayer Date: Thu, 17 Apr 2014 19:36:43 +0000 (-0400) Subject: - Revised the query used to determine the current default schema name X-Git-Tag: rel_0_9_5~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fb4ad75a38ce84d0e7b170927025500b73b5519;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Revised the query used to determine the current default schema name to use the ``database_principal_id()`` function in conjunction with the ``sys.database_principals`` view so that we can determine the default schema independently of the type of login in progress (e.g., SQL Server, Windows, etc). fixes #3025 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 313e341939..a4d5b9b68a 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,16 @@ .. changelog:: :version: 0.9.5 + .. change:: + :tags: bug, mssql + :tickets: 3025 + + Revised the query used to determine the current default schema name + to use the ``database_principal_id()`` function in conjunction with + the ``sys.database_principals`` view so that we can determine + the default schema independently of the type of login in progress + (e.g., SQL Server, Windows, etc). + .. change:: :tags: bug, sql :tickets: 3024 diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 522cb5ce36..9a8cddd988 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1216,22 +1216,16 @@ class MSDialect(default.DefaultDialect): self.implicit_returning = True def _get_default_schema_name(self, connection): - user_name = connection.scalar("SELECT user_name()") - if user_name is not None: - # now, get the default schema - query = sql.text(""" + query = sql.text(""" SELECT default_schema_name FROM sys.database_principals - WHERE name = :name - AND type = 'S' - """) - try: - default_schema_name = connection.scalar(query, name=user_name) - if default_schema_name is not None: - return util.text_type(default_schema_name) - except: - pass - return self.schema_name + 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 @_db_plus_owner def has_table(self, connection, tablename, dbname, owner, schema):