libpqxx  7.7.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-2022, 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 #include "pqxx/dbtransaction.hxx"
16 
17 namespace pqxx::internal
18 {
20 class PQXX_LIBEXPORT basic_transaction : public dbtransaction
21 {
22 protected:
24  connection &c, zview begin_command, std::string_view tname);
25  basic_transaction(connection &c, zview begin_command, std::string &&tname);
26  basic_transaction(connection &c, zview begin_command);
27 
28  virtual ~basic_transaction() noexcept override = 0;
29 
30 private:
31  virtual void do_commit() override;
32 };
33 } // namespace pqxx::internal
34 
35 
36 namespace pqxx
37 {
42 
44 
64 template<
65  isolation_level ISOLATION = isolation_level::read_committed,
68 {
69 public:
71 
76  transaction(connection &c, std::string_view tname) :
77  internal::basic_transaction{
78  c, internal::begin_cmd<ISOLATION, READWRITE>, tname}
79  {}
80 
82 
86  explicit transaction(connection &c) :
87  internal::basic_transaction{
88  c, internal::begin_cmd<ISOLATION, READWRITE>}
89  {}
90 
91  virtual ~transaction() noexcept override { close(); }
92 };
93 
94 
97 
99 using read_transaction =
101 
103 } // namespace pqxx
104 #endif
write_policy
Should a transaction be read-only, or read-write?
Definition: isolation.hxx:22
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:49
Standard back-end transaction, templatised on isolation level.
Definition: transaction.hxx:67
virtual ~transaction() noexcept override
Definition: transaction.hxx:91
transaction(connection &c)
Begin a transaction.
Definition: transaction.hxx:86
Helper base class for the transaction class template.
Definition: transaction.hxx:20
isolation_level
Transaction isolation levels.
Definition: isolation.hxx:61
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
Internal items for libpqxx&#39; own use. Do not use these yourself.
Definition: composite.hxx:79
Connection to a database.
Definition: connection.hxx:180
transaction(connection &c, std::string_view tname)
Begin a transaction.
Definition: transaction.hxx:76
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22