diff options
author | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:16:10 -0400 |
---|---|---|
committer | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:16:10 -0400 |
commit | 13e0821fd783a1d5083d825af53cf20e8dcbfd76 (patch) | |
tree | 1ea363b0f13b3e87d177100e6ae6b9f30a2de1b8 /subprojects/boost-sqlite/doc/reference/transaction.adoc | |
parent | aa55cb93036a89c64c08e08f4e1de4fa1fd5a775 (diff) | |
parent | efcea3a80da7c4479d5fe168435ecc9fd06bdc72 (diff) | |
download | sqlite-kv-bench-13e0821fd783a1d5083d825af53cf20e8dcbfd76.tar.gz |
Merge commit 'efcea3a80da7c4479d5fe168435ecc9fd06bdc72' as 'subprojects/boost-sqlite'
Diffstat (limited to 'subprojects/boost-sqlite/doc/reference/transaction.adoc')
-rw-r--r-- | subprojects/boost-sqlite/doc/reference/transaction.adoc | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/subprojects/boost-sqlite/doc/reference/transaction.adoc b/subprojects/boost-sqlite/doc/reference/transaction.adoc new file mode 100644 index 0000000..b6bc449 --- /dev/null +++ b/subprojects/boost-sqlite/doc/reference/transaction.adoc @@ -0,0 +1,104 @@ +== `sqlite/transaction.hpp` + +=== `transaction` + +A simple transaction guard implementing RAAI for transactions + +.Definition +[source,cpp] +---- +struct transaction +{ + // The mode of the transaction + enum behaviour {deferred, immediate, exclusive}; + // A tag to use, to adopt an already initiated transaction. + constexpr static struct adopt_transaction_t {} adopt_transaction{}; + + // Create transaction guard on an existing transaction + transaction(connection & conn, adopt_transaction_t); + + + // Create transaction guard and initiate a transaction + transaction(connection & conn); + + // Create transaction guard and initiate a transaction with the defined behaviour + transaction(connection & conn, behaviour b) ; + + // see https://www.sqlite.org/lang_transaction.html re noexcept + // rollback the transaction if not committed. + ~transaction() noexcept(SQLITE_VERSION_NUMBER >= 3007011); + + + // Commit the transaction. + void commit(); + void commit(system::error_code & ec, error_info & ei); + // Rollback the transaction explicitly. + void rollback(); + void rollback(system::error_code & ec, error_info & ei); + +}; +---- + + + +.Example +[source,cpp] +---- +sqlite::connection conn; +conn.connect("./my-database.db"); + +sqlite::transaction t{conn}; +conn.prepare("insert into log (text) values ($1)").execute(std::make_tuple("booting up")); +t.commit(); +---- + +=== `savepoint` + +A simple transaction guard implementing RAAI for savepoints. Savepoints can be used recursively. + +.Definition +[source,cpp] +---- + +struct savepoint +{ + // A tag to use, to adopt an already initiated transaction. + constexpr static transaction::adopt_transaction_t adopt_transaction{}; + + // Create savepoint guard on an existing savepoint + savepoint(connection & conn, std::string name, transaction::adopt_transaction_t); + + // Create transaction guard and initiate it + savepoint(connection & conn, std::string name); + + // rollback to the savepoint if not committed. + ~savepoint() noexcept(SQLITE_VERSION_NUMBER >= 3007011); + + // Commit/Release the transaction. + void commit(); + void commit(system::error_code & ec, error_info & ei); + + void release(); + void release(system::error_code & ec, error_info & ei); + + // Rollback the transaction explicitly. + void rollback(); + void rollback(system::error_code & ec, error_info & ei); + // The name of the savepoint. + + const std::string & name() const; +}; +---- + + +.Example +[source,cpp] +---- +sqlite::connection conn; +conn.connect("./my-database.db"); + +sqlite::savepoint t{conn, "my-savepoint}; +conn.prepare("insert into log (text) values ($1)").execute(std::make_tuple("booting up")); +t.commit(); +---- + |