X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=43d5bf0d3ed94526451a1886f38ace1f022db68b;hb=60283c2e81a0c2ec3ef9ee94350f1a620291e65a;hp=b87648af2d3f022e7af339366846581575ff3f78;hpb=e8d293dfb0a738b6ad37f9ce500f517a247c5289;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index b87648a..43d5bf0 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1,5 +1,7 @@ package DBIx::Class::Storage::DBI; +use base 'DBIx::Class::Storage'; + use strict; use warnings; use DBI; @@ -145,16 +147,7 @@ sub _join_condition { sub _quote { my ($self, $label) = @_; return '' unless defined $label; - return "*" if $label eq '*'; return $label unless $self->{quote_char}; - if(ref $self->{quote_char} eq "ARRAY"){ - return $self->{quote_char}->[0] . $label . $self->{quote_char}->[1] - if !defined $self->{name_sep}; - my $sep = $self->{name_sep}; - return join($self->{name_sep}, - map { $self->{quote_char}->[0] . $_ . $self->{quote_char}->[1] } - split(/\Q$sep\E/,$label)); - } return $self->SUPER::_quote($label); } @@ -301,8 +294,10 @@ sub ensure_connected { sub dbh { my ($self) = @_; - $self->_dbh(undef) - if $self->_connection_pid && $self->_connection_pid != $$; + if($self->_connection_pid && $self->_connection_pid != $$) { + $self->_dbh->{InactiveDestroy} = 1; + $self->_dbh(undef) + } $self->ensure_connected; return $self->_dbh; } @@ -353,11 +348,15 @@ sub _connect { Calls begin_work on the current dbh. +See L for the txn_do() method, which allows for +an entire code block to be executed transactionally. + =cut sub txn_begin { my $self = shift; - $self->dbh->begin_work if $self->{transaction_depth}++ == 0 and $self->dbh->{AutoCommit}; + $self->dbh->begin_work + if $self->{transaction_depth}++ == 0 and $self->dbh->{AutoCommit}; } =head2 txn_commit @@ -378,17 +377,32 @@ sub txn_commit { =head2 txn_rollback -Issues a rollback against the current dbh. +Issues a rollback against the current dbh. A nested rollback will +throw a L exception, +which allows the rollback to propagate to the outermost transaction. =cut sub txn_rollback { my $self = shift; - if ($self->{transaction_depth} == 0) { - $self->dbh->rollback unless $self->dbh->{AutoCommit}; - } - else { - --$self->{transaction_depth} == 0 ? $self->dbh->rollback : die $@; + + eval { + if ($self->{transaction_depth} == 0) { + $self->dbh->rollback unless $self->dbh->{AutoCommit}; + } + else { + --$self->{transaction_depth} == 0 ? + $self->dbh->rollback : + die DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION->new; + } + }; + + if ($@) { + my $error = $@; + my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION"; + $error =~ /$exception_class/ and $self->throw_exception($error); + $self->{transaction_depth} = 0; # ensure that a failed rollback + $self->throw_exception($error); # resets the transaction depth } } @@ -397,8 +411,8 @@ sub _execute { my ($sql, @bind) = $self->sql_maker->$op($ident, @args); unshift(@bind, @$extra_bind) if $extra_bind; if ($self->debug) { - my @debug_bind = map { defined $_ ? $_ : 'NULL' } @bind; - $self->debugfh->print("$sql: @debug_bind\n"); + my @debug_bind = map { defined $_ ? qq{`$_'} : q{`NULL'} } @bind; + $self->debugfh->print("$sql: " . join(', ', @debug_bind) . "\n"); } my $sth = $self->sth($sql,$op); $self->throw_exception("no sth generated via sql: $sql") unless $sth;