C++DB is the database layer that was designed to work with C++CMS. This customized version is used within Ye Ol' Pi Shack.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

26 lines
1.2 KiB

  1. /*! \page transaction Handling Transactions
  2. \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.
  3. There is a transaction scope guard \ref cppdb::transaction that allows to wrap transactions in exception safe way.
  4. In the \ref cppdb::transaction::transaction(cppdb::session&) "transaction guard's constructor" you specify the SQL \ref cppdb::session "session" you want to
  5. run transaction on and when operations is completed you call its \ref cppdb::transaction::commit() "commit()" function to complete
  6. the transaction or \ref cppdb::transaction::rollback() "rollback()"
  7. If the transaction wasn't either committed or rolled back, it would be automatically rolled back during stack unwind.
  8. For example:
  9. \code
  10. cppdb::transaction guard(sql);
  11. sql << "UPDATE accounts SET amount=amount+? WHERE user=?" << amount << receiver << cppdb::exec;
  12. sql << "UPDATE accounts SET amount=amount-? WHERE user=?" << amount << sender << cppdb::exec;
  13. guard.commit();
  14. \endcode
  15. This would execute a transaction in exception safe way.
  16. */