summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-10-31 11:53:26 +0100
committerYorhel <git@yorhel.nl>2008-10-31 11:53:26 +0100
commitcacfc00dc2b1499edb2865da3064e84eef7b5d54 (patch)
tree16bb0ed0a2177220608db867903634c1673627bf
parent3499c666034942a162ed6d93726e43ff74f57ee6 (diff)
YAWF::DB: Added dbPage
-rw-r--r--lib/YAWF/DB.pm18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/YAWF/DB.pm b/lib/YAWF/DB.pm
index 314f45a..a17c421 100644
--- a/lib/YAWF/DB.pm
+++ b/lib/YAWF/DB.pm
@@ -8,7 +8,7 @@ use DBI;
use Exporter 'import';
our @EXPORT = qw|
dbInit dbCheck dbDisconnect dbCommit dbRollBack
- dbExec dbRow dbAll
+ dbExec dbRow dbAll dbPage
|;
@@ -79,6 +79,22 @@ sub dbAll {
}
+# same as dbAll, but paginates results by adding
+# an OFFSET and LIMIT to the query, the first argument
+# should be a hashref with the keys page and results.
+# Returns the usual value from dbAll and a value
+# 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);
+ return ($r, 0) if $#$r != $o->{results};
+ pop @$r;
+ return ($r, 1);
+}
+
+
sub sqlhelper { # type, query, @list
my $self = shift;
my $type = shift;