begin_work
(),
commit_work
() and
rollback_work
()book ok; conn->begin_work(); // ... ok=false; conn->begin_work(); // ... ok=true; // ... if (ok) conn->commit_work(); else conn->rollback__work(); // ... if (ok) conn->commit_work(); else conn->rollback_work();
begin_work
(),
commit_work
() and
rollback_work
()
requires a modern database driver that implements modern
SAVEPOINT SQL
that allows for nested logical
transactions.
Without save point support the only options are
autocommit
(),
commit
(), and
rollback
().
begin_work
()
opens a logical transaction until it's closed by
commit_work
() or
rollback_work
().
While a transaction is open, invoking
begin_work
()
again opens a nested transaction.
The next call to
commit_work
() or
rollback_work
()
closes the nested transaction.
The nested transaction's changes get either commited to the original
transaction, or undone, leaving the original transaction in its state
prior to the nested transaction's start.
The original transaction remains open until its own matching
commit_work
() or
rollback_work
().
The first commit_work
() is equivalent to
autocommit(false);
, and the final
commit_work
() is equivalent to
commit
() followed by
autocommit(true)
.
Nested transactions get implemented using SQL savepoints. The limit on
the maximum number of nested transactions depends on the database
driver-specific limit on the maximum number of savepoints within a
transaction.