transaction.hxx
/* Definition of the pqxx::transaction class.
* pqxx::transaction represents a standard database transaction.
*
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/transaction instead.
*
* Copyright (c) 2000-2023, Jeroen T. Vermeulen.
*
* See COPYING for copyright license. If you did not receive a file called
* COPYING with this source code, please notify the distributor of this
* mistake, or contact the author.
*/
#ifndef PQXX_H_TRANSACTION
#define PQXX_H_TRANSACTION
#if !defined(PQXX_HEADER_PRE)
# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
#endif
#include "pqxx/dbtransaction.hxx"
namespace pqxx::internal
{
class PQXX_LIBEXPORT basic_transaction : public dbtransaction
{
protected:
basic_transaction(
connection &c, zview begin_command, std::string_view tname);
basic_transaction(connection &c, zview begin_command, std::string &&tname);
basic_transaction(connection &c, zview begin_command);
virtual ~basic_transaction() noexcept override = 0;
private:
virtual void do_commit() override;
};
} // namespace pqxx::internal
namespace pqxx
{
template<
isolation_level ISOLATION = isolation_level::read_committed,
write_policy READWRITE = write_policy::read_write>
class transaction final : public internal::basic_transaction
{
public:
transaction(connection &c, std::string_view tname) :
internal::basic_transaction{
c, internal::begin_cmd<ISOLATION, READWRITE>, tname}
{}
explicit transaction(connection &c) :
internal::basic_transaction{
c, internal::begin_cmd<ISOLATION, READWRITE>}
{}
virtual ~transaction() noexcept override { close(); }
};
using work = transaction<>;
using read_transaction =
transaction<isolation_level::read_committed, write_policy::read_only>;
} // namespace pqxx
#endif
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:33
pqxx::write_policy
write_policy
Should a transaction be read-only, or read-write?
Definition isolation.hxx:27
pqxx::isolation_level
isolation_level
Transaction isolation levels.
Definition isolation.hxx:66
pqxx::internal
Internal items for libpqxx' own use. Do not use these yourself.
Definition composite.hxx:84
pqxx::connection
Connection to a database.
Definition connection.hxx:253
pqxx::dbtransaction
Abstract transaction base class: bracket transactions on the database.
Definition dbtransaction.hxx:54
pqxx::internal::basic_transaction
Helper base class for the transaction class template.
Definition transaction.hxx:25
pqxx::internal::basic_transaction::~basic_transaction
virtual ~basic_transaction() noexcept override=0
pqxx::zview
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38