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
00070 #ifdef PQXX_DEPRECATED_HEADERS
00071
00072 void Commit() { commit(); }
00074 void Abort() { abort(); }
00075 #endif
00076
00078
00090 void commit();
00091
00093
00096 void abort();
00097
00098 #ifdef PQXX_DEPRECATED_HEADERS
00099
00100 result Exec(const char Q[], const PGSTD::string &D=PGSTD::string())
00101 { return exec(Q,D); }
00103 result Exec(const PGSTD::string &Q, const PGSTD::string &D=PGSTD::string())
00104 { return exec(Q,D); }
00105 #endif
00106
00108
00112 result exec(const char Query[],
00113 const PGSTD::string &Desc=PGSTD::string());
00114
00116
00123 result exec(const PGSTD::string &Query,
00124 const PGSTD::string &Desc=PGSTD::string())
00125 { return exec(Query.c_str(), Desc); }
00126
00127 #ifdef PQXX_DEPRECATED_HEADERS
00128
00129 void ProcessNotice(const char M[]) const { return process_notice(M); }
00131 void ProcessNotice(const PGSTD::string &M) const { return process_notice(M); }
00132 #endif
00133
00135 void process_notice(const char Msg[]) const
00136 { m_Conn.process_notice(Msg); }
00138 void process_notice(const PGSTD::string &Msg) const
00139 { m_Conn.process_notice(Msg); }
00140
00141 #ifdef PQXX_DEPRECATED_HEADERS
00142
00143 PGSTD::string Name() const { return name(); }
00144
00146 connection_base &Conn() const { return conn(); }
00147 #endif
00148
00149 PGSTD::string name() const { return m_Name; }
00150
00152 connection_base &conn() const { return m_Conn; }
00153
00154 #ifdef PQXX_DEPRECATED_HEADERS
00155
00156 void SetVariable(const PGSTD::string &Var, const PGSTD::string &Val)
00157 { set_variable(Var,Val); }
00158 #endif
00159
00161
00169 void set_variable(const PGSTD::string &Var, const PGSTD::string &Val);
00170
00171
00172 protected:
00175 explicit transaction_base(connection_base &,
00176 const PGSTD::string &TName=PGSTD::string());
00177
00180 void Begin();
00181
00183 void End() throw ();
00184
00186 virtual void do_begin() =0;
00188 virtual result do_exec(const char Query[]) =0;
00190 virtual void do_commit() =0;
00192 virtual void do_abort() =0;
00193
00194
00195
00197 result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00198
00199 private:
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 enum Status
00218 {
00219 st_nascent,
00220 st_active,
00221 st_aborted,
00222 st_committed,
00223 st_in_doubt
00224 };
00225
00226
00227 friend class Cursor;
00228 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00229 void MakeEmpty(result &R) const { m_Conn.MakeEmpty(R); }
00230
00231 friend class tablestream;
00232 void RegisterStream(tablestream *);
00233 void UnregisterStream(tablestream *) throw ();
00234 void EndCopy() throw () { m_Conn.EndCopy(); }
00235 friend class tablereader;
00236 void BeginCopyRead(const PGSTD::string &Table)
00237 { m_Conn.BeginCopyRead(Table); }
00238 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00239 friend class tablewriter;
00240 void BeginCopyWrite(const PGSTD::string &Table)
00241 { m_Conn.BeginCopyWrite(Table); }
00242 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00243
00244 connection_base &m_Conn;
00245
00246 PGSTD::string m_Name;
00247 int m_UniqueCursorNum;
00248 unique<tablestream> m_Stream;
00249 Status m_Status;
00250 bool m_Registered;
00251 mutable PGSTD::map<PGSTD::string, PGSTD::string> m_Vars;
00252
00253
00254 transaction_base();
00255 transaction_base(const transaction_base &);
00256 transaction_base &operator=(const transaction_base &);
00257 };
00258
00259
00260 }
00261
00262