00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "pqxx/compiler-public.hxx"
00021 #include "pqxx/compiler-internal-pre.hxx"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "pqxx/connection_base"
00033 #include "pqxx/isolation"
00034 #include "pqxx/result"
00035
00036
00037
00038
00039 namespace pqxx
00040 {
00041 class connection_base;
00042 class transaction_base;
00043
00044
00045 namespace internal
00046 {
00047 class PQXX_LIBEXPORT transactionfocus : public virtual namedclass
00048 {
00049 public:
00050 explicit transactionfocus(transaction_base &t) :
00051 namedclass("transactionfocus"),
00052 m_Trans(t),
00053 m_registered(false)
00054 {
00055 }
00056
00057 protected:
00058 void register_me();
00059 void unregister_me() throw ();
00060 void reg_pending_error(const PGSTD::string &) throw ();
00061 bool registered() const throw () { return m_registered; }
00062
00063 transaction_base &m_Trans;
00064
00065 private:
00066 bool m_registered;
00067
00069 transactionfocus();
00071 transactionfocus(const transactionfocus &);
00073 transactionfocus &operator=(const transactionfocus &);
00074 };
00075
00076 }
00077
00078
00079
00081
00091 class PQXX_LIBEXPORT transaction_base : public virtual internal::namedclass
00092 {
00093 public:
00095 typedef isolation_traits<read_committed> isolation_tag;
00096
00097 virtual ~transaction_base() =0;
00098
00100
00112 void commit();
00113
00115
00118 void abort();
00119
00124
00125 PGSTD::string esc(const char str[]) const;
00127 PGSTD::string esc(const char str[], size_t maxlen) const
00128 { return m_Conn.esc(str,maxlen); }
00130 PGSTD::string esc(const PGSTD::string &) const;
00132
00134
00139 result exec(const char Query[],
00140 const PGSTD::string &Desc=PGSTD::string());
00141
00143
00151 result exec(const PGSTD::string &Query,
00152 const PGSTD::string &Desc=PGSTD::string())
00153 { return exec(Query.c_str(), Desc); }
00154
00155 result exec(const PGSTD::stringstream &Query,
00156 const PGSTD::string &Desc=PGSTD::string())
00157 { return exec(Query.str(), Desc); }
00158
00163
00164
00198 prepare::invocation prepared(const PGSTD::string &statement);
00199
00201
00206
00207 void process_notice(const char Msg[]) const
00208 { m_Conn.process_notice(Msg); }
00210 void process_notice(const PGSTD::string &Msg) const
00211 { m_Conn.process_notice(Msg); }
00213
00215 connection_base &conn() const { return m_Conn; }
00216
00218
00226 void set_variable(const PGSTD::string &Var, const PGSTD::string &Val);
00227
00229
00238 PGSTD::string get_variable(const PGSTD::string &);
00239
00240 #ifdef PQXX_DEPRECATED_HEADERS
00241
00245
00246 void Commit() PQXX_DEPRECATED { commit(); }
00248 void Abort() PQXX_DEPRECATED { abort(); }
00250 result Exec(const char Q[], const PGSTD::string &D=PGSTD::string())
00251 PQXX_DEPRECATED { return exec(Q,D); }
00253 result Exec(const PGSTD::string &Q, const PGSTD::string &D=PGSTD::string())
00254 PQXX_DEPRECATED { return exec(Q,D); }
00256 void ProcessNotice(const char M[]) const PQXX_DEPRECATED
00257 { return process_notice(M); }
00259 void ProcessNotice(const PGSTD::string &M) const PQXX_DEPRECATED
00260 { return process_notice(M); }
00262 PGSTD::string Name() const PQXX_DEPRECATED { return name(); }
00264 connection_base &Conn() const PQXX_DEPRECATED { return conn(); }
00266 void SetVariable(const PGSTD::string &Var, const PGSTD::string &Val)
00267 PQXX_DEPRECATED { set_variable(Var,Val); }
00269 #endif
00270
00271 protected:
00273
00278 explicit transaction_base(connection_base &, bool direct=true);
00279
00281
00283 void Begin();
00284
00286 void End() throw ();
00287
00289 virtual void do_begin() =0;
00291 virtual result do_exec(const char Query[]) =0;
00293 virtual void do_commit() =0;
00295 virtual void do_abort() =0;
00296
00297
00298
00300
00308 result DirectExec(const char C[], int Retries=0);
00309
00311 void reactivation_avoidance_clear() throw ()
00312 {m_reactivation_avoidance.clear();}
00313
00314 private:
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 enum Status
00335 {
00336 st_nascent,
00337 st_active,
00338 st_aborted,
00339 st_committed,
00340 st_in_doubt
00341 };
00342
00343
00344 void PQXX_PRIVATE CheckPendingError();
00345
00346 template<typename T> bool parm_is_null(T *p) const throw () { return !p; }
00347 template<typename T> bool parm_is_null(T) const throw () { return false; }
00348
00349 friend class Cursor;
00350 friend class cursor_base;
00351 void MakeEmpty(result &R) const { m_Conn.MakeEmpty(R); }
00352
00353 friend class internal::transactionfocus;
00354 void PQXX_PRIVATE RegisterFocus(internal::transactionfocus *);
00355 void PQXX_PRIVATE UnregisterFocus(internal::transactionfocus *) throw ();
00356 void PQXX_PRIVATE RegisterPendingError(const PGSTD::string &) throw ();
00357 friend class tablereader;
00358 void PQXX_PRIVATE BeginCopyRead(const PGSTD::string &, const PGSTD::string &);
00359 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00360 friend class tablewriter;
00361 void PQXX_PRIVATE BeginCopyWrite(const PGSTD::string &Table,
00362 const PGSTD::string &Columns = PGSTD::string());
00363 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00364 void EndCopyWrite() { m_Conn.EndCopyWrite(); }
00365
00366 friend class pipeline;
00367 void start_exec(const PGSTD::string &Q) { m_Conn.start_exec(Q); }
00368 internal::pq::PGresult *get_result() { return m_Conn.get_result(); }
00369 void consume_input() throw () { m_Conn.consume_input(); }
00370 bool is_busy() const throw () { return m_Conn.is_busy(); }
00371
00372 friend class prepare::invocation;
00373 result prepared_exec(const PGSTD::string &, const char *const[], int);
00374
00375 connection_base &m_Conn;
00376
00377 internal::unique<internal::transactionfocus> m_Focus;
00378 Status m_Status;
00379 bool m_Registered;
00380 PGSTD::map<PGSTD::string, PGSTD::string> m_Vars;
00381 PGSTD::string m_PendingError;
00382
00383 friend class subtransaction;
00385
00387 internal::reactivation_avoidance_counter m_reactivation_avoidance;
00388
00390 transaction_base();
00392 transaction_base(const transaction_base &);
00394 transaction_base &operator=(const transaction_base &);
00395 };
00396
00397 }
00398
00399
00400 #include "pqxx/compiler-internal-post.hxx"