Warning, /sdk/codevis/thirdparty/soci/docs/transactions.md is written in an unsupported language. File is not indexed.
0001 # Transactions 0002 0003 The SOCI library provides the following members of the `session` class for transaction management: 0004 0005 * `void begin();` 0006 * `void commit();` 0007 * `void rollback();` 0008 0009 In addition to the above there is a RAII wrapper that allows to associate the transaction with the given scope of code: 0010 0011 ```cpp 0012 class transaction 0013 { 0014 public: 0015 explicit transaction(session & sql); 0016 0017 ~transaction(); 0018 0019 void commit(); 0020 void rollback(); 0021 0022 private: 0023 // ... 0024 }; 0025 ``` 0026 0027 The object of class `transaction` will roll back automatically when the object is destroyed 0028 (usually as a result of leaving the scope) *and* when the transaction was not explicitly committed before that. 0029 0030 A typical usage pattern for this class might be: 0031 0032 ```cpp 0033 { 0034 transaction tr(sql); 0035 0036 sql << "insert into ..."; 0037 sql << "more sql queries ..."; 0038 // ... 0039 0040 tr.commit(); 0041 } 0042 ``` 0043 0044 With the above pattern the transaction is committed only when the code successfully reaches the end of block. 0045 If some exception is thrown before that, the scope will be left without reaching the final statement and the transaction object will automatically roll back in its destructor.