This seems to be working... posting this in case it may help someone else with the same problem some day.

Handling the rollback at the app level, not the DB level, by rolling back each handle if anything fails.

It calls a function AllTables::handles that returns all handles to every CDBI class (this isn't part of CDBI, but it is easy to cache the handles when the classes are defined) -- rolling back every object is probably somewhat redundant and overkill, as handles are unique by database, not by table, but I think that redundancy does no harm.

sub do_transaction { my ($code) = @_; &transactions_on; eval { $code->() }; &rollback_and_die if $@; &commit; &transactions_off; } sub rollback_and_die { my $commit_error = $@; # save it as rollback could fail eval { $_->rollback foreach (AllTables::handles); }; &transactions_off; # just to be safe die $commit_error; # and fatal death } sub commit { eval { $_->commit foreach (AllTables::handles); }; &rollback_and_die if $@; # commit failed, so bail } sub transactions_on { $_->{AutoCommit} = 0 foreach (AllTables::handles); } sub transactions_off { $_->{AutoCommit} = 1 foreach (AllTables::handles); }

In reply to Re: CDBI and multiple databases by water
in thread CDBI and multiple databases by water

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.