summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-04-17 15:36:43 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-04-17 15:36:43 -0400
commit1fb4ad75a38ce84d0e7b170927025500b73b5519 (patch)
tree5534368ca97de8190150bfea9f0b7d9b925f9cfe
parent99ae0dc821a1a36a6d1a966f51843f6632fc4117 (diff)
downloadsqlalchemy-1fb4ad75a38ce84d0e7b170927025500b73b5519.tar.gz
- 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
-rw-r--r--doc/build/changelog/changelog_09.rst10
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py22
2 files changed, 18 insertions, 14 deletions
diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst
index 313e34193..a4d5b9b68 100644
--- a/doc/build/changelog/changelog_09.rst
+++ b/doc/build/changelog/changelog_09.rst
@@ -15,6 +15,16 @@
: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 522cb5ce3..9a8cddd98 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):