1 package DBIx::Class::Storage::DBI::Cursor;
7 Class::Accessor::Grouped
12 __PACKAGE__->mk_group_accessors('simple' =>
18 DBIx::Class::Storage::DBI::Cursor - Object representing a query cursor on a
23 my $cursor = $schema->resultset('CD')->cursor();
24 my $first_cd = $cursor->next;
28 A Cursor represents a query cursor on a L<DBIx::Class::ResultSet> object. It
29 allows for traversing the result set with L</next>, retrieving all results with
30 L</all> and resetting the cursor with L</reset>.
32 Usually, you would use the cursor methods built into L<DBIx::Class::ResultSet>
33 to traverse it. See L<DBIx::Class::ResultSet/next>,
34 L<DBIx::Class::ResultSet/reset> and L<DBIx::Class::ResultSet/all> for more
41 Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
46 my ($class, $storage, $args, $attrs) = @_;
47 $class = ref $class if ref $class;
54 _dbh_gen => $storage->{_dbh_gen},
57 return bless ($new, $class);
66 =item Return Value: \@row_columns
70 Advances the cursor to the next row and returns an array of column
71 values (the result of L<DBI/fetchrow_array> method).
76 my ($storage, $dbh, $self) = @_;
78 $self->_check_dbh_gen;
80 $self->{attrs}{software_limit}
81 && $self->{attrs}{rows}
82 && $self->{pos} >= $self->{attrs}{rows}
84 $self->sth->finish if $self->sth->{Active};
88 return if $self->{done};
90 $self->sth(($storage->_select(@{$self->{args}}))[1]);
91 if ($self->{attrs}{software_limit}) {
92 if (my $offset = $self->{attrs}{offset}) {
93 $self->sth->fetch for 1 .. $offset;
97 my @row = $self->sth->fetchrow_array;
109 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
116 =item Arguments: none
118 =item Return Value: \@row_columns+
122 Returns a list of arrayrefs of column values for all rows in the
123 L<DBIx::Class::ResultSet>.
128 my ($storage, $dbh, $self) = @_;
130 $self->_check_dbh_gen;
131 $self->sth->finish if $self->sth && $self->sth->{Active};
133 my ($rv, $sth) = $storage->_select(@{$self->{args}});
134 return @{$sth->fetchall_arrayref};
139 if ($self->{attrs}{software_limit}
140 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
141 return $self->next::method;
144 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
149 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
156 # No need to care about failures here
157 eval { $self->sth->finish if $self->sth && $self->sth->{Active} };
165 delete $self->{done};
173 if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) {
174 $self->{_dbh_gen} = $self->{storage}->{_dbh_gen};
182 # None of the reasons this would die matter if we're in DESTROY anyways
184 eval { $self->sth->finish if $self->sth && $self->sth->{Active} };