libpqxx
The C++ client library for PostgreSQL
Loading...
Searching...
No Matches
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
20
21namespace pqxx::internal
22{
24class PQXX_LIBEXPORT basic_transaction : public dbtransaction
25{
26protected:
27 basic_transaction(
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
34private:
35 virtual void do_commit() override;
36};
37} // namespace pqxx::internal
38
39
40namespace pqxx
41{
43
69template<
70 isolation_level ISOLATION = isolation_level::read_committed,
71 write_policy READWRITE = write_policy::read_write>
72class transaction final : public internal::basic_transaction
73{
74public:
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
103using work =
105
106
108
112
113} // namespace pqxx
114#endif
virtual ~transaction() noexcept override
Definition transaction.hxx:96
transaction(connection &cx)
Begin a transaction.
Definition transaction.hxx:91
transaction(connection &cx, std::string_view tname)
Begin a transaction.
Definition transaction.hxx:81
transaction Standard back-end transaction, templatised on isolation level.
Definition transaction.hxx:73
transaction< isolation_level::read_committed, write_policy::read_only > read_transaction
Read-only transaction.
Definition transaction.hxx:110
transaction< isolation_level::read_committed, write_policy::read_write > work
The default transaction type.
Definition transaction.hxx:103
#define PQXX_LIBEXPORT
Definition header-pre.hxx:157
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
write_policy
Should a transaction be read-only, or read-write?
Definition isolation.hxx:27
isolation_level
Transaction isolation levels.
Definition isolation.hxx:66