diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-10-04 11:32:20 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-10-04 11:32:20 -0400 |
commit | 562e37ee7eaab8b19a9f081d4b170b95fce4f619 (patch) | |
tree | 02a1429a1306973b185dbc4b975fa39b9f6824de /lib/sqlalchemy | |
parent | f0ea9e37f94bd39fa4f0785dbdcd0ee1759c4a11 (diff) | |
download | sqlalchemy-562e37ee7eaab8b19a9f081d4b170b95fce4f619.tar.gz |
Use schema_name() for SQL Server default schema
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
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 9db025df7..19558a2d6 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -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): |