I saw the thread in late June about nested transactions and
John's response that:
"Nested transactions are not supported by RDBO. If a
database handle is already in a transaction, RDBO will
not start a new one, nor will it commit the existing one."
I think that's referring to actual nested transactions
at the db-level, correct?
What about nested transactions at the app level? For example,
here's a nested call to do_transaction(). I expect this to
result in a rollback.
my $dbh = $db->dbh or die;
$db->do_transaction(sub {
$db->do_transaction(sub {
$dbh->do("UPDATE users SET email = 'fooblort' WHERE user_id = 1");
}) or die "inner trx failed";
die "outer trx";
}) or die "trx failed: " . $db->error;
This issues a commit though.
2007-07-09 15:37:48 PDT LOG: duration: 0.196 ms statement: begin
2007-07-09 15:37:48 PDT LOG: duration: 14.546 ms statement: UPDATE
users SET email = 'fooblort' WHERE user_id = 1
2007-07-09 15:37:48 PDT LOG: duration: 0.275 ms statement: commit
Is there any reason not to support nested transactions at the app
level? I find them very useful. Otherwise you have to make sure your
transactions are always at the top-level, which makes things more
error-prone, IMO.
Take the example that's shown in Rose::DB, for example, of a balance
transfer. I'd expect to wrap that into stand-alone method. Something
like Account->do_transfer($amt, $id1, $id2).
I don't want to have to remember to use do_transaction
around every call to do_transfer() though, so I place the
do_transaction() within do_transfer() itself.
But now I need nested transactions if I'd going to make do_transfer()
part of a larger transaction.
How do you guys handle that?
Maurice
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object