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
35 Returns a new L<DBIx::Class::Storage::DBI::Cursor> object.
40 my ($class, $storage, $args, $attrs) = @_;
41 #use Data::Dumper; warn Dumper(@_);
42 $class = ref $class if ref $class;
51 $new->{tid} = threads->tid if $INC{'threads.pm'};
53 return bless ($new, $class);
60 =item Arguments: (none)
62 =item Returns: \@row_columns
66 Advances the cursor to the next row and returns an arrayref of column values.
73 $self->_check_forks_threads;
74 if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) {
75 $self->{sth}->finish if $self->{sth}->{Active};
79 return if $self->{done};
80 unless ($self->{sth}) {
81 $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1];
82 if ($self->{attrs}{software_limit}) {
83 if (my $offset = $self->{attrs}{offset}) {
84 $self->{sth}->fetch for 1 .. $offset;
88 my @row = $self->{sth}->fetchrow_array;
102 =item Arguments: (none)
104 =item Returns: \@row_columns+
108 Returns a list of arrayrefs of column values for all rows in the
109 L<DBIx::Class::ResultSet>.
116 $self->_check_forks_threads;
117 return $self->SUPER::all if $self->{attrs}{rows};
118 $self->{sth}->finish if $self->{sth}->{Active};
120 my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}});
121 return @{$sth->fetchall_arrayref};
128 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
135 $self->_check_forks_threads;
136 $self->{sth}->finish if $self->{sth}->{Active};
145 delete $self->{done};
149 sub _check_forks_threads {
152 if($INC{'threads.pm'} && $self->{tid} != threads->tid) {
154 $self->{tid} = threads->tid;
157 if($self->{pid} != $$) {
166 $self->_check_forks_threads;
167 $self->{sth}->finish if $self->{sth}->{Active};