Enhance transaction

This commit is contained in:
wqy
2022-09-03 09:52:08 +08:00
parent 5f3db14067
commit bf188494f5

View File

@@ -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: