X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FCursor.pm;h=361b1295373727189820d303ce0111b51a564230;hb=60283c2e81a0c2ec3ef9ee94350f1a620291e65a;hp=67476c7b5ad1b43d89ba76e909238bdc7a32d2e8;hpb=5c91499f8d1122eaad9bb4f36ae50380feadd4eb;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI/Cursor.pm b/lib/DBIx/Class/Storage/DBI/Cursor.pm index 67476c7..361b129 100644 --- a/lib/DBIx/Class/Storage/DBI/Cursor.pm +++ b/lib/DBIx/Class/Storage/DBI/Cursor.pm @@ -6,51 +6,58 @@ use strict; use warnings; sub new { - my ($it_class, $sth, $args, $attrs) = @_; + my ($class, $storage, $args, $attrs) = @_; #use Data::Dumper; warn Dumper(@_); - $it_class = ref $it_class if ref $it_class; + $class = ref $class if ref $class; my $new = { - sth => $sth, + storage => $storage, args => $args, pos => 0, attrs => $attrs }; - return bless ($new, $it_class); + return bless ($new, $class); } sub next { my ($self) = @_; - return if $self->{attrs}{rows} - && $self->{pos} >= $self->{attrs}{rows}; # + $self->{attrs}{offset}); - my $sth = $self->{sth}; - unless ($self->{live_sth}) { - $sth->execute(@{$self->{args} || []}); + if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) { + $self->{sth}->finish if $self->{sth}->{Active}; + delete $self->{sth}; + $self->{done} = 1; + } + return if $self->{done}; + unless ($self->{sth}) { + $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1]; if ($self->{attrs}{software_limit}) { if (my $offset = $self->{attrs}{offset}) { - $sth->fetch for 1 .. $offset; + $self->{sth}->fetch for 1 .. $offset; } } - $self->{live_sth} = 1; } - my @row = $sth->fetchrow_array; - $self->{pos}++ if @row; + my @row = $self->{sth}->fetchrow_array; + if (@row) { + $self->{pos}++; + } else { + delete $self->{sth}; + $self->{done} = 1; + } return @row; } sub all { my ($self) = @_; return $self->SUPER::all if $self->{attrs}{rows}; - my $sth = $self->{sth}; - $sth->finish if $sth->{Active}; - $sth->execute(@{$self->{args} || []}); - delete $self->{live_sth}; + $self->{sth}->finish if $self->{sth}->{Active}; + delete $self->{sth}; + my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}}); return @{$sth->fetchall_arrayref}; } sub reset { my ($self) = @_; $self->{sth}->finish if $self->{sth}->{Active}; + delete $self->{sth}; $self->{pos} = 0; - $self->{live_sth} = 0; + delete $self->{done}; return $self; }