aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/proxy/state_impl/base.py')
-rw-r--r--src/hydrilla/proxy/state_impl/base.py38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/hydrilla/proxy/state_impl/base.py b/src/hydrilla/proxy/state_impl/base.py
index 78a50c0..788a93d 100644
--- a/src/hydrilla/proxy/state_impl/base.py
+++ b/src/hydrilla/proxy/state_impl/base.py
@@ -72,40 +72,38 @@ class HaketiloStateWithFields(state.HaketiloState):
lock: threading.RLock = dc.field(default_factory=threading.RLock)
@contextmanager
- def cursor(self, lock: bool = False, transaction: bool = False) \
+ def cursor(self, transaction: bool = False) \
-> t.Iterator[sqlite3.Cursor]:
"""...."""
start_transaction = transaction and not self.connection.in_transaction
- assert lock or not start_transaction
-
try:
- if lock:
- self.lock.acquire()
+ self.lock.acquire()
if self.current_cursor is not None:
yield self.current_cursor
return
- self.current_cursor = self.connection.cursor()
-
- if start_transaction:
- self.current_cursor.execute('BEGIN TRANSACTION;')
-
try:
- yield self.current_cursor
+ self.current_cursor = self.connection.cursor()
if start_transaction:
- self.current_cursor.execute('COMMIT TRANSACTION;')
- except:
- if start_transaction:
- self.current_cursor.execute('ROLLBACK TRANSACTION;')
- raise
+ self.current_cursor.execute('BEGIN TRANSACTION;')
+
+ try:
+ yield self.current_cursor
+
+ if start_transaction:
+ assert self.connection.in_transaction
+ self.current_cursor.execute('COMMIT TRANSACTION;')
+ except:
+ if start_transaction:
+ self.current_cursor.execute('ROLLBACK TRANSACTION;')
+ raise
+ finally:
+ self.current_cursor = None
finally:
- self.current_cursor = None
-
- if lock:
- self.lock.release()
+ self.lock.release()
def rebuild_structures(self, cursor: sqlite3.Cursor) -> None:
"""...."""