1 package DBIx::Class::Storage::DBI::Cursor;
6 use base qw/DBIx::Class::Cursor/;
8 __PACKAGE__->mk_group_accessors('simple' =>
14 DBIx::Class::Storage::DBI::Cursor - Object representing a query cursor on a
19 my $cursor = $schema->resultset('CD')->cursor();
20 my $first_cd = $cursor->next;
24 A Cursor represents a query cursor on a L<DBIx::Class::ResultSet> object. It
25 allows for traversing the result set with L</next>, retrieving all results with
26 L</all> and resetting the cursor with L</reset>.
28 Usually, you would use the cursor methods built into L<DBIx::Class::ResultSet>
29 to traverse it. See L<DBIx::Class::ResultSet/next>,
30 L<DBIx::Class::ResultSet/reset> and L<DBIx::Class::ResultSet/all> for more
37 Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
42 my ($class, $storage, $args, $attrs) = @_;
43 $class = ref $class if ref $class;
50 _dbh_gen => $storage->{_dbh_gen},
53 return bless ($new, $class);
62 =item Return Value: \@row_columns
66 Advances the cursor to the next row and returns an array of column
67 values (the result of L<DBI/fetchrow_array> method).
72 my ($storage, $dbh, $self) = @_;
74 $self->_check_dbh_gen;
76 $self->{attrs}{software_limit}
77 && $self->{attrs}{rows}
78 && $self->{pos} >= $self->{attrs}{rows}
80 $self->sth->finish if $self->sth->{Active};
84 return if $self->{done};
86 $self->sth(($storage->_select(@{$self->{args}}))[1]);
87 if ($self->{attrs}{software_limit}) {
88 if (my $offset = $self->{attrs}{offset}) {
89 $self->sth->fetch for 1 .. $offset;
93 my @row = $self->sth->fetchrow_array;
105 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
112 =item Arguments: none
114 =item Return Value: \@row_columns+
118 Returns a list of arrayrefs of column values for all rows in the
119 L<DBIx::Class::ResultSet>.
124 my ($storage, $dbh, $self) = @_;
126 $self->_check_dbh_gen;
127 $self->sth->finish if $self->sth && $self->sth->{Active};
129 my ($rv, $sth) = $storage->_select(@{$self->{args}});
130 return @{$sth->fetchall_arrayref};
135 if ($self->{attrs}{software_limit}
136 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
137 return $self->next::method;
140 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
145 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
152 # No need to care about failures here
153 eval { $self->sth->finish if $self->sth && $self->sth->{Active} };
162 delete $self->{done};
169 if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) {
170 $self->{_dbh_gen} = $self->{storage}->{_dbh_gen};
178 # None of the reasons this would die matter if we're in DESTROY anyways
180 eval { $self->sth->finish if $self->sth && $self->sth->{Active} };