Debian Codegraph @

docs/transaction.txt

raw
1 /*! \page transaction Handling Transactions
2
3 \ref cppdb::session class has \ref cppdb::session::begin() "begin()", \ref cppdb::session::commit() "commit()", \ref cppdb::session::rollback() "rollback()" member functions that allow you to handle transactions. However you are not expected to use them directly for RAII reasons.
4
5 There is a transaction scope guard \ref cppdb::transaction that allows to wrap transactions in exception safe way.
6 In the \ref cppdb::transaction::transaction(cppdb::session&) "transaction guard's constructor" you specify the SQL \ref cppdb::session "session" you want to
7 run transaction on and when operations is completed you call its \ref cppdb::transaction::commit() "commit()" function to complete
8 the transaction or \ref cppdb::transaction::rollback() "rollback()"
9
10 If the transaction wasn't either committed or rolled back, it would be automatically rolled back during stack unwind.
11
12 For example:
13
14 \code
15 cppdb::transaction guard(sql);
16 sql << "UPDATE accounts SET amount=amount+? WHERE user=?" << amount << receiver << cppdb::exec;
17 sql << "UPDATE accounts SET amount=amount-? WHERE user=?" << amount << sender << cppdb::exec;
18 guard.commit();
19 \endcode
20
21 This would execute a transaction in exception safe way.
22
23
24 */
25