1 package DBIx::Class::Cursor;
10 my ($it_class, $db_class, $sth, $args, $cols, $attrs) = @_;
11 #use Data::Dumper; warn Dumper(@_);
12 $it_class = ref $it_class if ref $it_class;
14 $attrs->{bind} = $args;
15 $sth = $db_class->storage->select($db_class->_table_name,$cols,
16 $attrs->{where},$attrs);
25 return bless ($new, $it_class);
29 my ($self, $min, $max) = @_;
30 my $attrs = { %{ $self->{attrs} || {} } };
31 $self->{class}->throw("Can't slice without where") unless $attrs->{where};
32 $attrs->{offset} = $min;
33 $attrs->{rows} = ($max ? ($max - $min + 1) : 1);
34 my $slice = $self->new($self->{class}, undef, $self->{args},
35 $self->{cols}, $attrs);
36 return (wantarray ? $slice->all : $slice);
41 return if $self->{attrs}{rows}
42 && $self->{pos} >= $self->{attrs}{rows}; # + $self->{attrs}{offset});
43 unless ($self->{live_sth}) {
44 $self->{sth}->execute(@{$self->{args} || []});
45 if (my $offset = $self->{attrs}{offset}) {
46 $self->{sth}->fetchrow_array for 1 .. $offset;
48 $self->{live_sth} = 1;
50 my @row = $self->{sth}->fetchrow_array;
53 return $self->{class}->_row_to_object($self->{cols}, \@row);
58 return $self->{attrs}{rows} if $self->{attrs}{rows};
59 if (my $cond = $self->{attrs}->{where}) {
60 #warn "Counting ".$$cond;
61 return $self->{class}->count($cond, { bind => $self->{args} });
63 return scalar $_[0]->all; # So inefficient
71 while (my $obj = $self->next) {
80 $self->{sth}->finish if $self->{sth}->{Active};
82 $self->{live_sth} = 0;
87 return $_[0]->reset->next;
92 $_->delete for $self->all;
98 $self->{sth}->finish if $self->{sth}->{Active};