Loading...
Searching...
No Matches
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-2024, 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 &cx, zview begin_command, std::string_view tname);
basic_transaction(connection &cx, zview begin_command, std::string &&tname);
basic_transaction(connection &cx, 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 &cx, std::string_view tname) :
internal::basic_transaction{
cx, internal::begin_cmd<ISOLATION, READWRITE>, tname}
{}
explicit transaction(connection &cx) :
internal::basic_transaction{
cx, 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::transaction::transaction
transaction(connection &cx)
Begin a transaction.
Definition transaction.hxx:90
pqxx::transaction::transaction
transaction(connection &cx, std::string_view tname)
Begin a transaction.
Definition transaction.hxx:80
pqxx::transaction
Standard back-end transaction, templatised on isolation level.
Definition transaction.hxx:72
pqxx::internal
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
pqxx::work
transaction<> work
The default transaction type.
Definition transaction.hxx:100
pqxx::read_transaction
transaction< isolation_level::read_committed, write_policy::read_only > read_transaction
Read-only transaction.
Definition transaction.hxx:103
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