libpqxx
|
Simple "transaction" class offering no transactional integrity. More...
#include <nontransaction.hxx>
Public Member Functions | |
nontransaction (connection_base &C, const std::string &Name=std::string{}) | |
Constructor. More... | |
virtual | ~nontransaction () |
![]() | |
transaction_base ()=delete | |
transaction_base (const transaction_base &)=delete | |
transaction_base & | operator= (const transaction_base &)=delete |
virtual | ~transaction_base ()=0 |
void | commit () |
Commit the transaction. More... | |
void | abort () |
Abort the transaction. More... | |
result | exec (const std::string &Query, const std::string &Desc=std::string{}) |
Execute query. More... | |
result | exec (const std::stringstream &Query, const std::string &Desc=std::string{}) |
result | exec0 (const std::string &Query, const std::string &Desc=std::string{}) |
Execute query, which should zero rows of data. More... | |
row | exec1 (const std::string &Query, const std::string &Desc=std::string{}) |
Execute query returning a single row of data. More... | |
result | exec_n (size_t rows, const std::string &Query, const std::string &Desc=std::string{}) |
Execute query, expect given number of rows. More... | |
connection_base & | conn () const |
Connection this transaction is running in. More... | |
void | set_variable (const std::string &Var, const std::string &Val) |
Set session variable in this connection. More... | |
std::string | get_variable (const std::string &) |
Get currently applicable value of variable. More... | |
std::string | esc (const char str[]) const |
Escape string for use as SQL string literal in this transaction. More... | |
std::string | esc (const char str[], size_t maxlen) const |
Escape string for use as SQL string literal in this transaction. More... | |
std::string | esc (const std::string &str) const |
Escape string for use as SQL string literal in this transaction. More... | |
std::string | esc_raw (const unsigned char data[], size_t len) const |
Escape binary data for use as SQL string literal in this transaction. More... | |
std::string | esc_raw (const std::string &) const |
Escape binary data for use as SQL string literal in this transaction. More... | |
std::string | unesc_raw (const std::string &text) const |
Unescape binary data, e.g. from a table field or notification payload. More... | |
std::string | unesc_raw (const char *text) const |
Unescape binary data, e.g. from a table field or notification payload. More... | |
template<typename T > | |
std::string | quote (const T &t) const |
Represent object as SQL string, including quoting & escaping. More... | |
std::string | quote_raw (const unsigned char str[], size_t len) const |
Binary-escape and quote a binarystring for use as an SQL constant. More... | |
std::string | quote_raw (const std::string &str) const |
std::string | quote_name (const std::string &identifier) const |
Escape an SQL identifier for use in a query. More... | |
std::string | esc_like (const std::string &str, char escape_char='\\') const |
Escape string for literal LIKE match. More... | |
template<typename ... Args> | |
result | exec_params (const std::string &query, Args &&...args) |
Execute an SQL statement with parameters. More... | |
template<typename ... Args> | |
row | exec_params1 (const std::string &query, Args &&... args) |
template<typename ... Args> | |
result | exec_params0 (const std::string &query, Args &&...args) |
template<typename ... Args> | |
result | exec_params_n (size_t rows, const std::string &query, Args &&...args) |
internal::parameterized_invocation | parameterized (const std::string &query) |
Parameterize a statement. More... | |
template<typename ... Args> | |
result | exec_prepared (const std::string &statement, Args &&... args) |
Execute a prepared statement, with optional arguments. More... | |
template<typename ... Args> | |
row | exec_prepared1 (const std::string &statement, Args &&... args) |
Execute a prepared statement, and expect a single-row result. More... | |
template<typename ... Args> | |
result | exec_prepared0 (const std::string &statement, Args &&... args) |
Execute a prepared statement, and expect a result with zero rows. More... | |
template<typename ... Args> | |
result | exec_prepared_n (size_t rows, const std::string &statement, Args &&... args) |
Execute a prepared statement, expect a result with given number of rows. More... | |
prepare::invocation | prepared (const std::string &statement=std::string{}) |
Execute prepared statement. More... | |
void | process_notice (const char Msg[]) const |
Have connection process warning message. More... | |
void | process_notice (const std::string &Msg) const |
Have connection process warning message. More... | |
![]() | |
namedclass (const std::string &Classname) | |
namedclass (const std::string &Classname, const std::string &Name) | |
const std::string & | name () const noexcept |
Object name, or the empty string if no name was given. More... | |
const std::string & | classname () const noexcept |
Class name. More... | |
std::string | description () const |
Combination of class name and object name; or just class name. More... | |
Additional Inherited Members | |
![]() | |
using | isolation_tag = isolation_traits< read_committed > |
If nothing else is known, our isolation level is at least read_committed. More... | |
![]() | |
transaction_base (connection_base &c, bool direct=true) | |
Create a transaction (to be called by implementation classes only) More... | |
void | Begin () |
Begin transaction (to be called by implementing class) More... | |
void | End () noexcept |
End transaction. To be called by implementing class' destructor. More... | |
result | direct_exec (const char C[], int Retries=0) |
Execute query on connection directly. More... | |
void | reactivation_avoidance_clear () noexcept |
Forget about any reactivation-blocking resources we tried to allocate. More... | |
![]() | |
internal::reactivation_avoidance_counter | m_reactivation_avoidance |
Resources allocated in this transaction that make reactivation impossible. More... | |
Simple "transaction" class offering no transactional integrity.
nontransaction, like transaction or any other transaction_base-derived class, provides access to a database through a connection. Unlike its siblings, however, nontransaction does not maintain any kind of transactional integrity. This may be useful eg. for read-only access to the database that does not require a consistent, atomic view on its data; or for operations that are not allowed within a backend transaction, such as creating tables.
For queries that update the database, however, a real transaction is likely to be faster unless the transaction consists of only a single record update.
Also, you can keep a nontransaction open for as long as you like. Actual back-end transactions are limited in lifespan, and will sometimes fail just because they took too long to execute or were left idle for too long. This will not happen with a nontransaction (although the connection may still time out, e.g. when the network is unavailable for a very long time).
Any query executed in a nontransaction is committed immediately, and neither commit() nor abort() has any effect.
Database features that require a backend transaction, such as cursors or large objects, will not work in a nontransaction.
|
explicit |
Constructor.
Create a "dummy" transaction.
C | Connection that this "transaction" will operate on. |
Name | Optional name for the transaction, beginning with a letter and containing only letters and digits. |
|
virtual |
Implementation of the pqxx::nontransaction class.
pqxx::nontransaction provides nontransactional database access.
Copyright (c) 2002-2017, 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.
References pqxx::transaction_base::direct_exec(), and pqxx::transaction_base::End().