summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/TUWF/DB.pm5
-rw-r--r--lib/TUWF/DB.pod12
2 files changed, 9 insertions, 8 deletions
diff --git a/lib/TUWF/DB.pm b/lib/TUWF/DB.pm
index b70b8a2..a583609 100644
--- a/lib/TUWF/DB.pm
+++ b/lib/TUWF/DB.pm
@@ -114,9 +114,8 @@ sub dbAll {
# indicating whether there is a next page
sub dbPage {
my($s, $o, $q, @a) = @_;
- $q .= ' LIMIT ? OFFSET ?';
- push @a, $o->{results}+1, $o->{results}*($o->{page}-1);
- my $r = $s->dbAll($q, @a);
+ my $r = $s->dbAll($q.' LIMIT ? OFFSET ?', @a, $o->{results}+(wantarray?1:0), $o->{results}*($o->{page}-1));
+ return $r if !wantarray;
return ($r, 0) if $#$r != $o->{results};
pop @$r;
return ($r, 1);
diff --git a/lib/TUWF/DB.pod b/lib/TUWF/DB.pod
index e01322d..6f11a97 100644
--- a/lib/TUWF/DB.pod
+++ b/lib/TUWF/DB.pod
@@ -141,11 +141,13 @@ I<page>, a number indicating the currently requested page, counting from 1.
This method automatically adds a C<LIMIT> and C<OFFSET> to the end of the
query, so these should be omitted from the I<query> argument.
-This method returns two values: the first value identical to the return value
-of C<dbAll()> with the proper C<LIMIT> and C<OFFSET> clauses. The second value
-is either 0 or 1, and indicates whether there are more rows. That is, if the
-second value is true, calling the this method with the same arguments but with
-the I<page> option increased with one will return at least one more row.
+In scalar context, this method returns an arrayref of hashrefs, the same as
+C<dbAll()> except with the proper C<LIMIT> and C<OFFSET> clauses applied. In
+array context, this method returns two values: the first value is the arrayref,
+the second value is either 0 or 1, indicating whether there are more rows.
+That is, if the second value is true, calling the this method with the same
+arguments but with the I<page> option increased with one will return at least
+one more row.
my($rows, $nextpage) = tuwf->dbPage(
{page => 2, results => 10},