Skip to content

Commit 6a2c158

Browse files
committed
Merge branch 'azure-1.11' into azure-2.0
2 parents 55f853a + 041e85f commit 6a2c158

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ Dictionary. Current available keys are:
127127
``"SQL Server Native Client 11.0"``, ``"FreeTDS"`` etc).
128128
Default is ``"ODBC Driver 13 for SQL Server"``.
129129

130+
- isolation_level
131+
132+
String. Sets `transaction isolation level
133+
<https://docs.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql>`__
134+
for each database session. Valid values for this entry are
135+
``READ UNCOMMITTED``, ``READ COMMITTED``, ``REPEATABLE READ``,
136+
``SNAPSHOT``, and ``SERIALIZABLE``. Default is ``None`` which means
137+
no isolation levei is set to a database session and SQL Server default
138+
will be used.
139+
130140
- dsn
131141

132142
String. A named DSN can be used instead of ``HOST``.

sql_server/pyodbc/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,15 @@ def init_connection_state(self):
344344
settings_dict = self.settings_dict
345345
cursor = self.create_cursor()
346346

347+
options = settings_dict.get('OPTIONS', {})
348+
isolation_level = options.get('isolation_level', None)
349+
if isolation_level:
350+
cursor.execute('SET TRANSACTION ISOLATION LEVEL %s' % isolation_level)
351+
347352
# Set date format for the connection. Also, make sure Sunday is
348353
# considered the first day of the week (to be consistent with the
349354
# Django convention for the 'week_day' Django lookup) if the user
350355
# hasn't told us otherwise
351-
options = settings_dict.get('OPTIONS', {})
352356
datefirst = options.get('datefirst', 7)
353357
cursor.execute('SET DATEFORMAT ymd; SET DATEFIRST %s' % datefirst)
354358

0 commit comments

Comments
 (0)