Loading...
Searching...
No Matches
robusttransaction.hxx
/* Definition of the pqxx::robusttransaction class.
*
* pqxx::robusttransaction is a slower but safer transaction class.
*
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/robusttransaction instead.
*
* Copyright (c) 2000-2024, Jeroen T. Vermeulen.
*
* See COPYING for copyright license. If you did not receive a file called
* COPYING with this source code, please notify the distributor of this
* mistake, or contact the author.
*/
#ifndef PQXX_H_ROBUSTTRANSACTION
#define PQXX_H_ROBUSTTRANSACTION
#if !defined(PQXX_HEADER_PRE)
# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
#endif
#include "pqxx/dbtransaction.hxx"
namespace pqxx::internal
{
class PQXX_LIBEXPORT PQXX_NOVTABLE basic_robusttransaction
: public dbtransaction
{
public:
virtual ~basic_robusttransaction() override = 0;
protected:
basic_robusttransaction(
connection &cx, zview begin_command, std::string_view tname);
basic_robusttransaction(connection &cx, zview begin_command);
private:
using IDType = unsigned long;
std::string m_conn_string;
std::string m_xid;
int m_backendpid = -1;
void init(zview begin_command);
// @warning This function will become `final`.
virtual void do_commit() override;
};
} // namespace pqxx::internal
namespace pqxx
{
template<isolation_level ISOLATION = read_committed>
class robusttransaction final : public internal::basic_robusttransaction
{
public:
robusttransaction(connection &cx, std::string_view tname) :
internal::basic_robusttransaction{
cx, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>,
tname}
{}
robusttransaction(connection &cx, std::string &&tname) :
internal::basic_robusttransaction{
cx, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>,
std::move(tname)}
{}
explicit robusttransaction(connection &cx) :
internal::basic_robusttransaction{
cx, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>}
{}
virtual ~robusttransaction() noexcept override { close(); }
};
} // namespace pqxx
#endif
pqxx::connection
Connection to a database.
Definition connection.hxx:279
pqxx::internal::basic_robusttransaction
Helper base class for the robusttransaction class template.
Definition robusttransaction.hxx:27
pqxx::zview
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38
pqxx::transaction_base::close
void close() noexcept
End transaction. To be called by implementing class' destructor.
Definition transaction_base.cxx:332
pqxx::dbtransaction
Abstract transaction base class: bracket transactions on the database.
Definition dbtransaction.hxx:54
pqxx::internal
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
pqxx::write_policy
write_policy
Should a transaction be read-only, or read-write?
Definition isolation.hxx:27