1 package DBIx::Class::Storage::DBI::Cursor;
3 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 #use Data::Dumper; warn Dumper(@_);
40 $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;
71 if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) {
72 $self->{sth}->finish if $self->{sth}->{Active};
76 return if $self->{done};
77 unless ($self->{sth}) {
78 $self->{sth} = ($storage->_select(@{$self->{args}}))[1];
79 if ($self->{attrs}{software_limit}) {
80 if (my $offset = $self->{attrs}{offset}) {
81 $self->{sth}->fetch for 1 .. $offset;
85 my @row = $self->{sth}->fetchrow_array;
97 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
104 =item Arguments: none
106 =item Return Value: \@row_columns+
110 Returns a list of arrayrefs of column values for all rows in the
111 L<DBIx::Class::ResultSet>.
116 my ($storage, $dbh, $self) = @_;
118 $self->_check_dbh_gen;
119 $self->{sth}->finish if $self->{sth}->{Active};
121 my ($rv, $sth) = $storage->_select(@{$self->{args}});
122 return @{$sth->fetchall_arrayref};
127 if ($self->{attrs}{software_limit}
128 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
129 return $self->SUPER::all;
131 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
136 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
143 # No need to care about failures here
144 eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} };
152 delete $self->{done};
160 if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) {
161 $self->{_dbh_gen} = $self->{storage}->{_dbh_gen};
169 # None of the reasons this would die matter if we're in DESTROY anyways
171 eval { $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active} };