Commit | Line | Data |
28927b50 |
1 | package DBIx::Class::Storage::DBI::Cursor; |
2 | |
3 | use base qw/DBIx::Class::Cursor/; |
4 | |
5 | use strict; |
6 | use warnings; |
7 | |
8 | sub new { |
9 | my ($it_class, $sth, $args, $attrs) = @_; |
10 | #use Data::Dumper; warn Dumper(@_); |
11 | $it_class = ref $it_class if ref $it_class; |
12 | my $new = { |
13 | sth => $sth, |
14 | args => $args, |
15 | pos => 0, |
16 | attrs => $attrs }; |
17 | return bless ($new, $it_class); |
18 | } |
19 | |
20 | sub next { |
21 | my ($self) = @_; |
22 | return if $self->{attrs}{rows} |
23 | && $self->{pos} >= $self->{attrs}{rows}; # + $self->{attrs}{offset}); |
1a14aa3f |
24 | my $sth = $self->{sth}; |
28927b50 |
25 | unless ($self->{live_sth}) { |
1a14aa3f |
26 | $sth->execute(@{$self->{args} || []}); |
28927b50 |
27 | $self->{live_sth} = 1; |
28 | } |
1a14aa3f |
29 | my @row = $sth->fetchrow_array; |
28927b50 |
30 | $self->{pos}++ if @row; |
31 | return @row; |
32 | } |
33 | |
1a14aa3f |
34 | sub all { |
35 | my ($self) = @_; |
36 | return $self->SUPER::all if $self->{attrs}{rows}; |
37 | my $sth = $self->{sth}; |
38 | $sth->finish if $sth->{Active}; |
39 | $sth->execute(@{$self->{args} || []}); |
40 | delete $self->{live_sth}; |
41 | return @{$sth->fetchall_arrayref}; |
42 | } |
43 | |
28927b50 |
44 | sub reset { |
45 | my ($self) = @_; |
46 | $self->{sth}->finish if $self->{sth}->{Active}; |
47 | $self->{pos} = 0; |
48 | $self->{live_sth} = 0; |
49 | return $self; |
50 | } |
51 | |
52 | sub DESTROY { |
53 | my ($self) = @_; |
54 | $self->{sth}->finish if $self->{sth}->{Active}; |
55 | } |
56 | |
57 | 1; |