00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PQXX_TRANSACTIONITF_H
00016 #define PQXX_TRANSACTIONITF_H
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "pqxx/connectionitf.h"
00030 #include "pqxx/result.h"
00031
00032
00033
00034
00035
00036 namespace pqxx
00037 {
00038 class ConnectionItf;
00039 class Result;
00040 class TableStream;
00041
00042
00043 template<> inline PGSTD::string Classname(const TableStream *)
00044 {
00045 return "TableStream";
00046 }
00047
00048
00050
00058 class PQXX_LIBEXPORT TransactionItf
00059 {
00060 public:
00061 virtual ~TransactionItf() =0;
00062
00064
00076 void Commit();
00077
00079
00082 void Abort();
00083
00085
00089 Result Exec(const char Query[],
00090 const PGSTD::string &Desc=PGSTD::string());
00091
00093
00100 Result Exec(const PGSTD::string &Query,
00101 const PGSTD::string &Desc=PGSTD::string())
00102 { return Exec(Query.c_str(), Desc); }
00103
00105 void ProcessNotice(const char Msg[]) const
00106 { m_Conn.ProcessNotice(Msg); }
00108 void ProcessNotice(const PGSTD::string &Msg) const
00109 { m_Conn.ProcessNotice(Msg); }
00110
00111 PGSTD::string Name() const { return m_Name; }
00112
00114 ConnectionItf &Conn() const { return m_Conn; }
00115
00117
00125 void SetVariable(const PGSTD::string &Var, const PGSTD::string &Value);
00126
00127
00128 protected:
00131 explicit TransactionItf(ConnectionItf &,
00132 const PGSTD::string &TName=PGSTD::string());
00133
00136 void Begin();
00137
00139 void End() throw ();
00140
00142 virtual void DoBegin() =0;
00143 virtual Result DoExec(const char Query[]) =0;
00144 virtual void DoCommit() =0;
00145 virtual void DoAbort() =0;
00146
00147
00148
00150 Result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00151
00152 private:
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 enum Status
00171 {
00172 st_nascent,
00173 st_active,
00174 st_aborted,
00175 st_committed,
00176 st_in_doubt
00177 };
00178
00179
00180 friend class Cursor;
00181 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00182 void MakeEmpty(Result &R) const { m_Conn.MakeEmpty(R); }
00183
00184 friend class TableStream;
00185 void RegisterStream(TableStream *);
00186 void UnregisterStream(TableStream *) throw ();
00187 void EndCopy() { m_Conn.EndCopy(); }
00188 friend class TableReader;
00189 void BeginCopyRead(const PGSTD::string &Table)
00190 { m_Conn.BeginCopyRead(Table); }
00191 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00192 friend class TableWriter;
00193 void BeginCopyWrite(const PGSTD::string &Table)
00194 { m_Conn.BeginCopyWrite(Table); }
00195 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00196
00197 ConnectionItf &m_Conn;
00198
00199 PGSTD::string m_Name;
00200 int m_UniqueCursorNum;
00201 Unique<TableStream> m_Stream;
00202 Status m_Status;
00203 bool m_Registered;
00204 mutable PGSTD::map<PGSTD::string, PGSTD::string> m_Vars;
00205
00206
00207 TransactionItf();
00208 TransactionItf(const TransactionItf &);
00209 TransactionItf &operator=(const TransactionItf &);
00210 };
00211
00212
00213 }
00214
00215 #endif
00216