00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pqxx/compiler-public.hxx"
00020 #include "pqxx/compiler-internal-pre.hxx"
00021
00022 #ifdef PQXX_HAVE_LIMITS
00023 #include <limits>
00024 #endif
00025
00026 #include <map>
00027 #include <string>
00028
00029 #include "pqxx/transaction_base"
00030
00031
00032
00033
00034
00035 namespace pqxx
00036 {
00037
00039
00062 class PQXX_LIBEXPORT pipeline : public internal::transactionfocus
00063 {
00064 public:
00065 typedef long query_id;
00066
00067 explicit pipeline(transaction_base &,
00068 const PGSTD::string &Name=PGSTD::string());
00069
00070 ~pipeline() throw ();
00071
00073
00079 query_id insert(const PGSTD::string &);
00080
00082 void complete();
00083
00085
00092 void flush();
00093
00095 bool is_finished(query_id) const;
00096
00098
00104 result retrieve(query_id qid)
00105 { return retrieve(m_queries.find(qid)).second; }
00106
00108
00109 PGSTD::pair<query_id, result> retrieve();
00110
00111 bool empty() const throw () { return m_queries.empty(); }
00112
00114
00125 int retain(int retain_max=2);
00126
00127
00129 void resume();
00130
00131 private:
00132 class PQXX_PRIVATE Query
00133 {
00134 public:
00135 explicit Query(const PGSTD::string &q) : m_query(q), m_res() {}
00136
00137 const result &get_result() const throw () { return m_res; }
00138 void set_result(const result &r) throw () { m_res = r; }
00139 const PGSTD::string &get_query() const throw () { return m_query; }
00140
00141 private:
00142 PGSTD::string m_query;
00143 result m_res;
00144 };
00145
00146 typedef PGSTD::map<query_id,Query> QueryMap;
00147
00148 struct getquery:PGSTD::unary_function<QueryMap::const_iterator,PGSTD::string>
00149 {
00150 getquery(){}
00151 PGSTD::string operator()(QueryMap::const_iterator i) const
00152 { return i->second.get_query(); }
00153 };
00154
00156 static query_id qid_limit() throw ()
00157 {
00158 #if defined(PQXX_HAVE_LIMITS)
00159 return PGSTD::numeric_limits<query_id>::max();
00160 #else
00161 return LONG_MAX;
00162 #endif
00163 }
00164
00166 query_id PQXX_PRIVATE generate_id();
00167
00168 bool have_pending() const throw ()
00169 { return m_issuedrange.second != m_issuedrange.first; }
00170
00171 void PQXX_PRIVATE issue();
00172
00174 void set_error_at(query_id qid) throw () { if (qid < m_error) m_error = qid; }
00175
00176 void PQXX_PRIVATE internal_error(const PGSTD::string &err)
00177 throw (PGSTD::logic_error);
00178
00179 bool PQXX_PRIVATE obtain_result(bool expect_none=false);
00180
00181 void PQXX_PRIVATE obtain_dummy();
00182 void PQXX_PRIVATE get_further_available_results();
00183 void PQXX_PRIVATE check_end_results();
00184
00186 void PQXX_PRIVATE receive_if_available();
00187
00189 void PQXX_PRIVATE receive(pipeline::QueryMap::const_iterator stop);
00190 PGSTD::pair<pipeline::query_id, result> retrieve(pipeline::QueryMap::iterator);
00191
00192 QueryMap m_queries;
00193 PGSTD::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
00194 int m_retain;
00195 int m_num_waiting;
00196 query_id m_q_id;
00197
00199 bool m_dummy_pending;
00200
00202 query_id m_error;
00203
00205 pipeline(const pipeline &);
00207 pipeline &operator=(const pipeline &);
00208 };
00209
00210
00211 }
00212
00213
00214 #include "pqxx/compiler-internal-post.hxx"