1 package DBIx::Class::Storage::DBI::Cursor;
6 use base qw/DBIx::Class::Cursor/;
10 __PACKAGE__->mk_group_accessors('simple' =>
16 DBIx::Class::Storage::DBI::Cursor - Object representing a query cursor on a
21 my $cursor = $schema->resultset('CD')->cursor();
22 my $first_cd = $cursor->next;
26 A Cursor represents a query cursor on a L<DBIx::Class::ResultSet> object. It
27 allows for traversing the result set with L</next>, retrieving all results with
28 L</all> and resetting the cursor with L</reset>.
30 Usually, you would use the cursor methods built into L<DBIx::Class::ResultSet>
31 to traverse it. See L<DBIx::Class::ResultSet/next>,
32 L<DBIx::Class::ResultSet/reset> and L<DBIx::Class::ResultSet/all> for more
39 Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
44 my ($class, $storage, $args, $attrs) = @_;
45 $class = ref $class if ref $class;
52 _dbh_gen => $storage->{_dbh_gen},
55 return bless ($new, $class);
64 =item Return Value: \@row_columns
68 Advances the cursor to the next row and returns an array of column
69 values (the result of L<DBI/fetchrow_array> method).
74 my ($storage, $dbh, $self) = @_;
76 $self->_check_dbh_gen;
78 $self->{attrs}{software_limit}
79 && $self->{attrs}{rows}
80 && $self->{pos} >= $self->{attrs}{rows}
82 $self->sth->finish if $self->sth->{Active};
86 return if $self->{done};
88 $self->sth(($storage->_select(@{$self->{args}}))[1]);
89 if ($self->{attrs}{software_limit}) {
90 if (my $offset = $self->{attrs}{offset}) {
91 $self->sth->fetch for 1 .. $offset;
95 my @row = $self->sth->fetchrow_array;
107 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
114 =item Arguments: none
116 =item Return Value: \@row_columns+
120 Returns a list of arrayrefs of column values for all rows in the
121 L<DBIx::Class::ResultSet>.
126 my ($storage, $dbh, $self) = @_;
128 $self->_check_dbh_gen;
129 $self->sth->finish if $self->sth && $self->sth->{Active};
131 my ($rv, $sth) = $storage->_select(@{$self->{args}});
132 return @{$sth->fetchall_arrayref};
137 if ($self->{attrs}{software_limit}
138 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
139 return $self->next::method;
142 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
147 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
154 # No need to care about failures here
155 try { $self->sth->finish }
156 if $self->sth && $self->sth->{Active};
165 delete $self->{done};
172 if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) {
173 $self->{_dbh_gen} = $self->{storage}->{_dbh_gen};
181 # None of the reasons this would die matter if we're in DESTROY anyways
182 try { $self->sth->finish }
183 if $self->sth && $self->sth->{Active};