pg_async
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Transactions

All the work with the database is wrapped into transactions. A transaction MUST be explicitly committed or it well be rolled back when the transaction handle object goes out of scope.

If a transaction is rolled back, the error callback is called in any case, either the transaction was rolled back explicitly by the user or if it was rolled back as the result of abandoned transaction object.

#include <tip/db/pg.hpp>
using namespace tip::db::pg;
// Start a transaction explicitly
// Database alias
"main"_db,
// Function to be called in the transaction
[]( transaction_ptr tran )
{
// run queries
tran->commit();
},
// Transaction error handler
[](db_error const& e)
{
}
);
// Start a transaction implicitly
query("main"_db, "sql statement")(
[](transaction_ptr tran, resultset res, bool complete)
{
// Process results, run more queries
tran->commit();
},
// This handler will receive both the query and the transaction errors
[](db_error const&)
{
});
See Also
tip::db::pg::transaction
Errors and exceptions