libpqxx  7.9.0
transaction.hxx
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-2024, 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 {
24 class PQXX_LIBEXPORT basic_transaction : public dbtransaction
25 {
26 protected:
28  connection &c, zview begin_command, std::string_view tname);
29  basic_transaction(connection &c, zview begin_command, std::string &&tname);
30  basic_transaction(connection &c, 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 {
46 
48 
68 template<
69  isolation_level ISOLATION = isolation_level::read_committed,
72 {
73 public:
75 
80  transaction(connection &c, std::string_view tname) :
81  internal::basic_transaction{
82  c, internal::begin_cmd<ISOLATION, READWRITE>, tname}
83  {}
84 
86 
90  explicit transaction(connection &c) :
91  internal::basic_transaction{
92  c, internal::begin_cmd<ISOLATION, READWRITE>}
93  {}
94 
95  virtual ~transaction() noexcept override { close(); }
96 };
97 
98 
101 
105 
107 } // namespace pqxx
108 #endif
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx: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
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:84
const zview begin_cmd
The SQL command for starting a given type of transaction.
Connection to a database.
Definition: connection.hxx:233
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:54
Helper base class for the transaction class template.
Definition: transaction.hxx:25
virtual ~basic_transaction() noexcept override=0
Standard back-end transaction, templatised on isolation level.
Definition: transaction.hxx:72
virtual ~transaction() noexcept override
Definition: transaction.hxx:95
transaction(connection &c, std::string_view tname)
Begin a transaction.
Definition: transaction.hxx:80
transaction(connection &c)
Begin a transaction.
Definition: transaction.hxx:90
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:38