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 result;
00042 class tablestream;
00043
00044
00046 template<> inline PGSTD::string Classname(const tablestream *)
00047 {
00048 return "tablestream";
00049 }
00050
00051
00053
00061 class PQXX_LIBEXPORT transaction_base
00062 {
00063
00064 public:
00066 typedef isolation_traits<read_committed> isolation_tag;
00067
00068 virtual ~transaction_base() =0;
00069
00071
00083 void commit();
00084
00086
00089 void abort();
00090
00092
00096 result exec(const char Query[],
00097 const PGSTD::string &Desc=PGSTD::string());
00098
00100
00107 result exec(const PGSTD::string &Query,
00108 const PGSTD::string &Desc=PGSTD::string())
00109 { return exec(Query.c_str(), Desc); }
00110
00112 void process_notice(const char Msg[]) const
00113 { m_Conn.process_notice(Msg); }
00115 void process_notice(const PGSTD::string &Msg) const
00116 { m_Conn.process_notice(Msg); }
00117
00118 PGSTD::string name() const { return m_Name; }
00119
00121 connection_base &conn() const { return m_Conn; }
00122
00124
00132 void set_variable(const PGSTD::string &Var, const PGSTD::string &Val);
00133
00134
00135 #ifdef PQXX_DEPRECATED_HEADERS
00136
00137 void Commit() { commit(); }
00139 void Abort() { abort(); }
00141 result Exec(const char Q[], const PGSTD::string &D=PGSTD::string())
00142 { return exec(Q,D); }
00144 result Exec(const PGSTD::string &Q, const PGSTD::string &D=PGSTD::string())
00145 { return exec(Q,D); }
00147 void ProcessNotice(const char M[]) const { return process_notice(M); }
00149 void ProcessNotice(const PGSTD::string &M) const { return process_notice(M); }
00151 PGSTD::string Name() const { return name(); }
00153 connection_base &Conn() const { return conn(); }
00155 void SetVariable(const PGSTD::string &Var, const PGSTD::string &Val)
00156 { set_variable(Var,Val); }
00157 #endif
00158
00159 protected:
00162 explicit transaction_base(connection_base &,
00163 const PGSTD::string &TName=PGSTD::string());
00164
00167 void Begin();
00168
00170 void End() throw ();
00171
00173 virtual void do_begin() =0;
00175 virtual result do_exec(const char Query[]) =0;
00177 virtual void do_commit() =0;
00179 virtual void do_abort() =0;
00180
00181
00182
00184 result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00185
00186 private:
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 enum Status
00205 {
00206 st_nascent,
00207 st_active,
00208 st_aborted,
00209 st_committed,
00210 st_in_doubt
00211 };
00212
00213
00214 friend class Cursor;
00215 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00216 void MakeEmpty(result &R) const { m_Conn.MakeEmpty(R); }
00217
00218 friend class tablestream;
00219 void RegisterStream(tablestream *);
00220 void UnregisterStream(tablestream *) throw ();
00221 void EndCopy() throw () { m_Conn.EndCopy(); }
00222 friend class tablereader;
00223 void BeginCopyRead(const PGSTD::string &Table)
00224 { m_Conn.BeginCopyRead(Table); }
00225 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00226 friend class tablewriter;
00227 void BeginCopyWrite(const PGSTD::string &Table)
00228 { m_Conn.BeginCopyWrite(Table); }
00229 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00230 void EndCopyWrite() throw () { m_Conn.EndCopyWrite(); }
00231
00232 connection_base &m_Conn;
00233
00234 PGSTD::string m_Name;
00235 int m_UniqueCursorNum;
00236 unique<tablestream> m_Stream;
00237 Status m_Status;
00238 bool m_Registered;
00239 mutable PGSTD::map<PGSTD::string, PGSTD::string> m_Vars;
00240
00241
00242 transaction_base();
00243 transaction_base(const transaction_base &);
00244 transaction_base &operator=(const transaction_base &);
00245 };
00246
00247
00248 }
00249
00250