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 pos attrs _dbh_gen/
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;
58 _dbh_gen => $storage->{_dbh_gen},
61 return bless ($new, $class);
70 =item Return Value: \@row_columns
74 Advances the cursor to the next row and returns an array of column
75 values (the result of L<DBI/fetchrow_array> method).
80 my ($storage, $dbh, $self) = @_;
82 $self->_check_dbh_gen;
84 $self->{attrs}{software_limit}
85 && $self->{attrs}{rows}
86 && $self->{pos} >= $self->{attrs}{rows}
88 $self->sth->finish if $self->sth->{Active};
92 return if $self->{done};
94 $self->sth(($storage->_select(@{$self->{args}}))[1]);
95 if ($self->{attrs}{software_limit}) {
96 if (my $offset = $self->{attrs}{offset}) {
97 $self->sth->fetch for 1 .. $offset;
101 my @row = $self->sth->fetchrow_array;
113 $self->{storage}->dbh_do($self->can('_dbh_next'), $self);
120 =item Arguments: none
122 =item Return Value: \@row_columns+
126 Returns a list of arrayrefs of column values for all rows in the
127 L<DBIx::Class::ResultSet>.
132 my ($storage, $dbh, $self) = @_;
134 $self->_check_dbh_gen;
135 $self->sth->finish if $self->sth && $self->sth->{Active};
137 my ($rv, $sth) = $storage->_select(@{$self->{args}});
138 return @{$sth->fetchall_arrayref};
143 if ($self->{attrs}{software_limit}
144 && ($self->{attrs}{offset} || $self->{attrs}{rows})) {
145 return $self->next::method;
148 $self->{storage}->dbh_do($self->can('_dbh_all'), $self);
153 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
160 # No need to care about failures here
161 try { $self->sth->finish }
162 if $self->sth && $self->sth->{Active};
171 delete $self->{done};
178 if($self->{_dbh_gen} != $self->{storage}->{_dbh_gen}) {
179 $self->{_dbh_gen} = $self->{storage}->{_dbh_gen};
185 # None of the reasons this would die matter if we're in DESTROY anyways
186 if (my $sth = $_[0]->sth) {
187 local $SIG{__WARN__} = sub {};
188 try { $sth->finish } if $sth->FETCH('Active');