1 package DBIx::Class::Storage::DBI::Cursor;
6 use base qw/DBIx::Class::Cursor/;
11 __PACKAGE__->mk_group_accessors('simple' =>
17 DBIx::Class::Storage::DBI::Cursor - Object representing a query cursor on a
22 my $cursor = $schema->resultset('CD')->cursor();
23 my $first_cd = $cursor->next;
27 A Cursor represents a query cursor on a L<DBIx::Class::ResultSet> object. It
28 allows for traversing the result set with L</next>, retrieving all results with
29 L</all> and resetting the cursor with L</reset>.
31 Usually, you would use the cursor methods built into L<DBIx::Class::ResultSet>
32 to traverse it. See L<DBIx::Class::ResultSet/next>,
33 L<DBIx::Class::ResultSet/reset> and L<DBIx::Class::ResultSet/all> for more
40 Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
45 my ($class, $storage, $args, $attrs) = @_;
46 $class = ref $class if ref $class;
53 _dbh_gen => $storage->{_dbh_gen},
56 return bless ($new, $class);
65 =item Return Value: \@row_columns
69 Advances the cursor to the next row and returns an array of column
70 values (the result of L<DBI/fetchrow_array> method).
75 my ($storage, $dbh, $self) = @_;
77 $self->_check_dbh_gen;
79 $self->{attrs}{software_limit}
80 && $self->{attrs}{rows}
81 && $self->{pos} >= $self->{attrs}{rows}
83 $self->sth->finish if $self->sth->{Active};
87 return if $self->{done};
89 $self->sth(($storage->_select(@{$self->{args}}))[1]);
90 if ($self->{attrs}{software_limit}) {
91 if (my $offset = $self->{attrs}{offset}) {
92 $self->sth->fetch for 1 .. $offset;
96 my @row = $self->sth->fetchrow_array;
108 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
115 =item Arguments: none
117 =item Return Value: \@row_columns+
121 Returns a list of arrayrefs of column values for all rows in the
122 L<DBIx::Class::ResultSet>.
127 my ($storage, $dbh, $self) = @_;
129 $self->_check_dbh_gen;
130 $self->sth->finish if $self->sth && $self->sth->{Active};
132 my ($rv, $sth) = $storage->_select(@{$self->{args}});
133 return @{$sth->fetchall_arrayref};
138 if ($self->{attrs}{software_limit}
139 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
140 return $self->next::method;
143 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
148 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
155 # No need to care about failures here
156 try { $self->sth->finish }
157 if $self->sth && $self->sth->{Active};
166 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
183 try { $self->sth->finish }
184 if $self->sth && $self->sth->{Active};