From: Nigel Metheringham Date: Fri, 7 Apr 2006 11:03:36 +0000 (+0000) Subject: Made storage txn_* functions log DBI operations to SQL debug trace X-Git-Tag: v0.06001~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=986e4fcaa25c60c5bc527e7f89a271138cf4752a;p=dbsrgits%2FDBIx-Class.git Made storage txn_* functions log DBI operations to SQL debug trace --- diff --git a/Changes b/Changes index 11d0595..c5f3186 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,7 @@ Revision history for DBIx::Class - slice now uses search directly - fixes for update() on resultset - bugfix to Cursor to avoid error during DESTROY + - transaction DBI operations now in debug trace output 0.06000 - Lots of documentation improvements diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index e103d44..8bcb424 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -420,8 +420,11 @@ an entire code block to be executed transactionally. sub txn_begin { my $self = shift; - $self->dbh->begin_work - if $self->{transaction_depth}++ == 0 and $self->dbh->{AutoCommit}; + if (($self->{transaction_depth}++ == 0) and ($self->dbh->{AutoCommit})) { + $self->debugfh->print("BEGIN WORK\n") + if ($self->debug); + $self->dbh->begin_work; + } } =head2 txn_commit @@ -433,10 +436,18 @@ Issues a commit against the current dbh. sub txn_commit { my $self = shift; if ($self->{transaction_depth} == 0) { - $self->dbh->commit unless $self->dbh->{AutoCommit}; + unless ($self->dbh->{AutoCommit}) { + $self->debugfh->print("COMMIT\n") + if ($self->debug); + $self->dbh->commit; + } } else { - $self->dbh->commit if --$self->{transaction_depth} == 0; + if (--$self->{transaction_depth} == 0) { + $self->debugfh->print("COMMIT\n") + if ($self->debug); + $self->dbh->commit; + } } } @@ -453,12 +464,21 @@ sub txn_rollback { eval { if ($self->{transaction_depth} == 0) { - $self->dbh->rollback unless $self->dbh->{AutoCommit}; + unless ($self->dbh->{AutoCommit}) { + $self->debugfh->print("ROLLBACK\n") + if ($self->debug); + $self->dbh->rollback; + } } else { - --$self->{transaction_depth} == 0 ? - $self->dbh->rollback : + if (--$self->{transaction_depth} == 0) { + $self->debugfh->print("ROLLBACK\n") + if ($self->debug); + $self->dbh->rollback; + } + else { die DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION->new; + } } };