From bf188494f561590cdad7ed50fccb5d19fed78ad7 Mon Sep 17 00:00:00 2001 From: wqy Date: Sat, 3 Sep 2022 09:52:08 +0800 Subject: [PATCH] Enhance transaction --- api/operation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api/operation.py b/api/operation.py index 969362f..33c0446 100644 --- a/api/operation.py +++ b/api/operation.py @@ -16,6 +16,9 @@ def _remove_transaction(name: str) -> None: def _remove_operation(name: str, id: int) -> None: with conn[name].cursor(row_factory=dict_row) as cur: + # can not be >= since there is a tree ! + cur.execute(f"delete from transaction_operation where id = {id}") # this should not happen + cur.execute(f"delete from snapshot_operation where id = {id}") # this may happen cur.execute(f"delete from operation where id = {id}") return int(cur.fetchone()['id']) @@ -83,7 +86,7 @@ def execute_undo(name: str, discard: bool = False) -> None: if bool(tran['strict']): # strict mode disallow undo print("Do not allow to undo in strict transaction mode!") return - elif tran <= curr: # normal mode disallow undo start point + elif tran <= curr: # normal mode disallow undo start point, and there is foreign key constraint print("Do not allow to undo transaction start point!") return @@ -175,7 +178,8 @@ def pick_snapshot(name: str, tag: str) -> None: execute_redo(name) # transaction is volatile, commit/rollback will destroy transaction. -# can not undo a committed transaction or redo a rollback transaction. +# can not redo a rollback transaction. +# but can undo a committed transaction... inconsistent... # it may remove snapshot tag if snapshot in a rollback transaction def have_transaction(name: str) -> bool: