00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "pqxx/connection_base"
00031 #include "pqxx/isolation"
00032 #include "pqxx/result"
00033
00034
00035
00036
00037
00038 namespace pqxx
00039 {
00040 class connection_base;
00041 class transaction_base;
00042
00043
00044 namespace internal
00045 {
00046 class PQXX_LIBEXPORT transactionfocus : public namedclass
00047 {
00048 public:
00049 transactionfocus(transaction_base &t,
00050 const PGSTD::string &Name,
00051 const PGSTD::string &Classname) :
00052 namedclass(Name, Classname),
00053 m_Trans(t)
00054 {
00055 }
00056
00057 protected:
00058 void register_me();
00059 void unregister_me() throw ();
00060 void reg_pending_error(const PGSTD::string &) throw ();
00061
00062 transaction_base &m_Trans;
00063
00064 private:
00066 transactionfocus();
00068 transactionfocus(const transactionfocus &);
00070 transactionfocus &operator=(const transactionfocus &);
00071 };
00072 }
00073
00074
00075
00077
00085 class PQXX_LIBEXPORT transaction_base : public internal::namedclass
00086 {
00087
00088 public:
00090 typedef isolation_traits<read_committed> isolation_tag;
00091
00092 virtual ~transaction_base() =0;
00093
00095
00107 void commit();
00108
00110
00113 void abort();
00114
00116
00120 result exec(const char Query[],
00121 const PGSTD::string &Desc=PGSTD::string());
00122
00124
00131 result exec(const PGSTD::string &Query,
00132 const PGSTD::string &Desc=PGSTD::string())
00133 { return exec(Query.c_str(), Desc); }
00134
00136 void process_notice(const char Msg[]) const
00137 { m_Conn.process_notice(Msg); }
00139 void process_notice(const PGSTD::string &Msg) const
00140 { m_Conn.process_notice(Msg); }
00141
00143 connection_base &conn() const { return m_Conn; }
00144
00146
00154 void set_variable(const PGSTD::string &Var, const PGSTD::string &Val);
00155
00157
00163 PGSTD::string get_variable(const PGSTD::string &) const;
00164
00165 #ifdef PQXX_DEPRECATED_HEADERS
00166
00167 void Commit() { commit(); }
00169 void Abort() { abort(); }
00171 result Exec(const char Q[], const PGSTD::string &D=PGSTD::string())
00172 { return exec(Q,D); }
00174 result Exec(const PGSTD::string &Q, const PGSTD::string &D=PGSTD::string())
00175 { return exec(Q,D); }
00177 void ProcessNotice(const char M[]) const { return process_notice(M); }
00179 void ProcessNotice(const PGSTD::string &M) const { return process_notice(M); }
00181 PGSTD::string Name() const { return name(); }
00183 connection_base &Conn() const { return conn(); }
00185 void SetVariable(const PGSTD::string &Var, const PGSTD::string &Val)
00186 { set_variable(Var,Val); }
00187 #endif
00188
00189 protected:
00191
00194 explicit transaction_base(connection_base &,
00195 const PGSTD::string &TName,
00196 const PGSTD::string &CName);
00197
00199
00201 void Begin();
00202
00204 void End() throw ();
00205
00207 virtual void do_begin() =0;
00209 virtual result do_exec(const char Query[]) =0;
00211 virtual void do_commit() =0;
00213 virtual void do_abort() =0;
00214
00215
00216
00218
00226 result DirectExec(const char C[], int Retries=0);
00227
00228 private:
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 enum Status
00247 {
00248 st_nascent,
00249 st_active,
00250 st_aborted,
00251 st_committed,
00252 st_in_doubt
00253 };
00254
00255
00256 void CheckPendingError();
00257
00258 friend class Cursor;
00259 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00260 void MakeEmpty(result &R) const { m_Conn.MakeEmpty(R); }
00261
00262 friend class internal::transactionfocus;
00263 void RegisterFocus(internal::transactionfocus *);
00264 void UnregisterFocus(internal::transactionfocus *) throw ();
00265 void RegisterPendingError(const PGSTD::string &) throw ();
00266 friend class tablereader;
00267 void BeginCopyRead(const PGSTD::string &Table);
00268 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00269 friend class tablewriter;
00270 void BeginCopyWrite(const PGSTD::string &Table);
00271 bool WriteCopyLine(const PGSTD::string &L, bool async=false)
00272 { return m_Conn.WriteCopyLine(L, async); }
00273 void EndCopyWrite() throw () { m_Conn.EndCopyWrite(); }
00274
00275 friend class pipeline;
00276 void start_exec(const PGSTD::string &Q) { m_Conn.start_exec(Q); }
00277 PGresult *get_result() { return m_Conn.get_result(); }
00278
00279 connection_base &m_Conn;
00280
00281 int m_UniqueCursorNum;
00282 internal::unique<internal::transactionfocus> m_Focus;
00283 Status m_Status;
00284 bool m_Registered;
00285 mutable PGSTD::map<PGSTD::string, PGSTD::string> m_Vars;
00286 PGSTD::string m_PendingError;
00287
00289 transaction_base();
00291 transaction_base(const transaction_base &);
00293 transaction_base &operator=(const transaction_base &);
00294 };
00295
00296 }
00297
00298