From: Brandon L. Black Date: Wed, 13 Sep 2006 22:04:10 +0000 (+0000) Subject: Storage::DBI::Cursor now makes use of the new Storage::DBI exception stuff instead... X-Git-Tag: v0.08010~43^2~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dbaee7482fe6ff190e8ae53d609d0294b911339b;p=dbsrgits%2FDBIx-Class.git Storage::DBI::Cursor now makes use of the new Storage::DBI exception stuff instead of manually checking $$/threads->tid for itself --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index a4abf35..ff7c9cd 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -305,6 +305,7 @@ sub new { $new->transaction_depth(0); $new->_sql_maker_opts({}); $new->{_in_dbh_do} = 0; + $new->{_dbh_gen} = 0; $new; } @@ -590,6 +591,7 @@ sub disconnect { $self->_dbh->rollback unless $self->_dbh->{AutoCommit}; $self->_dbh->disconnect; $self->_dbh(undef); + $self->{_dbh_gen}++; } } @@ -598,7 +600,9 @@ sub connected { if(my $dbh = $self->_dbh) { if(defined $self->_conn_tid && $self->_conn_tid != threads->tid) { - return $self->_dbh(undef); + $self->_dbh(undef); + $self->{_dbh_gen}++; + return; } else { $self->_verify_pid; @@ -618,6 +622,7 @@ sub _verify_pid { $self->_dbh->{InactiveDestroy} = 1; $self->_dbh(undef); + $self->{_dbh_gen}++; return; } diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index 770608c..c9dedf6 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -43,11 +43,9 @@ sub new { args => $args, pos => 0, attrs => $attrs, - pid => $$, + _dbh_gen => $storage->{_dbh_gen}, }; - $new->{tid} = threads->tid if $INC{'threads.pm'}; - return bless ($new, $class); } @@ -65,10 +63,10 @@ Advances the cursor to the next row and returns an arrayref of column values. =cut -sub next { - my ($self) = @_; +sub _dbh_next { + my ($storage, $dbh, $self) = @_; - $self->_check_forks_threads; + $self->_check_dbh_gen; if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) { $self->{sth}->finish if $self->{sth}->{Active}; delete $self->{sth}; @@ -76,7 +74,7 @@ sub next { } return if $self->{done}; unless ($self->{sth}) { - $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1]; + $self->{sth} = ($storage->_select(@{$self->{args}}))[1]; if ($self->{attrs}{software_limit}) { if (my $offset = $self->{attrs}{offset}) { $self->{sth}->fetch for 1 .. $offset; @@ -93,6 +91,11 @@ sub next { return @row; } +sub next { + my ($self) = @_; + $self->{storage}->dbh_do($self->can('_dbh_next'), $self); +} + =head2 all =over 4 @@ -108,17 +111,22 @@ L. =cut -sub all { - my ($self) = @_; +sub _dbh_all { + my ($storage, $dbh, $self) = @_; - $self->_check_forks_threads; - return $self->SUPER::all if $self->{attrs}{rows}; + $self->_check_dbh_gen; $self->{sth}->finish if $self->{sth}->{Active}; delete $self->{sth}; - my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}}); + my ($rv, $sth) = $storage->_select(@{$self->{args}}); return @{$sth->fetchall_arrayref}; } +sub all { + my ($self) = @_; + return $self->SUPER::all if $self->{attrs}{rows}; + $self->{storage}->dbh_do($self->can('_dbh_all'), $self); +} + =head2 reset Resets the cursor to the beginning of the L. @@ -128,8 +136,8 @@ Resets the cursor to the beginning of the L. sub reset { my ($self) = @_; - $self->_check_forks_threads; - $self->{sth}->finish if $self->{sth}->{Active}; + # No need to care about failures here + eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} }; $self->_soft_reset; } @@ -137,30 +145,25 @@ sub _soft_reset { my ($self) = @_; delete $self->{sth}; - $self->{pos} = 0; delete $self->{done}; + $self->{pos} = 0; return $self; } -sub _check_forks_threads { +sub _check_dbh_gen { my ($self) = @_; - if($INC{'threads.pm'} && $self->{tid} != threads->tid) { - $self->_soft_reset; - $self->{tid} = threads->tid; - } - - if($self->{pid} != $$) { - $self->_soft_reset; - $self->{pid} = $$; + if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) { + $self->{_dbh_gen} = $self->{storage}->{_dbh_gen}; + $self->_soft_reset; } } sub DESTROY { my ($self) = @_; - $self->_check_forks_threads; - $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active}; + # None of the reasons this would die matter if we're in DESTROY anyways + eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} }; } 1;