1 package DBIx::Class::Storage::DBI::Cursor;
6 use base qw/DBIx::Class::Cursor/;
11 __PACKAGE__->mk_group_accessors('simple' =>
12 qw/sth storage args attrs/
17 DBIx::Class::Storage::DBI::Cursor - Object representing a query cursor on a
22 my $cursor = $schema->resultset('CD')->cursor();
24 # raw values off the database handle in resultset columns/select order
25 my @next_cd_column_values = $cursor->next;
27 # list of all raw values as arrayrefs
28 my @all_cds_column_values = $cursor->all;
32 A Cursor represents a query cursor on a L<DBIx::Class::ResultSet> object. It
33 allows for traversing the result set with L</next>, retrieving all results with
34 L</all> and resetting the cursor with L</reset>.
36 Usually, you would use the cursor methods built into L<DBIx::Class::ResultSet>
37 to traverse it. See L<DBIx::Class::ResultSet/next>,
38 L<DBIx::Class::ResultSet/reset> and L<DBIx::Class::ResultSet/all> for more
45 Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
50 my ($class, $storage, $args, $attrs) = @_;
51 $class = ref $class if ref $class;
57 _dbh_gen => $storage->{_dbh_gen},
62 return bless ($new, $class);
71 =item Return Value: \@row_columns
75 Advances the cursor to the next row and returns an array of column
76 values (the result of L<DBI/fetchrow_array> method).
81 my ($storage, $dbh, $self) = @_;
83 $self->_check_dbh_gen;
85 $self->{attrs}{software_limit}
86 && $self->{attrs}{rows}
87 && $self->{_pos} >= $self->{attrs}{rows}
89 $self->sth->finish if $self->sth->{Active};
94 return if $self->{_done};
97 $self->sth(($storage->_select(@{$self->{args}}))[1]);
98 if ($self->{attrs}{software_limit}) {
99 if (my $offset = $self->{attrs}{offset}) {
100 $self->sth->fetch for 1 .. $offset;
104 my @row = $self->sth->fetchrow_array;
116 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
123 =item Arguments: none
125 =item Return Value: \@row_columns+
129 Returns a list of arrayrefs of column values for all rows in the
130 L<DBIx::Class::ResultSet>.
135 my ($storage, $dbh, $self) = @_;
137 $self->_check_dbh_gen;
138 $self->sth->finish if $self->sth && $self->sth->{Active};
140 my ($rv, $sth) = $storage->_select(@{$self->{args}});
141 return @{$sth->fetchall_arrayref};
146 if ($self->{attrs}{software_limit}
147 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
148 return $self->next::method;
151 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
156 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
163 # No need to care about failures here
164 try { $self->sth->finish }
165 if $self->sth && $self->sth->{Active};
181 if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) {
182 $self->{_dbh_gen} = $self->{storage}->{_dbh_gen};
188 # None of the reasons this would die matter if we're in DESTROY anyways
189 if (my $sth = $_[0]->sth) {
190 local $SIG{__WARN__} = sub {};
191 try { $sth->finish } if $sth->FETCH('Active');