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 transaction_base(C, NName),
00061 m_StartCmd()
00062 {
00063 if (IsolationString != isolation_traits<read_committed>::name())
00064 m_StartCmd = "SET TRANSACTION ISOLATION LEVEL " + IsolationString;
00065 }
00066
00068 void start_backend_transaction()
00069 {
00070 DirectExec("BEGIN", 2);
00071 if (!startcommand().empty()) DirectExec(startcommand().c_str());
00072 }
00073
00075 const PGSTD::string &startcommand() const { return m_StartCmd; }
00076
00077 #ifdef PQXX_DEPRECATED_HEADERS
00078
00079 const PGSTD::string &StartCmd() const { return startcommand(); }
00080 #endif
00081
00082 private:
00083
00085 virtual void do_begin() =0;
00087 virtual result do_exec(const char Query[]);
00089 virtual void do_commit() =0;
00091 virtual void do_abort() =0;
00092
00094 PGSTD::string m_StartCmd;
00095 };
00096
00098 template<> inline PGSTD::string Classname(const dbtransaction *)
00099 {
00100 return "dbtransaction";
00101 }
00102
00103
00104 inline result dbtransaction::do_exec(const char Query[])
00105 {
00106 result R;
00107 try
00108 {
00109 R = DirectExec(Query);
00110 }
00111 catch (const PGSTD::exception &)
00112 {
00113 try { abort(); } catch (const PGSTD::exception &) {}
00114 throw;
00115 }
00116 return R;
00117 }
00118
00119 }
00120