libpqxx  7.7.1
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 #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 
103 using read_transaction =
105 
107 } // namespace pqxx
108 #endif
Helper base class for the transaction class template.
Definition: transaction.hxx:24
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:53
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
Connection to a database.
Definition: connection.hxx:185
isolation_level
Transaction isolation levels.
Definition: isolation.hxx:65
transaction(connection &c, std::string_view tname)
Begin a transaction.
Definition: transaction.hxx:80
transaction(connection &c)
Begin a transaction.
Definition: transaction.hxx:90
Standard back-end transaction, templatised on isolation level.
Definition: transaction.hxx:71
write_policy
Should a transaction be read-only, or read-write?
Definition: isolation.hxx:26
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:82
virtual ~transaction() noexcept override
Definition: transaction.hxx:95