00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <string>
00020
00021 #include "pqxx/transaction_base"
00022
00023 namespace pqxx
00024 {
00025
00027
00054 class PQXX_LIBEXPORT dbtransaction : public transaction_base
00055 {
00056 protected:
00057 explicit dbtransaction(connection_base &C,
00058 const PGSTD::string &IsolationString,
00059 const PGSTD::string &NName,
00060 const PGSTD::string &CName) :
00061 transaction_base(C, NName, CName),
00062 m_StartCmd()
00063 {
00064 if (IsolationString != isolation_traits<read_committed>::name())
00065 m_StartCmd = "SET TRANSACTION ISOLATION LEVEL " + IsolationString;
00066 }
00067
00069 void start_backend_transaction()
00070 {
00071 DirectExec("BEGIN", 2);
00072 if (!startcommand().empty()) DirectExec(startcommand().c_str());
00073 }
00074
00076 const PGSTD::string &startcommand() const { return m_StartCmd; }
00077
00078 #ifdef PQXX_DEPRECATED_HEADERS
00079
00080 const PGSTD::string &StartCmd() const { return startcommand(); }
00081 #endif
00082
00083 private:
00084
00086 virtual void do_begin() =0;
00088 virtual result do_exec(const char Query[]);
00090 virtual void do_commit() =0;
00092 virtual void do_abort() =0;
00093
00095 PGSTD::string m_StartCmd;
00096 };
00097
00098
00099 inline result dbtransaction::do_exec(const char Query[])
00100 {
00101 result R;
00102 try
00103 {
00104 R = DirectExec(Query);
00105 }
00106 catch (const PGSTD::exception &)
00107 {
00108 try { abort(); } catch (const PGSTD::exception &) {}
00109 throw;
00110 }
00111 return R;
00112 }
00113
00114 }
00115