diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-11 09:39:19 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-08-11 09:39:19 +0200 |
commit | 3f3ba519ae3c3346945928b21ab36f7238e5387e (patch) | |
tree | 2852ed975257ee375d185746a7b559d587668aee /src/hydrilla/proxy/state_impl/base.py | |
parent | 72fcc76cc75ccb7e180886170db01dae637e250e (diff) | |
download | haketilo-hydrilla-3f3ba519ae3c3346945928b21ab36f7238e5387e.tar.gz haketilo-hydrilla-3f3ba519ae3c3346945928b21ab36f7238e5387e.zip |
save computed payloads into sqlite db
Diffstat (limited to 'src/hydrilla/proxy/state_impl/base.py')
-rw-r--r-- | src/hydrilla/proxy/state_impl/base.py | 38 |
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: """....""" |