Enhance transaction
This commit is contained in:
@@ -16,6 +16,9 @@ def _remove_transaction(name: str) -> None:
|
|||||||
|
|
||||||
def _remove_operation(name: str, id: int) -> None:
|
def _remove_operation(name: str, id: int) -> None:
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
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}")
|
cur.execute(f"delete from operation where id = {id}")
|
||||||
return int(cur.fetchone()['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
|
if bool(tran['strict']): # strict mode disallow undo
|
||||||
print("Do not allow to undo in strict transaction mode!")
|
print("Do not allow to undo in strict transaction mode!")
|
||||||
return
|
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!")
|
print("Do not allow to undo transaction start point!")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -175,7 +178,8 @@ def pick_snapshot(name: str, tag: str) -> None:
|
|||||||
execute_redo(name)
|
execute_redo(name)
|
||||||
|
|
||||||
# transaction is volatile, commit/rollback will destroy transaction.
|
# 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
|
# it may remove snapshot tag if snapshot in a rollback transaction
|
||||||
|
|
||||||
def have_transaction(name: str) -> bool:
|
def have_transaction(name: str) -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user