X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FCursor.pm;h=b2c13543e44d05e7000615036022646dee6b649e;hb=5d9c76e106f9ac8929bf1dddeeb157bed8d404ac;hp=c9dedf652d127640448d4dd1301fcb6ede29ed3c;hpb=dbaee7482fe6ff190e8ae53d609d0294b911339b;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index c9dedf6..b2c1354 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -1,10 +1,18 @@ package DBIx::Class::Storage::DBI::Cursor; -use base qw/DBIx::Class::Cursor/; - use strict; use warnings; +use base qw/ + Class::Accessor::Grouped + DBIx::Class::Cursor +/; +use mro 'c3'; + +__PACKAGE__->mk_group_accessors('simple' => + qw/sth/ +); + =head1 NAME DBIx::Class::Storage::DBI::Cursor - Object representing a query cursor on a @@ -36,8 +44,8 @@ Returns a new L object. sub new { my ($class, $storage, $args, $attrs) = @_; - #use Data::Dumper; warn Dumper(@_); $class = ref $class if ref $class; + my $new = { storage => $storage, args => $args, @@ -59,7 +67,8 @@ sub new { =back -Advances the cursor to the next row and returns an arrayref of column values. +Advances the cursor to the next row and returns an array of column +values (the result of L method). =cut @@ -67,25 +76,29 @@ sub _dbh_next { my ($storage, $dbh, $self) = @_; $self->_check_dbh_gen; - if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) { - $self->{sth}->finish if $self->{sth}->{Active}; - delete $self->{sth}; + if ( + $self->{attrs}{software_limit} + && $self->{attrs}{rows} + && $self->{pos} >= $self->{attrs}{rows} + ) { + $self->sth->finish if $self->sth->{Active}; + $self->sth(undef); $self->{done} = 1; } return if $self->{done}; - unless ($self->{sth}) { - $self->{sth} = ($storage->_select(@{$self->{args}}))[1]; + unless ($self->sth) { + $self->sth(($storage->_select(@{$self->{args}}))[1]); if ($self->{attrs}{software_limit}) { if (my $offset = $self->{attrs}{offset}) { - $self->{sth}->fetch for 1 .. $offset; + $self->sth->fetch for 1 .. $offset; } } } - my @row = $self->{sth}->fetchrow_array; + my @row = $self->sth->fetchrow_array; if (@row) { $self->{pos}++; } else { - delete $self->{sth}; + $self->sth(undef); $self->{done} = 1; } return @row; @@ -115,15 +128,19 @@ sub _dbh_all { my ($storage, $dbh, $self) = @_; $self->_check_dbh_gen; - $self->{sth}->finish if $self->{sth}->{Active}; - delete $self->{sth}; + $self->sth->finish if $self->sth && $self->sth->{Active}; + $self->sth(undef); my ($rv, $sth) = $storage->_select(@{$self->{args}}); return @{$sth->fetchall_arrayref}; } sub all { my ($self) = @_; - return $self->SUPER::all if $self->{attrs}{rows}; + if ($self->{attrs}{software_limit} + && ($self->{attrs}{offset} || $self->{attrs}{rows})) { + return $self->next::method; + } + $self->{storage}->dbh_do($self->can('_dbh_all'), $self); } @@ -137,17 +154,17 @@ sub reset { my ($self) = @_; # No need to care about failures here - eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} }; + eval { $self->sth->finish if $self->sth && $self->sth->{Active} }; $self->_soft_reset; + return undef; } sub _soft_reset { my ($self) = @_; - delete $self->{sth}; + $self->sth(undef); delete $self->{done}; $self->{pos} = 0; - return $self; } sub _check_dbh_gen { @@ -163,7 +180,8 @@ sub DESTROY { my ($self) = @_; # None of the reasons this would die matter if we're in DESTROY anyways - eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} }; + local $@; + eval { $self->sth->finish if $self->sth && $self->sth->{Active} }; } 1;