9ec8eb952e
All checks were successful
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m11s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m22s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m27s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m29s
linux-x64-gcc / linux-gcc (push) Successful in 1m55s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 3m17s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (pull_request) Successful in 1m9s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (pull_request) Successful in 1m14s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (pull_request) Successful in 1m20s
linux-x64-gcc / linux-gcc (pull_request) Successful in 1m24s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 4m26s
linux-mips64-gcc / linux-gcc-mips64el (pull_request) Successful in 1m43s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (pull_request) Successful in 1m55s
linux-hisiv500-gcc / linux-gcc-hisiv500 (pull_request) Successful in 4m8s
45 lines
1004 B
Markdown
45 lines
1004 B
Markdown
# Transactions
|
|
|
|
Transactions are simple in sqlpp11. Assuming you have a connection called `db`,
|
|
you can start and commit a transaction just like this:
|
|
|
|
```C++
|
|
auto tx = start_transaction(db);
|
|
// do something
|
|
tx.commit();
|
|
```
|
|
|
|
If you need to rollback the transaction, you can call it's `rollback()` member,
|
|
for instance like this:
|
|
|
|
```C++
|
|
auto tx = start_transaction(db);
|
|
try
|
|
{
|
|
// do something
|
|
tx.commit();
|
|
}
|
|
catch (...)
|
|
{
|
|
tx.rollback();
|
|
}
|
|
```
|
|
|
|
In case you call neither `commit()` nor `rollback()` on a transaction before it
|
|
goes out of scope, it will call `rollback()` in its destructor. This automatic
|
|
rollback will be reported by the connection.
|
|
|
|
## More options
|
|
You can turn off reporting for automatic rollback in the destructor by passing
|
|
`sqlpp::quiet_auto_rollback`.
|
|
|
|
```C++
|
|
auto tx = start_transaction(db, sqlpp::quiet_auto_rollback);
|
|
```
|
|
|
|
You can also specify the isolation level for the transaction:
|
|
|
|
```C++
|
|
auto tx = start_transaction(db, ::sqlpp::isolation_level::repeatable_read);
|
|
```
|