diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-09-02 23:21:14 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-09-02 23:21:14 +0000 |
| commit | 5a606a10f764050474f34bcf7cb96f291ec4cb05 (patch) | |
| tree | 0f28b9a1093f99e90e4d39630966f092785e728b /lib/sqlalchemy | |
| parent | 02dd6879aa574674cabf589cdac6ef47839f7127 (diff) | |
| parent | 645977088404da0ed6d72ae7638a7d23dcf1e8e7 (diff) | |
| download | sqlalchemy-5a606a10f764050474f34bcf7cb96f291ec4cb05.tar.gz | |
Merge "Fix Azure Synapse connection error" into main
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/base.py | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 94e082611..82a5bb6f7 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -3008,27 +3008,34 @@ class MSDialect(default.DefaultDialect): ) view_name = "sys.{}".format(row[0]) - cursor.execute( - """ - SELECT CASE transaction_isolation_level - WHEN 0 THEN NULL - WHEN 1 THEN 'READ UNCOMMITTED' - WHEN 2 THEN 'READ COMMITTED' - WHEN 3 THEN 'REPEATABLE READ' - WHEN 4 THEN 'SERIALIZABLE' - WHEN 5 THEN 'SNAPSHOT' END AS TRANSACTION_ISOLATION_LEVEL - FROM {} - where session_id = @@SPID - """.format( - view_name + + try: + cursor.execute( + """ + SELECT CASE transaction_isolation_level + WHEN 0 THEN NULL + WHEN 1 THEN 'READ UNCOMMITTED' + WHEN 2 THEN 'READ COMMITTED' + WHEN 3 THEN 'REPEATABLE READ' + WHEN 4 THEN 'SERIALIZABLE' + WHEN 5 THEN 'SNAPSHOT' END + AS TRANSACTION_ISOLATION_LEVEL + FROM {} + where session_id = @@SPID + """.format( + view_name + ) ) - ) - row = cursor.fetchone() - assert row is not None - val = row[0] + except self.dbapi.Error as err: + raise NotImplementedError( + "Can't fetch isolation level; encountered error {} when " + 'attempting to query the "{}" view.'.format(err, view_name) + ) from err + else: + row = cursor.fetchone() + return row[0].upper() finally: cursor.close() - return val.upper() def initialize(self, connection): super(MSDialect, self).initialize(connection) |
