13 #ifndef PQXX_H_PIPELINE
14 #define PQXX_H_PIPELINE
16 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/internal/compiler-internal-pre.hxx"
23 #include "pqxx/transaction_base.hxx"
51 namedclass{
"pipeline"},
57 namedclass{
"pipeline", name},
63 namedclass{
"pipeline", std::move(name)},
69 namedclass{
"pipeline", name},
84 query_id insert(std::string_view);
119 [[nodiscard]]
bool is_finished(query_id) const;
130 return retrieve(m_queries.find(qid)).second;
135 std::pair<query_id, result> retrieve();
137 [[nodiscard]]
bool empty() const noexcept {
return m_queries.empty(); }
152 int retain(
int retain_max = 2);
159 class PQXX_PRIVATE Query
162 explicit Query(std::string_view q) :
163 m_query{std::make_shared<std::string>(q)},
167 result
const &get_result() const noexcept {
return m_res; }
168 void set_result(result
const &r) noexcept { m_res = r; }
169 std::shared_ptr<std::string> get_query() const noexcept {
return m_query; }
172 std::shared_ptr<std::string> m_query;
176 using QueryMap = std::map<query_id, Query>;
183 static constexpr query_id qid_limit() noexcept
189 return (std::numeric_limits<query_id>::max)();
193 PQXX_PRIVATE query_id generate_id();
195 bool have_pending() const noexcept
197 return m_issuedrange.second != m_issuedrange.first;
200 PQXX_PRIVATE
void issue();
203 void set_error_at(query_id qid) noexcept
210 [[noreturn]] PQXX_PRIVATE
void internal_error(std::string
const &err);
212 PQXX_PRIVATE
bool obtain_result(
bool expect_none =
false);
214 PQXX_PRIVATE
void obtain_dummy();
215 PQXX_PRIVATE
void get_further_available_results();
216 PQXX_PRIVATE
void check_end_results();
219 PQXX_PRIVATE
void receive_if_available();
222 PQXX_PRIVATE
void receive(pipeline::QueryMap::const_iterator stop);
223 std::pair<pipeline::query_id, result> retrieve(pipeline::QueryMap::iterator);
226 std::pair<QueryMap::iterator, QueryMap::iterator> m_issuedrange;
228 int m_num_waiting = 0;
232 bool m_dummy_pending =
false;
235 query_id m_error = qid_limit();
239 #include "pqxx/internal/compiler-internal-post.hxx"
~pipeline() noexcept
Definition: pipeline.cxx:39
long query_id
Definition: pipeline.hxx:45
bool is_finished(query_id) const
Is result for given query available?
Definition: pipeline.cxx:131
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
void cancel()
Cancel ongoing query, if any.
Definition: pipeline.cxx:119
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:478
encoding_group enc_group(int libpq_enc_id)
Definition: encodings.cxx:585
int retain(int retain_max=2)
Definition: pipeline.cxx:149
Processes several queries in FIFO manner, optimized for high throughput.
Definition: pipeline.hxx:42
std::pair< query_id, result > retrieve()
Retrieve oldest unretrieved result (possibly wait for one).
Definition: pipeline.cxx:141
Result set containing data returned by a query or command.
Definition: result.hxx:70
pipeline(transaction_base &t, char const name[])
Definition: pipeline.hxx:56
bool empty() const noexcept
Definition: pipeline.hxx:137
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:192
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:97
pipeline(transaction_base &t)
Definition: pipeline.hxx:50
Internal error in libpqxx library.
Definition: except.hxx:157
void resume()
Resume retained query emission. Harmless when not needed.
Definition: pipeline.cxx:165
void flush()
Forget all ongoing or pending operations and retrieved results.
Definition: pipeline.cxx:104
pipeline(transaction_base &t, std::string &&name)
Definition: pipeline.hxx:62
query_id insert(std::string_view)
Add query to the pipeline.
Definition: pipeline.cxx:65
std::string separated_list(std::string_view sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: separated_list.hxx:40
pipeline(transaction_base &t, std::string_view name)
Definition: pipeline.hxx:68
Definition: transaction_base.hxx:42
void complete()
Wait for all ongoing or pending operations to complete, and detach.
Definition: pipeline.cxx:91