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
00054 class PQXX_LIBEXPORT TransactionItf
00055 {
00056 public:
00057 virtual ~TransactionItf() =0;
00058
00059 void Commit();
00060 void Abort();
00061
00063 Result Exec(const char[]);
00064
00066 Result Exec(const PGSTD::string &Q) { return Exec(Q.c_str()); }
00067
00069 void ProcessNotice(const char Msg[]) { m_Conn.ProcessNotice(Msg); }
00071
00072 { m_Conn.ProcessNotice(Msg); }
00073
00074 PGSTD::string Name() const { return m_Name; }
00075
00077 ConnectionItf &Conn() const { return m_Conn; }
00078
00079 protected:
00082 explicit TransactionItf(ConnectionItf &,
00083 const PGSTD::string &TName=PGSTD::string());
00084
00087 void Begin();
00088
00090 void End() throw ();
00091
00093 virtual void DoBegin() =0;
00094 virtual Result DoExec(const char C[]) =0;
00095 virtual void DoCommit() =0;
00096 virtual void DoAbort() =0;
00097
00098
00099
00101 Result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00102
00103 private:
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 enum Status
00122 {
00123 st_nascent,
00124 st_active,
00125 st_aborted,
00126 st_committed,
00127 st_in_doubt
00128 };
00129
00130
00131 friend class Cursor;
00132 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00133 void MakeEmpty(Result &R) const { m_Conn.MakeEmpty(R); }
00134
00135 friend class TableStream;
00136 void RegisterStream(const TableStream *);
00137 void UnregisterStream(const TableStream *) throw ();
00138 void EndCopy() { m_Conn.EndCopy(); }
00139 friend class TableReader;
00140 void BeginCopyRead(const PGSTD::string &Table)
00141 { m_Conn.BeginCopyRead(Table); }
00142 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00143 friend class TableWriter;
00144 void BeginCopyWrite(const PGSTD::string &Table)
00145 { m_Conn.BeginCopyWrite(Table); }
00146 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00147
00148 ConnectionItf &m_Conn;
00149
00150 PGSTD::string m_Name;
00151 int m_UniqueCursorNum;
00152 Unique<TableStream> m_Stream;
00153 Status m_Status;
00154 bool m_Registered;
00155
00156
00157 TransactionItf();
00158 TransactionItf(const TransactionItf &);
00159 TransactionItf &operator=(const TransactionItf &);
00160 };
00161
00162
00164
00170 class PQXX_LIBEXPORT in_doubt_error : public PGSTD::runtime_error
00171 {
00172 public:
00173 explicit in_doubt_error(const PGSTD::string &whatarg) :
00174 PGSTD::runtime_error(whatarg) {}
00175 };
00176
00177 }
00178
00179 #endif
00180