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
00073 query_id insert(const PGSTD::string &);
00074
00076 void complete();
00077
00079
00086 void flush();
00087
00089 bool is_finished(query_id) const;
00090
00092
00098 result retrieve(query_id qid)
00099 { return retrieve(m_queries.find(qid)).second; }
00100
00102
00103 PGSTD::pair<query_id, result> retrieve();
00104
00105 bool empty() const throw () { return m_queries.empty(); }
00106
00108
00119 int retain(int retain_max=2);
00120
00121
00123 void resume();
00124
00125 private:
00126 class Query
00127 {
00128 public:
00129 explicit Query(const PGSTD::string &q) : m_query(q), m_res() {}
00130
00131 const result &get_result() const throw () { return m_res; }
00132 void set_result(const result &r) throw () { m_res = r; }
00133 const PGSTD::string &get_query() const throw () { return m_query; }
00134
00135 private:
00136 PGSTD::string m_query;
00137 result m_res;
00138 };
00139
00140 typedef PGSTD::map<query_id,Query> QueryMap;
00141
00142 struct getquery:PGSTD::unary_function<QueryMap::const_iterator,PGSTD::string>
00143 {
00144 PGSTD::string operator()(QueryMap::const_iterator i) const
00145 { return i->second.get_query(); }
00146 };
00147
00149 static query_id qid_limit() throw ()
00150 {
00151 #if defined(PQXX_HAVE_LIMITS) && !defined(_MSC_VER)
00152 return PGSTD::numeric_limits<query_id>::max();
00153 #else
00154 return LONG_MAX;
00155 #endif
00156 }
00157
00159 query_id generate_id();
00160
00161 bool have_pending() const throw ()
00162 { return m_issuedrange.second != m_issuedrange.first; }
00163
00164 void issue();
00165
00167 void set_error_at(query_id qid) throw () { if (qid < m_error) m_error = qid; }
00168
00169 void internal_error(const PGSTD::string &err) throw (PGSTD::logic_error);
00170
00171 bool obtain_result(bool expect_none=false);
00172
00173 void obtain_dummy();
00174 void get_further_available_results();
00175 void check_end_results();
00176
00178 void receive_if_available();
00179
00181 void receive(QueryMap::const_iterator stop);
00182 PGSTD::pair<query_id, result> retrieve(QueryMap::iterator);
00183
00184 QueryMap m_queries;
00185 PGSTD::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
00186 int m_retain;
00187 int m_num_waiting;
00188 query_id m_q_id;
00189
00191 bool m_dummy_pending;
00192
00194 query_id m_error;
00195
00197 pipeline(const pipeline &);
00199 pipeline &operator=(const pipeline &);
00200 };
00201
00202
00203 }
00204
00205