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 { |
cb5f2eea |
9 | my ($class, $storage, $args, $attrs) = @_; |
28927b50 |
10 | #use Data::Dumper; warn Dumper(@_); |
cb5f2eea |
11 | $class = ref $class if ref $class; |
28927b50 |
12 | my $new = { |
cb5f2eea |
13 | storage => $storage, |
28927b50 |
14 | args => $args, |
15 | pos => 0, |
16 | attrs => $attrs }; |
cb5f2eea |
17 | return bless ($new, $class); |
28927b50 |
18 | } |
19 | |
20 | sub next { |
21 | my ($self) = @_; |
cb5f2eea |
22 | if ($self->{attrs}{rows} && $self->{pos} >= $self->{attrs}{rows}) { |
23 | delete $self->{sth}; |
24 | $self->{done} = 1; |
25 | } |
26 | return if $self->{done}; |
27 | unless ($self->{sth}) { |
28 | $self->{sth} = ($self->{storage}->_select(@{$self->{args}}))[1]; |
5c91499f |
29 | if ($self->{attrs}{software_limit}) { |
30 | if (my $offset = $self->{attrs}{offset}) { |
cb5f2eea |
31 | $self->{sth}->fetch for 1 .. $offset; |
5c91499f |
32 | } |
33 | } |
28927b50 |
34 | } |
cb5f2eea |
35 | my @row = $self->{sth}->fetchrow_array; |
36 | if (@row) { |
37 | $self->{pos}++; |
38 | } else { |
39 | delete $self->{sth}; |
40 | $self->{done} = 1; |
41 | } |
28927b50 |
42 | return @row; |
43 | } |
44 | |
1a14aa3f |
45 | sub all { |
46 | my ($self) = @_; |
47 | return $self->SUPER::all if $self->{attrs}{rows}; |
cb5f2eea |
48 | $self->{sth}->finish if $self->{sth}->{Active}; |
49 | delete $self->{sth}; |
50 | my ($rv, $sth) = $self->{storage}->_select(@{$self->{args}}); |
1a14aa3f |
51 | return @{$sth->fetchall_arrayref}; |
52 | } |
53 | |
28927b50 |
54 | sub reset { |
55 | my ($self) = @_; |
56 | $self->{sth}->finish if $self->{sth}->{Active}; |
cb5f2eea |
57 | delete $self->{sth}; |
28927b50 |
58 | $self->{pos} = 0; |
cb5f2eea |
59 | delete $self->{done}; |
28927b50 |
60 | return $self; |
61 | } |
62 | |
63 | sub DESTROY { |
64 | my ($self) = @_; |
65 | $self->{sth}->finish if $self->{sth}->{Active}; |
66 | } |
67 | |
68 | 1; |