count => undef,
pager => undef,
attrs => $attrs };
- return bless ($new, $it_class);
+ bless ($new, $it_class);
+ $new->pager if ($attrs->{page});
+ return $new;
}
sub cursor {
$self->{cond}, $attrs);
}
return 0 unless $self->{count};
+ return $self->{pager}->entries_on_this_page if ($self->{pager});
return ( $attrs->{rows} && $attrs->{rows} < $self->{count} )
? $attrs->{rows}
: $self->{count};
$order = $1 if $$condition =~ s/ORDER BY (.*)$//i;
}
my @args = ('select', $attrs->{bind}, $ident, $select, $condition, $order);
- if ($self->sql_maker->_default_limit_syntax eq "GenericSubQ") {
- $attrs->{software_limit} = 1;
+ if ($attrs->{software_limit} ||
+ $self->sql_maker->_default_limit_syntax eq "GenericSubQ") {
+ $attrs->{software_limit} = 1;
} else {
push @args, $attrs->{rows}, $attrs->{offset};
}
$order = $1 if $$condition =~ s/ORDER BY (.*)$//i;
}
my @args = ('select', $attrs->{bind}, $ident, $select, $condition, $order);
- if ($self->sql_maker->_default_limit_syntax eq "GenericSubQ") {
- $attrs->{software_limit} = 1;
+ if ($attrs->{software_limit} ||
+ $self->sql_maker->_default_limit_syntax eq "GenericSubQ") {
+ $attrs->{software_limit} = 1;
} else {
push @args, 1, $attrs->{offset};
}
use Test::More;
-plan tests => 8;
+plan tests => 13;
use lib qw(t/lib);
);
my $page = $it->page(2);
+is( $page->count, 2, "standard resultset paged rs count ok" );
+
is( $page->next->title, "Generic Manufactured Singles", "second page of standard resultset ok" );
+
+# test software-based limit paging
+$it = DBICTest::CD->search(
+ {},
+ { order_by => 'title',
+ rows => 3,
+ page => 2,
+ software_limit => 1 }
+);
+is( $it->pager->entries_on_this_page, 2, "software entries_on_this_page ok" );
+
+is( $it->pager->previous_page, 1, "software previous_page ok" );
+
+is( $it->count, 2, "software count on paged rs ok" );
+
+is( $it->next->title, "Generic Manufactured Singles", "software iterator->next ok" );
BEGIN {
eval "use DBD::SQLite";
- plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 6);
+ plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 10);
}
use lib qw(t/lib);
);
is( $cds[0]->title, "Spoonful of bees", "offset ok" );
+# test software-based limiting
+$it = DBICTest::CD->search( {},
+ { rows => 3,
+ software_limit => 1,
+ order_by => 'title' }
+);
+is( $it->count, 3, "software limit count ok" );
+is( $it->next->title, "Caterwaulin' Blues", "software iterator->next ok" );
+$it->next;
+$it->next;
+is( $it->next, undef, "software next past end of resultset ok" );
+
+@cds = DBICTest::CD->search( {},
+ { rows => 2,
+ offset => 2,
+ software_limit => 1,
+ order_by => 'year' }
+);
+is( $cds[0]->title, "Spoonful of bees", "software offset ok" );
+
# based on a failing criteria submitted by waswas
# requires SQL::Abstract >= 1.20
$it = DBICTest::CD->search(