00001 // database transaction convenience wrapper -*- C++ -*- 00002 // $Id: transaction.h,v 1.4 2004/01/07 14:29:39 roger Exp $ 00003 // 00004 // Copyright (C) 2003 Roger Leigh <rleigh@debian.org> 00005 // 00006 // 00007 // This program is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 #ifndef PQXX_OBJECT_TRANSACTION_H 00022 #define PQXX_OBJECT_TRANSACTION_H 00023 00024 #include <pqxx/connection> 00025 #include <pqxx/transaction> 00026 00027 #include <sigc++/signal.h> 00028 00029 #include <pqxx-object/exceptions.h> 00030 00031 namespace pqxxobject 00032 { 00046 class transaction 00047 { 00048 public: 00049 enum state 00050 { 00051 STATE_NONE, 00052 STATE_ABORTED, 00053 STATE_COMMITTED, 00054 STATE_EXECUTING 00055 }; 00056 00067 transaction(pqxx::connection& connection, 00068 pqxx::transaction<>*& transaction); 00069 00070 00072 virtual ~transaction(); 00073 00085 void begin(const std::string& name); 00086 00095 void end(); 00096 00104 pqxx::result exec(const std::string& query); 00105 00115 pqxx::result::size_type exec_noresult(const std::string& query); 00116 00135 pqxx::result::size_type perform(const std::string& query, 00136 pqxx::result::size_type min_rows, 00137 pqxx::result::size_type max_rows); 00138 00151 void commit(); 00152 00153 00165 void abort(); 00166 00167 SigC::Signal0<void>& signal_commit(); 00168 SigC::Signal0<void>& signal_abort(); 00169 00170 // PostgreSQL connection details 00172 pqxx::connection& m_connection; 00174 pqxx::transaction<>*& m_transaction; 00176 bool m_autocommit; 00177 00178 SigC::Signal0<void> m_signal_commit; 00179 SigC::Signal0<void> m_signal_abort; 00180 00181 state m_state; 00182 00183 }; // class transaction 00184 00185 }; // namespace pqxxobject 00186 00187 #endif // PQXX_OBJECT_TRANSACTION_H