8#ifndef BOOST_SQLITE_TRANSACTION_HPP
9#define BOOST_SQLITE_TRANSACTION_HPP
11#include <boost/sqlite/connection.hpp>
13BOOST_SQLITE_BEGIN_NAMESPACE
34 constexpr static struct adopt_transaction_t {} adopt_transaction{};
46 conn.execute(
"BEGIN");
55 case deferred: conn.execute(
"BEGIN DEFERRED");
break;
56 case immediate: conn.execute(
"BEGIN IMMEDIATE");
break;
57 case exclusive: conn.execute(
"BEGIN EXCLUSIVE");
break;
66 conn_.execute(
"ROLLBACK");
73 conn_.execute(
"COMMIT");
79 conn_.execute(
"COMMIT", ec, ei);
88 conn_.execute(
"ROLLBACK");
94 conn_.execute(
"ROLLBACK", ec, ei);
101 bool completed_ =
true;
121 constexpr static transaction::adopt_transaction_t adopt_transaction{};
124 savepoint(connection & conn, std::string name, transaction::adopt_transaction_t)
125 : conn_(conn), name_(std::move(name))
130 savepoint(connection & conn, std::string name) : conn_(conn), name_(std::move(name))
132 conn.execute(
"SAVEPOINT " + name_);
138 ~savepoint() noexcept(false)
141 conn_.execute(
"ROLLBACK TO " + name_);
148 conn_.execute(
"RELEASE " + name_);
152 void commit(system::error_code & ec,
error_info & ei)
154 conn_.execute(
"RELEASE " + name_, ec, ei);
160 conn_.execute(
"RELEASE " + name_);
164 void release(system::error_code & ec,
error_info & ei)
166 conn_.execute(
"RELEASE " + name_, ec, ei);
175 conn_.execute(
"ROLLBACK TO" + name_);
179 void rollback(system::error_code & ec,
error_info & ei)
181 conn_.execute(
"ROLLBACK TO " + name_, ec, ei);
187 const std::string & name()
const {
return name_;}
191 bool completed_ =
true;
195BOOST_SQLITE_END_NAMESPACE
main object for a connection to a database.
Additional information about error conditions stored in an sqlite-allocate string.
A simple transaction guard implementing RAAI for transactions.
transaction(connection &conn)
Create transaction guard and initiate a transaction.
transaction(connection &conn, behaviour b)
Create transaction guard and initiate a transaction with the defined behaviour.
void commit(system::error_code &ec, error_info &ei)
void rollback(system::error_code &ec, error_info &ei)
behaviour
The mode of the transaction.
transaction(connection &conn, adopt_transaction_t)
Create transaction guard on an existing transaction.
~transaction() noexcept(false)
rollback the transaction if not committed.