My attempt did not work as get errors such as these:
WARN: Aborted query attempt. Reason: 'Started transaction<READ COMMITTED>
while FlakyTransaction 'IMQM::DoNotCallAddDbTransactor' still active' query:
FlakyTransaction 'IMQM::DoNotCallAddDbTransactor' was never closed properly!
Anways, tips or a quick template would be greatly appreciated.
Thanks, Josh
On Wednesday 03 January 2007 18:19, Joshua Moore-Oliva wrote:
> I am currently making use of your transactor framework (love it!), but I
> really want to *test* my programs functionality when an abort or doubt
> arises (Sometimes a doubt doesn't matter, and I do the query again, other
> times I have to check manually if the query really went through or not).
>
> I want to make either a custom transaction or connection that can simulate
> an abort or doubt to
>
> template<typename TRANSACTOR>
> inline void pqxx::connection_base::perform(const TRANSACTOR &T,
> int Attempts)
> {
>
> to make sure that my program continues to operate correctly.
>
> I'd really like some guidance as to where would be the correct spot to
> insert some code to do this. My first idea was to make a dummy transaction
> (copy nontransaction) and have a real transaction as a member... and then
> either pump queries into the real transaction or throw exceptions depending
> on what I needed to do. My question is really, what should I delete from
> nontransaction to make it not do anything and just pump queries through to
> another underlying transaction? What should I be on the lookup for? Any
> hints are appreciated, and if it's not too much work, a quick class example
> where queries were pumped to a member transaction would be awesome. Here
> is roughly what I am looking to do. It compiles, but I haven't tested it.
>
> If the following looks good, then I'll add in functionality to send out
> abort or doubt errors. Maybe you'll like it enough to add it in as a
> utility for testing.
>
> Code follows.
>
>
> //FlakyTransaction.h
> /*#include "pqxx/compiler-public.hxx"
> #include "pqxx/compiler-internal-pre.hxx"*/
>
> #include "pqxx/connection_base"
> #include "pqxx/result"
> #include "pqxx/transaction_base"
> #include "pqxx/transaction"
> #include "pqxx/util"
>
> /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
> */
>
>
> class FlakyTransaction : public pqxx::transaction_base {
> public:
> explicit FlakyTransaction( pqxx::connection_base &C
> , const PGSTD::string &Name=PGSTD::string() )
> : pqxx::internal::namedclass( "FlakyTransaction"
> , Name )
> , pqxx::transaction_base( C ) /*THIS WORRIES ME: Is it a problem
> that C is going to two different transactions?*/
> , m_t( C ) {
> Begin();
> }
>
> virtual ~FlakyTransaction();
>
> private:
> pqxx::work m_t;
> virtual void do_begin() {}
> virtual pqxx::result do_exec(const char C[]);
> virtual void do_commit() { this->m_t.commit(); }
> virtual void do_abort() {}
> };
>
> //#include "pqxx/compiler-internal-post.hxx"
>
> ////FlakyTransaction.cpp
>
> #include "FlakyTransaction.h"
>
>
> using namespace PGSTD;
>
> FlakyTransaction::~FlakyTransaction() {
> End();
> }
>
>
> pqxx::result FlakyTransaction::do_exec( const char Query[] ) {
> return this->m_t.exec( Query );
> }
>
>
> _______________________________________________
> Libpqxx-general mailing list
> [email protected]
> http://gborg.postgresql.org/mailman/listinfo/libpqxx-general
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general