pipeline.hxx
#ifndef PQXX_H_PIPELINE
#define PQXX_H_PIPELINE
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#include <limits>
#include <map>
#include <string>
#include "pqxx/transaction_base.hxx"
// Methods tested in eg. test module test01 are marked with "//[t01]".
namespace pqxx
{
class PQXX_LIBEXPORT pipeline : public internal::transactionfocus
{
public:
using query_id = long;
pipeline(const pipeline &) =delete;
pipeline &operator=(const pipeline &) =delete;
explicit pipeline( //[t69]
transaction_base &,
const std::string &Name=std::string{});
~pipeline() noexcept;
query_id insert(const std::string &); //[t69]
void complete(); //[t71]
void flush(); //[t70]
void cancel();
bool is_finished(query_id) const; //[t71]
result retrieve(query_id qid) //[t71]
{ return retrieve(m_queries.find(qid)).second; }
std::pair<query_id, result> retrieve(); //[t69]
bool empty() const noexcept { return m_queries.empty(); } //[t69]
int retain(int retain_max=2); //[t70]
void resume(); //[t70]
private:
class PQXX_PRIVATE Query
{
public:
explicit Query(const std::string &q) : m_query{q}, m_res{} {}
const result &get_result() const noexcept { return m_res; }
void set_result(const result &r) noexcept { m_res = r; }
const std::string &get_query() const noexcept { return m_query; }
private:
std::string m_query;
result m_res;
};
using QueryMap = std::map<query_id,Query>;
void attach();
void detach();
static constexpr query_id qid_limit() noexcept
{
// Parenthesise this to work around an eternal Visual C++ problem:
// Without the extra parentheses, unless NOMINMAX is defined, the
// preprocessor will mistake this "max" for its annoying built-in macro
// of the same name.
return (std::numeric_limits<query_id>::max)();
}
PQXX_PRIVATE query_id generate_id();
bool have_pending() const noexcept
{ return m_issuedrange.second != m_issuedrange.first; }
PQXX_PRIVATE void issue();
void set_error_at(query_id qid) noexcept
{ if (qid < m_error) m_error = qid; }
[[noreturn]] PQXX_PRIVATE void internal_error(const std::string &err);
PQXX_PRIVATE bool obtain_result(bool expect_none=false);
PQXX_PRIVATE void obtain_dummy();
PQXX_PRIVATE void get_further_available_results();
PQXX_PRIVATE void check_end_results();
PQXX_PRIVATE void receive_if_available();
PQXX_PRIVATE void receive(pipeline::QueryMap::const_iterator stop);
std::pair<pipeline::query_id, result>
retrieve(pipeline::QueryMap::iterator);
QueryMap m_queries;
std::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
int m_retain = 0;
int m_num_waiting = 0;
query_id m_q_id = 0;
bool m_dummy_pending = false;
query_id m_error = qid_limit();
};
} // namespace
#include "pqxx/compiler-internal-post.hxx"
#endif
pqxx::result::size
PQXX_PURE size_type size() const noexcept
Definition: result.cxx:94
pqxx::pipeline::complete
void complete()
Wait for all ongoing or pending operations to complete.
Definition: pipeline.cxx:85
pqxx::internal
Private namespace for libpqxx's internal use; do not access.
Definition: connection_base.hxx:43
pqxx::pipeline::pipeline
pipeline(const pipeline &)=delete
pqxx::pipeline::empty
bool empty() const noexcept
Definition: pipeline.hxx:115
pqxx::pipeline
Processes several queries in FIFO manner, optimized for high throughput.
Definition: pipeline.hxx:48
pqxx::pipeline::is_finished
bool is_finished(query_id) const
Is result for given query available?
Definition: pipeline.cxx:123
pqxx::result
Result set containing data returned by a query or command.
Definition: result.hxx:69
pqxx::pipeline::resume
void resume()
Resume retained query emission (harmless when not needed)
Definition: pipeline.cxx:158
pqxx::pipeline::insert
query_id insert(const std::string &)
Add query to the pipeline.
Definition: pipeline.cxx:62
pqxx::pipeline::flush
void flush()
Forget all ongoing or pending operations and retrieved results.
Definition: pipeline.cxx:97
pqxx::sql_error
Exception class for failed queries.
Definition: except.hxx:130
pqxx::internal::enc_group
encoding_group enc_group(int libpq_enc_id)
Definition: encodings.cxx:637
pqxx::pipeline::retain
int retain(int retain_max=2)
Set maximum number of queries to retain before issuing them to the backend.
Definition: pipeline.cxx:142
pqxx::separated_list
std::string separated_list(const std::string &sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: util.hxx:95
pqxx::internal_error
Internal error in libpqxx library.
Definition: except.hxx:207
pqxx::broken_connection
Exception class for lost or failed backend connection.
Definition: except.hxx:118
pqxx::pipeline::retrieve
std::pair< query_id, result > retrieve()
Retrieve oldest unretrieved result (possibly wait for one)
Definition: pipeline.cxx:134
pqxx::result::at
const row at(size_type) const
Definition: result.cxx:131
pqxx::internal::namedclass
Helper base class: object descriptions for error messages and such.
Definition: util.hxx:233
pqxx::internal::transactionfocus
Definition: transaction_base.hxx:43
pqxx::to_string
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:451
pqxx::pipeline::~pipeline
~pipeline() noexcept
Definition: pipeline.cxx:43
pqxx::pipeline::query_id
long query_id
Definition: pipeline.hxx:51
pqxx::range_error
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:251
pqxx::transaction_base
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:136
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
pqxx::pipeline::cancel
void cancel()
Cancel ongoing query, if any.
Definition: pipeline.cxx:111