Skip to content

Commit 0fc0810

Browse files
author
David Erb
committed
removes all isolation level stuff
1 parent 9a76187 commit 0fc0810

File tree

1 file changed

+3
-85
lines changed

1 file changed

+3
-85
lines changed

src/dls_normsql/aiosqlite.py

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -71,66 +71,6 @@ def __init__(self, specification, database_definition_object):
7171
# Last undo position.
7272
self.__last_restore = 0
7373

74-
# ----------------------------------------------------------------------------------------
75-
async def __get_isolation_level(self):
76-
# Read the current isolation level
77-
cursor = await self.__connection.execute("PRAGMA isolation_level")
78-
result = await cursor.fetchone()
79-
80-
logger.debug(describe("result", result))
81-
82-
if result is None:
83-
isolation_level = ""
84-
else:
85-
isolation_level = result[0]
86-
87-
return isolation_level
88-
89-
# ----------------------------------------------------------------------------------------
90-
async def __set_isolation_level(self):
91-
"""
92-
Set the isolation level on the connection.
93-
94-
Set isolation level such that all statements which are not already in an explicit transaction
95-
are autocommitted immediately and visible on other connections.
96-
This might be less efficient? But it's nice when monitoring a sqlite file with a management tool.
97-
TODO: Consider the ramifications of setting aiosqlite isolation_level to None.
98-
"""
99-
100-
# Possible values are None, '' (default), DEFERRED, and EXCLUSIVE.
101-
# Default if not mentioned in the configuration is None.
102-
configured_isolation_level = self.__type_specific_tbd.get("isolation_level", "")
103-
previous_isolation_level = await self.__get_isolation_level()
104-
105-
logger.debug(describe("previous_isolation_level", previous_isolation_level))
106-
107-
if configured_isolation_level == previous_isolation_level:
108-
logger.debug(
109-
f"isolation_level is already the configured '{configured_isolation_level}'"
110-
)
111-
else:
112-
logger.debug(
113-
f"isolation_level is needs to be set from '{previous_isolation_level}' to '{configured_isolation_level}'"
114-
)
115-
116-
if configured_isolation_level is None:
117-
await self.execute("PRAGMA isolation_level =")
118-
else:
119-
await self.execute(
120-
f"PRAGMA isolation_level = {configured_isolation_level}"
121-
)
122-
await self.commit()
123-
124-
readback_isolation_level = await self.__get_isolation_level()
125-
126-
if readback_isolation_level != configured_isolation_level:
127-
raise RuntimeError(
128-
f"readback isolation level '{readback_isolation_level}' does not match '{configured_isolation_level}' as was set"
129-
)
130-
logger.debug(
131-
f"isolation_level is now set from '{previous_isolation_level}' to '{readback_isolation_level}'"
132-
)
133-
13474
# ----------------------------------------------------------------------------------------
13575
async def connect(self, should_drop_database=False):
13676
"""
@@ -152,31 +92,6 @@ async def connect(self, should_drop_database=False):
15292
self.__connection = await aiosqlite.connect(self.__filename)
15393
self.__connection.row_factory = aiosqlite.Row
15494

155-
# Set isolation level such that all statements which are not already in an explicit transaction
156-
# are autocommitted immediately and visible on other connections.
157-
# This might be less efficient? But it's nice when monitoring a sqlite file with a management tool.
158-
# TODO: Consider the ramifications of setting aiosqlite isolation_level to None.
159-
# Possible values are None, '' (default), DEFERRED, and EXCLUSIVE.
160-
logger.debug(
161-
f"isolation_level was set to '{self.__connection.isolation_level}'"
162-
)
163-
isolation_level = self.__type_specific_tbd.get("isolation_level", None)
164-
# self.__connection.isolation_level = isolation_level
165-
logger.debug(
166-
f"isolation_level is now set to '{self.__connection.isolation_level}'"
167-
)
168-
169-
# rows = await self.query("PRAGMA journal_mode", why="query journal mode")
170-
# logger.debug(f"journal mode rows {json.dumps(rows)}")
171-
172-
# rows = await self.query("PRAGMA journal_mode=OFF", why="turn OFF journal mode")
173-
# logger.debug(f"journal mode OFF rows {json.dumps(rows)}")
174-
175-
# rows = await self.query("PRAGMA journal_mode", why="query journal mode")
176-
# logger.debug(f"journal mode rows {json.dumps(rows)}")
177-
178-
# rows = await self.query("SELECT * from mainTable", why="main table check")
179-
18095
await self.__connection.create_function("regexp", 2, sqlite_regexp_callback)
18196

18297
# Let the base class contribute its table definitions to the in-memory list.
@@ -262,6 +177,9 @@ async def apply_revision(self, revision):
262177
async def disconnect(self):
263178

264179
if self.__connection is not None:
180+
# Commit any uncommitted transactions.
181+
await self.commit()
182+
265183
logger.debug(f"[DISSHU] {callsign(self)} disconnecting")
266184
await self.__connection.close()
267185
self.__connection = None

0 commit comments

Comments
 (0)