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 array of column
65 values (the result of L<DBI/fetchrow_array> method).
72 $self->_check_forks_threads;
73 if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) {
74 $self->{sth}->finish if $self->{sth}->{Active};
78 return if $self->{done};
79 unless ($self->{sth}) {
80 $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1];
81 if ($self->{attrs}{software_limit}) {
82 if (my $offset = $self->{attrs}{offset}) {
83 $self->{sth}->fetch for 1 .. $offset;
87 my @row = $self->{sth}->fetchrow_array;
101 =item Arguments: none
103 =item Return Value: \@row_columns+
107 Returns a list of arrayrefs of column values for all rows in the
108 L<DBIx::Class::ResultSet>.
115 $self->_check_forks_threads;
116 return $self->SUPER::all if $self->{attrs}{rows};
117 $self->{sth}->finish if $self->{sth}->{Active};
119 my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}});
120 return @{$sth->fetchall_arrayref};
125 Resets the cursor to the beginning of the L<DBIx::Class::ResultSet>.
132 $self->_check_forks_threads;
133 $self->{sth}->finish if $self->{sth}->{Active};
142 delete $self->{done};
146 sub _check_forks_threads {
149 if($INC{'threads.pm'} && $self->{tid} != threads->tid) {
151 $self->{tid} = threads->tid;
154 if($self->{pid} != $$) {
163 $self->_check_forks_threads;
164 $self->{sth}->finish if $self->{sth} && $self->{sth}->{Active};