libpqxx
The C++ client library for PostgreSQL
transaction.hxx
Go to the documentation of this file.
1 /* Definition of the pqxx::transaction class.
2  * pqxx::transaction represents a standard database transaction.
3  *
4  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/transaction instead.
5  *
6  * Copyright (c) 2000-2025, Jeroen T. Vermeulen.
7  *
8  * See COPYING for copyright license. If you did not receive a file called
9  * COPYING with this source code, please notify the distributor of this
10  * mistake, or contact the author.
11  */
12 #ifndef PQXX_H_TRANSACTION
13 #define PQXX_H_TRANSACTION
14 
15 #if !defined(PQXX_HEADER_PRE)
16 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
17 #endif
18 
19 #include "pqxx/dbtransaction.hxx"
20 
21 namespace pqxx::internal
22 {
25 {
26 protected:
28  connection &cx, zview begin_command, std::string_view tname);
29  basic_transaction(connection &cx, zview begin_command, std::string &&tname);
30  basic_transaction(connection &cx, zview begin_command);
31 
32  virtual ~basic_transaction() noexcept override = 0;
33 
34 private:
35  virtual void do_commit() override;
36 };
37 } // namespace pqxx::internal
38 
39 
40 namespace pqxx
41 {
43 
69 template<
73 {
74 public:
76 
81  transaction(connection &cx, std::string_view tname) :
82  internal::basic_transaction{
83  cx, internal::begin_cmd<ISOLATION, READWRITE>, tname}
84  {}
85 
87 
91  explicit transaction(connection &cx) :
92  internal::basic_transaction{
93  cx, internal::begin_cmd<ISOLATION, READWRITE>}
94  {}
95 
96  virtual ~transaction() noexcept override { close(); }
97 };
98 
99 
101 
103 using work =
105 
106 
108 
110 using read_transaction =
112 
113 } // namespace pqxx
114 #endif
void close() noexcept
End transaction. To be called by implementing class' destructor.
Definition: transaction_base.cxx:332
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
Definition: isolation.hxx:70
Internal items for libpqxx' own use. Do not use these yourself.
Definition: encodings.cxx:32
transaction(connection &cx, std::string_view tname)
Begin a transaction.
Definition: transaction.hxx:81
Helper base class for the pqxx::transaction class template.
Definition: transaction.hxx:24
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:53
transaction< isolation_level::read_committed, write_policy::read_write > work
The default transaction type.
Definition: transaction.hxx:104
#define PQXX_LIBEXPORT
Definition: header-pre.hxx:157
transaction(connection &cx)
Begin a transaction.
Definition: transaction.hxx:91
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
isolation_level
Transaction isolation levels.
Definition: isolation.hxx:65
transaction Standard back-end transaction, templatised on isolation level.
Definition: transaction.hxx:72
basic_transaction(connection &cx, zview begin_command, std::string_view tname)
Definition: transaction.cxx:24
virtual ~transaction() noexcept override
Definition: transaction.hxx:96
Connection to a database.
Definition: connection.hxx:278
write_policy
Should a transaction be read-only, or read-write?
Definition: isolation.hxx:26