Re: undefined behaviour for sub-transactions?
Tim Bunce <[email protected]>
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Nov 14, 2005 at 11:41:42PM -0800, Tyler MacDonald wrote: > Jochen Wiedmann <[email protected]> wrote: > > > Is there a way to ask DBI if it is already in a transaction? > > Read the AutCommit flag. :-) > > It says, > > Enable transactions (by turning "AutoCommit" off) until the next > call to "commit" or "rollback". After the next "commit" or "roll- > back", "AutoCommit" will automatically be turned on again. > If "AutoCommit" is already off when "begin_work" is called then it > does nothing except return an error. If the driver does not support > transactions then when "begin_work" attempts to set "AutoCommit" > off the driver will trigger a fatal error. > > However, when using the DBD::Pg driver, begin_work only triggers an error if > the driver was *initialized* with AutoCommit off, and if you begin_work with > AutoCommit on, the next query to $dbh->{AutoCommit} still returns true, and > transactions nest successfully. So is the DBD::Pg driver in error then? Looks like it. > (In other words, there's no support for nested transactions in DBI at all?) REAL nested transactions, i.e., creating savepoints and rolling back to savepoints, are done via SQL. So the DBI supports nested transactions just as much as it supports SELECT statements. You refer later to the DBI::Transaction module in CPAN. I've looked at it and it's not clear to me what it's trying to achieve (or even why or how) but perhaps I'm being extra dense today. I'll guess that what you're really after is to be able to call begin_work again whilst an earlier begin_work is in effect and have the DBI keep a counter of how deeply nested the begin_work calls are. Then commit would decrement the counter and only commit at the outer most level. sub foo { begin_work ... commit # doesn't actually commit here if called from bar() } sub bar { begin_work ... foo() ... commit } If you really want that then it's straightforward to implement via a subclass. Tim. -- MySQL Perl Mailing List For list archives: http://lists.mysql.com/perl To unsubscribe: http://lists.mysql.com/[email protected]