Well, sorry to spam you all but I have a framework that appears to work, at
least without throwing errors. I've basically copied and pasted transaction,
except I had to pull in basic_transaction since it declared do_commit() as
private.
I've commented the two points at which I could throw errors... If anyone who
is knowledgeable about the library could give me some insight as to whether
this is a good way to implement this, or whether I'm doing something very
wrong, I'd be grateful. Thanks for enduring my previous post spam :D
I've put a //COULD THROW ERROR HERE
wherever I plan to throw errors.
// FlakyTransaction.h
#include <pqxx/connection_base>
#include <pqxx/result>
#include <pqxx/dbtransaction>
class FlakyTransaction : public pqxx::dbtransaction {
public:
explicit FlakyTransaction( pqxx::connection_base &C
, const PGSTD::string &Name=PGSTD::string() );
virtual ~FlakyTransaction();
private:
virtual void do_commit();
virtual pqxx::result do_exec(const char C[]);
};
//FlakyTransaction.cpp
#include "FlakyTransaction.h"
#include <pqxx/util>
using namespace PGSTD;
FlakyTransaction::FlakyTransaction( pqxx::connection_base &C
, const PGSTD::string &Name ) :
pqxx::internal::namedclass( "transaction"
, Name )
, pqxx::dbtransaction( C,
pqxx::isolation_traits<pqxx::read_committed>::name() ) {
}
FlakyTransaction::~FlakyTransaction() {
}
void FlakyTransaction::do_commit() {
//COULD THROW ERROR HERE
try {
DirectExec(pqxx::internal::sql_commit_work);
}
catch (const exception &e) {
if ( !conn().is_open() ) {
process_notice(e.what() + string("\n"));
const string Msg = "WARNING: "
"Connection lost while committing transaction "
"'" + name() + "'. "
"There is no way to tell whether the
transaction succeeded "
"or was aborted except to check manually.";
process_notice(Msg + "\n");
throw pqxx::in_doubt_error(Msg);
} else {
throw;
}
}
}
pqxx::result FlakyTransaction::do_exec(const char C[]) {
//COULD THROW ERROR HERE
return pqxx::dbtransaction::do_exec( C );
}
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general