Re-added software-based LIMIT support for non-LIMIT-supporting databases
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Cursor.pm
CommitLineData
28927b50 1package DBIx::Class::Storage::DBI::Cursor;
2
3use base qw/DBIx::Class::Cursor/;
4
5use strict;
6use warnings;
7
8sub 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
20sub 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} || []});
5c91499f 27 if ($self->{attrs}{software_limit}) {
28 if (my $offset = $self->{attrs}{offset}) {
29 $sth->fetch for 1 .. $offset;
30 }
31 }
28927b50 32 $self->{live_sth} = 1;
33 }
1a14aa3f 34 my @row = $sth->fetchrow_array;
28927b50 35 $self->{pos}++ if @row;
36 return @row;
37}
38
1a14aa3f 39sub all {
40 my ($self) = @_;
41 return $self->SUPER::all if $self->{attrs}{rows};
42 my $sth = $self->{sth};
43 $sth->finish if $sth->{Active};
44 $sth->execute(@{$self->{args} || []});
45 delete $self->{live_sth};
46 return @{$sth->fetchall_arrayref};
47}
48
28927b50 49sub reset {
50 my ($self) = @_;
51 $self->{sth}->finish if $self->{sth}->{Active};
52 $self->{pos} = 0;
53 $self->{live_sth} = 0;
54 return $self;
55}
56
57sub DESTROY {
58 my ($self) = @_;
59 $self->{sth}->finish if $self->{sth}->{Active};
60}
61
621;