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 $sth = $db_class->_get_sth('select', $cols,
15 $db_class->_table_name, $attrs->{where});
24 return bless ($new, $it_class);
28 my ($self, $min, $max) = @_;
29 my $attrs = { %{ $self->{attrs} || {} } };
30 $self->{class}->throw("Can't slice without where") unless $attrs->{where};
31 $attrs->{offset} = $min;
32 $attrs->{rows} = ($max ? ($max - $min + 1) : 1);
33 my $slice = $self->new($self->{class}, undef, $self->{args},
34 $self->{cols}, $attrs);
35 return (wantarray ? $slice->all : $slice);
40 return if $self->{attrs}{rows}
41 && $self->{pos} >= $self->{attrs}{rows}; # + $self->{attrs}{offset});
42 unless ($self->{live_sth}) {
43 $self->{sth}->execute(@{$self->{args} || []});
44 if (my $offset = $self->{attrs}{offset}) {
45 $self->{sth}->fetchrow_array for 1 .. $offset;
47 $self->{live_sth} = 1;
49 my @row = $self->{sth}->fetchrow_array;
52 return $self->{class}->_row_to_object($self->{cols}, \@row);
57 return $self->{attrs}{rows} if $self->{attrs}{rows};
58 if (my $cond = $self->{attrs}->{where}) {
59 my $class = $self->{class};
60 my $sth = $class->_get_sth( 'select', [ 'COUNT(*)' ],
61 $class->_table_name, $cond);
62 my ($count) = $class->_get_dbh->selectrow_array(
63 $sth, undef, @{$self->{args} || []});
66 return scalar $_[0]->all; # So inefficient
74 while (my $obj = $self->next) {
83 $self->{sth}->finish if $self->{sth}->{Active};
85 $self->{live_sth} = 0;
90 return $_[0]->reset->next;
95 $_->delete for $self->all;