00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PQXX_TRANSACTION_BASE_H
00020 #define PQXX_TRANSACTION_BASE_H
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "pqxx/connection_base.h"
00033 #include "pqxx/isolation.h"
00034 #include "pqxx/result.h"
00035
00036
00037
00038
00039
00040 namespace pqxx
00041 {
00042 class connection_base;
00043 class result;
00044 class tablestream;
00045
00046
00048 template<> inline PGSTD::string Classname(const tablestream *)
00049 {
00050 return "tablestream";
00051 }
00052
00053
00055
00063 class PQXX_LIBEXPORT transaction_base
00064 {
00065
00066
00067
00068 public:
00070 typedef isolation_traits<read_committed> isolation_tag;
00071
00072 virtual ~transaction_base() =0;
00073
00075
00087 void Commit();
00088
00090
00093 void Abort();
00094
00096
00100 result Exec(const char Query[],
00101 const PGSTD::string &Desc=PGSTD::string());
00102
00104
00111 result Exec(const PGSTD::string &Query,
00112 const PGSTD::string &Desc=PGSTD::string())
00113 { return Exec(Query.c_str(), Desc); }
00114
00116 void ProcessNotice(const char Msg[]) const
00117 { m_Conn.ProcessNotice(Msg); }
00119 void ProcessNotice(const PGSTD::string &Msg) const
00120 { m_Conn.ProcessNotice(Msg); }
00121
00122 PGSTD::string Name() const { return m_Name; }
00123
00125 connection_base &Conn() const { return m_Conn; }
00126
00128
00136 void SetVariable(const PGSTD::string &Var, const PGSTD::string &Value);
00137
00138
00139 protected:
00142 explicit transaction_base(connection_base &,
00143 const PGSTD::string &TName=PGSTD::string());
00144
00147 void Begin();
00148
00150 void End() throw ();
00151
00153 virtual void DoBegin() =0;
00155 virtual result DoExec(const char Query[]) =0;
00157 virtual void DoCommit() =0;
00159 virtual void DoAbort() =0;
00160
00161
00162
00164 result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00165
00166 private:
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 enum Status
00185 {
00186 st_nascent,
00187 st_active,
00188 st_aborted,
00189 st_committed,
00190 st_in_doubt
00191 };
00192
00193
00194 friend class Cursor;
00195 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00196 void MakeEmpty(result &R) const { m_Conn.MakeEmpty(R); }
00197
00198 friend class tablestream;
00199 void RegisterStream(tablestream *);
00200 void UnregisterStream(tablestream *) throw ();
00201 void EndCopy() { m_Conn.EndCopy(); }
00202 friend class tablereader;
00203 void BeginCopyRead(const PGSTD::string &Table)
00204 { m_Conn.BeginCopyRead(Table); }
00205 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00206 friend class tablewriter;
00207 void BeginCopyWrite(const PGSTD::string &Table)
00208 { m_Conn.BeginCopyWrite(Table); }
00209 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00210
00211 connection_base &m_Conn;
00212
00213 PGSTD::string m_Name;
00214 int m_UniqueCursorNum;
00215 unique<tablestream> m_Stream;
00216 Status m_Status;
00217 bool m_Registered;
00218 mutable PGSTD::map<PGSTD::string, PGSTD::string> m_Vars;
00219
00220
00221 transaction_base();
00222 transaction_base(const transaction_base &);
00223 transaction_base &operator=(const transaction_base &);
00224 };
00225
00226
00227 }
00228
00229 #endif
00230