00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
#include "pqxx/libcompiler.h"
00020
00021
#include <map>
00022
#include <string>
00023
00024
#include "pqxx/transaction_base"
00025
00026
00027
00028
00029
00030
namespace pqxx
00031 {
00032
00034
00057 class PQXX_LIBEXPORT pipeline :
public internal::transactionfocus
00058 {
00059
public:
00060 typedef long query_id;
00061
00062
explicit pipeline(
transaction_base &,
const PGSTD::string &PName=
"");
00063
00064 ~pipeline() throw ();
00065
00067
00072 query_id insert(const PGSTD::string &);
00073
00075
void complete();
00076
00078
00084
void flush();
00085
00087 bool is_finished(query_id q) const
00088 {
return (q < m_issuedrange.first) && (q < m_error); }
00089
00091
00094 result retrieve(query_id qid)
00095 {
return retrieve(m_queries.find(qid)).second; }
00096
00098 PGSTD::pair<query_id, result> retrieve();
00099
00100 bool empty() const throw () {
return m_queries.empty(); }
00101
00102
int retain(
int retain_max=2);
00103
00104
00106
void resume();
00107
00108
private:
00109
00110
#ifndef NDEBUG
00111
void invariant() const;
00112 #endif
00113
00114 class Query
00115 {
00116
public:
00117
explicit Query(
const PGSTD::string &q) : m_query(q), m_res() {}
00118
00119
const result &get_result() const throw () {
return m_res; }
00120
void set_result(
const result &r)
throw () { m_res = r; }
00121
const PGSTD::string &get_query() const throw () {
return m_query; }
00122
00123
private:
00124 PGSTD::string m_query;
00125 result m_res;
00126 };
00127
00128
typedef PGSTD::map<query_id,Query> QueryMap;
00129
00131
static query_id qid_limit() throw ()
00132 {
00133
#ifdef _MSC_VER
00134
return LONG_MAX;
00135
#else
00136
return PGSTD::numeric_limits<query_id>::max();
00137
#endif
00138
}
00139
00141 query_id generate_id();
00142
00143
bool have_pending() const throw ()
00144 {
return m_issuedrange.second > m_issuedrange.first; }
00145
00146 QueryMap::const_iterator oldest_issued() const;
00147 QueryMap::iterator oldest_issued();
00148 QueryMap::const_iterator end_of_issued() const;
00149 QueryMap::iterator end_of_issued();
00150
00151 static const
char *separator() throw () {
return "; "; }
00152
static const char *dummyvalue() throw () {
return "1"; }
00153
00154
void issue(QueryMap::const_iterator stop);
00155
void issue() { issue(m_queries.end()); }
00156
00158
void set_error_at(query_id qid)
throw () {
if (qid < m_error) m_error = qid; }
00159
00160
void internal_error(
const PGSTD::string &err)
throw (PGSTD::logic_error);
00161
00162
bool obtain_result(
bool really_expect);
00163
00164
void obtain_dummy();
00165
void get_further_available_results();
00166
void check_end_results();
00167
00169
void receive_if_available();
00170
00172
void receive(QueryMap::const_iterator stop);
00173 PGSTD::pair<query_id, result> retrieve(QueryMap::iterator);
00174
00175 QueryMap m_queries;
00176 PGSTD::pair<query_id,query_id> m_issuedrange;
00177
int m_retain;
00178
int m_num_waiting;
00179 query_id m_q_id;
00180
00182
bool m_dummy_pending;
00183
00185 query_id m_error;
00186
00188 pipeline(
const pipeline &);
00190 pipeline &operator=(
const pipeline &);
00191 };
00192
00193
00194 }
00195
00196