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;
49 $new->{tid} = threads->tid if $INC{'threads.pm'};
51 return bless ($new, $class);
60 =item Return Value: \@row_columns
64 Advances the cursor to the next row and returns an arrayref of column values.
71 $self->_check_forks_threads;
72 if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) {
73 $self->{sth}->finish if $self->{sth}->{Active};
77 return if $self->{done};
78 unless ($self->{sth}) {
79 $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1];
80 if ($self->{attrs}{software_limit}) {
81 if (my $offset = $self->{attrs}{offset}) {
82 $self->{sth}->fetch for 1 .. $offset;
86 my @row = $self->{sth}->fetchrow_array;
100 =item Arguments: none
102 =item Return Value: \@row_columns+
106 Returns a list of arrayrefs of column values for all rows in the
107 L<DBIx::Class::ResultSet>.
114 $self->_check_forks_threads;
115 return $self->SUPER::all if $self->{attrs}{rows};
116 $self->{sth}->finish if $self->{sth}->{Active};
118 my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}});
119 return @{$sth->fetchall_arrayref};
124 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
131 $self->_check_forks_threads;
132 $self->{sth}->finish if $self->{sth}->{Active};
141 delete $self->{done};
145 sub _check_forks_threads {
148 if($INC{'threads.pm'} && $self->{tid} != threads->tid) {
150 $self->{tid} = threads->tid;
153 if($self->{pid} != $$) {
162 $self->_check_forks_threads;
163 $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active};