1 package DBIx::Class::Storage::DBI::Cursor;
6 use base qw/DBIx::Class::Cursor/;
10 DBIx::Class::Storage::DBI::Cursor - Object representing a query cursor on a
15 my $cursor = $schema->resultset('CD')->cursor();
16 my $first_cd = $cursor->next;
20 A Cursor represents a query cursor on a L<DBIx::Class::ResultSet> object. It
21 allows for traversing the result set with L</next>, retrieving all results with
22 L</all> and resetting the cursor with L</reset>.
24 Usually, you would use the cursor methods built into L<DBIx::Class::ResultSet>
25 to traverse it. See L<DBIx::Class::ResultSet/next>,
26 L<DBIx::Class::ResultSet/reset> and L<DBIx::Class::ResultSet/all> for more
33 Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
38 my ($class, $storage, $args, $attrs) = @_;
39 $class = ref $class if ref $class;
46 _dbh_gen => $storage->{_dbh_gen},
49 return bless ($new, $class);
58 =item Return Value: \@row_columns
62 Advances the cursor to the next row and returns an array of column
63 values (the result of L<DBI/fetchrow_array> method).
68 my ($storage, $dbh, $self) = @_;
70 $self->_check_dbh_gen;
72 $self->{attrs}{software_limit}
73 && $self->{attrs}{rows}
74 && $self->{pos} >= $self->{attrs}{rows}
76 $self->{sth}->finish if $self->{sth}->{Active};
80 return if $self->{done};
81 unless ($self->{sth}) {
82 $self->{sth} = ($storage->_select(@{$self->{args}}))[1];
83 if ($self->{attrs}{software_limit}) {
84 if (my $offset = $self->{attrs}{offset}) {
85 $self->{sth}->fetch for 1 .. $offset;
89 my @row = $self->{sth}->fetchrow_array;
101 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
108 =item Arguments: none
110 =item Return Value: \@row_columns+
114 Returns a list of arrayrefs of column values for all rows in the
115 L<DBIx::Class::ResultSet>.
120 my ($storage, $dbh, $self) = @_;
122 $self->_check_dbh_gen;
123 $self->{sth}->finish if $self->{sth}->{Active};
125 my ($rv, $sth) = $storage->_select(@{$self->{args}});
126 return @{$sth->fetchall_arrayref};
131 if ($self->{attrs}{software_limit}
132 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
133 return $self->next::method;
136 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
141 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
148 # No need to care about failures here
149 eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} };
157 delete $self->{done};
165 if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) {
166 $self->{_dbh_gen} = $self->{storage}->{_dbh_gen};
174 # None of the reasons this would die matter if we're in DESTROY anyways
176 eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} };