libpqxx  7.5.0
pqxx::robusttransaction< ISOLATION > Class Template Referencefinal

Slightly slower, better-fortified version of transaction. More...

#include <robusttransaction.hxx>

Inheritance diagram for pqxx::robusttransaction< ISOLATION >:

Public Member Functions

 robusttransaction (connection &c, std::string_view tname)
 
 robusttransaction (connection &c, std::string &&tname)
 
 robusttransaction (connection &c)
 
virtual ~robusttransaction () noexcept override
 
- Public Member Functions inherited from pqxx::internal::basic_robusttransaction
virtual ~basic_robusttransaction () override=0
 
- Public Member Functions inherited from pqxx::transaction_base
 transaction_base ()=delete
 
 transaction_base (transaction_base const &)=delete
 
 transaction_base (transaction_base &&)=delete
 
transaction_baseoperator= (transaction_base const &)=delete
 
transaction_baseoperator= (transaction_base &&)=delete
 
virtual ~transaction_base ()=0
 
void commit ()
 Commit the transaction. More...
 
void abort ()
 Abort the transaction. More...
 
connectionconn () const
 The connection in which this transaction lives. More...
 
void set_variable (std::string_view var, std::string_view value)
 Set session variable using SQL "SET" command. More...
 
std::string get_variable (std::string_view)
 Read session variable using SQL "SHOW" command. More...
 
std::string_view name () const noexcept
 Transaction name, if you passed one to the constructor; or empty string. More...
 
template<>
zview query_value (zview query, std::string_view desc)=delete
 Forbidden specialisation: underlying buffer immediately goes out of scope. More...
 
std::string esc (char const text[]) const
 Escape string for use as SQL string literal in this transaction. More...
 
std::string esc (char const text[], std::size_t maxlen) const
 Escape string for use as SQL string literal in this transaction. More...
 
std::string esc (std::string_view text) const
 Escape string for use as SQL string literal in this transaction. More...
 
std::string esc_raw (unsigned char const data[], std::size_t len) const
 Escape binary data for use as SQL string literal in this transaction. More...
 
std::string esc_raw (zview) const
 Escape binary data for use as SQL string literal in this transaction. More...
 
std::string unesc_raw (zview text) const
 Unescape binary data, e.g. from a table field or notification payload. More...
 
std::string unesc_raw (char const *text) const
 Unescape binary data, e.g. from a table field or notification payload. More...
 
template<typename T >
std::string quote (T const &t) const
 Represent object as SQL string, including quoting & escaping. More...
 
std::string quote_raw (unsigned char const bin[], std::size_t len) const
 Binary-escape and quote a binary string for use as an SQL constant. More...
 
std::string quote_raw (zview bin) const
 Binary-escape and quote a binary string for use as an SQL constant. More...
 
std::string quote_name (std::string_view identifier) const
 Escape an SQL identifier for use in a query. More...
 
std::string esc_like (std::string_view bin, char escape_char='\\') const
 Escape string for literal LIKE match. More...
 
result exec (std::string_view query, std::string_view desc=std::string_view{})
 Execute a command. More...
 
result exec (std::stringstream const &query, std::string_view desc=std::string_view{})
 Execute a command. More...
 
result exec0 (zview query, std::string_view desc=std::string_view{})
 Execute command, which should return zero rows of data. More...
 
row exec1 (zview query, std::string_view desc=std::string_view{})
 Execute command returning a single row of data. More...
 
result exec_n (result::size_type rows, zview query, std::string_view desc=std::string_view{})
 Execute command, expect given number of rows. More...
 
template<typename TYPE >
TYPE query_value (zview query, std::string_view desc=std::string_view{})
 Perform query, expecting exactly 1 row with 1 field, and convert it. More...
 
template<typename... TYPE>
auto stream (std::string_view query)
 Execute a query, and loop over the results row by row. More...
 
template<typename... Args>
result exec_params (zview query, Args &&...args)
 Execute an SQL statement with parameters. More...
 
template<typename... Args>
row exec_params1 (zview query, Args &&...args)
 
template<typename... Args>
result exec_params0 (zview query, Args &&...args)
 
template<typename... Args>
result exec_params_n (std::size_t rows, zview query, Args &&...args)
 
template<typename... Args>
result exec_prepared (zview statement, Args &&...args)
 Execute a prepared statement, with optional arguments. More...
 
template<typename... Args>
row exec_prepared1 (zview statement, Args &&...args)
 Execute a prepared statement, and expect a single-row result. More...
 
template<typename... Args>
result exec_prepared0 (zview statement, Args &&...args)
 Execute a prepared statement, and expect a result with zero rows. More...
 
template<typename... Args>
result exec_prepared_n (result::size_type rows, zview statement, Args &&...args)
 Execute a prepared statement, expect a result with given number of rows. More...
 
void process_notice (char const msg[]) const
 Have connection process a warning message. More...
 
void process_notice (zview msg) const
 Have connection process a warning message. More...
 

Additional Inherited Members

- Protected Member Functions inherited from pqxx::internal::basic_robusttransaction
 basic_robusttransaction (connection &c, zview begin_command, std::string_view tname)
 
 basic_robusttransaction (connection &c, zview begin_command)
 
- Protected Member Functions inherited from pqxx::dbtransaction
 dbtransaction (connection &c)
 Begin transaction. More...
 
 dbtransaction (connection &c, std::string_view tname)
 Begin transaction. More...
 
 dbtransaction (connection &c, std::string_view tname, std::shared_ptr< std::string > rollback_cmd)
 Begin transaction. More...
 
- Protected Member Functions inherited from pqxx::transaction_base
 transaction_base (connection &c, std::string_view tname, std::shared_ptr< std::string > rollback_cmd)
 Create a transaction (to be called by implementation classes only). More...
 
 transaction_base (connection &c, std::string_view tname)
 Create a transaction (to be called by implementation classes only). More...
 
 transaction_base (connection &c)
 Create a transaction (to be called by implementation classes only). More...
 
void register_transaction ()
 Register this transaction with the connection. More...
 
void close () noexcept
 End transaction. To be called by implementing class' destructor. More...
 
virtual void do_abort ()
 Transaction type-specific way of aborting a transaction. More...
 
void set_rollback_cmd (std::shared_ptr< std::string > cmd)
 Set the rollback command. More...
 
result direct_exec (std::string_view, std::string_view desc=""sv)
 Execute query on connection directly. More...
 
result direct_exec (std::shared_ptr< std::string >, std::string_view desc=""sv)
 

Detailed Description

template<isolation_level ISOLATION = read_committed>
class pqxx::robusttransaction< ISOLATION >

Slightly slower, better-fortified version of transaction.

Requires PostgreSQL 10 or better.

robusttransaction is similar to transaction, but spends more time and effort to deal with the hopefully rare case that the connection to the backend is lost just while it's trying to commit. In such cases, the client does not know whether the backend (on the other side of the broken connection) managed to commit the transaction.

When this happens, robusttransaction tries to reconnect to the database and figure out what happened.

This service level was made optional since you may not want to pay the overhead where it is not necessary. Certainly the use of this class makes no sense for local connections, or for transactions that read the database but never modify it, or for noncritical database manipulations.

Besides being slower, it's also more complex. Which means that in practice a robusttransaction could actually fail more instead of less often than a normal transaction. What robusttransaction tries to achieve is to give you certainty, not just be more successful per se.

Constructor & Destructor Documentation

◆ robusttransaction() [1/3]

template<isolation_level ISOLATION = read_committed>
pqxx::robusttransaction< ISOLATION >::robusttransaction ( connection c,
std::string_view  tname 
)

Create robusttransaction of given name.

Parameters
cConnection inside which this robusttransaction should live.
nameoptional human-readable name for this transaction.

◆ robusttransaction() [2/3]

template<isolation_level ISOLATION = read_committed>
pqxx::robusttransaction< ISOLATION >::robusttransaction ( connection c,
std::string &&  tname 
)

Create robusttransaction of given name.

Parameters
cConnection inside which this robusttransaction should live.
nameoptional human-readable name for this transaction.

◆ robusttransaction() [3/3]

template<isolation_level ISOLATION = read_committed>
pqxx::robusttransaction< ISOLATION >::robusttransaction ( connection c)
explicit

Create robusttransaction of given name.

Parameters
cConnection inside which this robusttransaction should live.
nameoptional human-readable name for this transaction.

◆ ~robusttransaction()

template<isolation_level ISOLATION = read_committed>
virtual pqxx::robusttransaction< ISOLATION >::~robusttransaction ( )
overridevirtualnoexcept

The documentation for this class was generated from the following file: