X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI.pm;h=015fa3ee566744129456243c6b949dfae5658e54;hb=90ec6cad73fe820d3e03fdbf2f13b6b841c42096;hp=657c91923c009799d59f6e5b0faa9ce6c59296ee;hpb=892d77688a0fee5ce467c9d27e3c78f3ff2545ce;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 657c919..015fa3e 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -303,8 +303,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; } @@ -337,17 +339,25 @@ sub _populate_dbh { sub _connect { my ($self, @info) = @_; + my ($old_connect_via, $dbh); + if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) { - my $old_connect_via = $DBI::connect_via; + $old_connect_via = $DBI::connect_via; $DBI::connect_via = 'connect'; - my $dbh = DBI->connect(@info); - $DBI::connect_via = $old_connect_via; - return $dbh; } - my $dbh = DBI->connect(@info); + if(ref $info[0] eq 'CODE') { + $dbh = &{$info[0]}; + } + else { + $dbh = DBI->connect(@info); + } + + $DBI::connect_via = $old_connect_via if $old_connect_via; + $self->throw_exception("DBI Connection failed: $DBI::errstr") unless $dbh; + $dbh; } @@ -355,11 +365,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 @@ -380,7 +394,9 @@ 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 @@ -412,8 +428,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; @@ -522,12 +538,7 @@ sub last_insert_id { } -sub sqlt_type { - my ($self) = @_; - my $dsn = $self->connect_info->[0]; - $dsn =~ /^dbi:(.*?)\d*:/; - return $1; -} +sub sqlt_type { shift->dbh->{Driver}->{Name} } sub deployment_statements { my ($self, $schema, $type) = @_;