diff options
author | Max Kanat-Alexander <mkanat@bugzilla.org> | 2011-02-11 18:03:50 -0800 |
---|---|---|
committer | Max Kanat-Alexander <mkanat@bugzilla.org> | 2011-02-11 18:03:50 -0800 |
commit | 99b870afefa80a2fb4b4ac9252d7fdd5f977260d (patch) | |
tree | c734ca76dda02abf79e1d91b91ce77fbdefb6390 /Bugzilla | |
parent | ede6518f4e49b26c9096173fcb9ba4197f774874 (diff) | |
download | bugs-99b870afefa80a2fb4b4ac9252d7fdd5f977260d.tar bugs-99b870afefa80a2fb4b4ac9252d7fdd5f977260d.tar.gz bugs-99b870afefa80a2fb4b4ac9252d7fdd5f977260d.tar.bz2 bugs-99b870afefa80a2fb4b4ac9252d7fdd5f977260d.tar.xz bugs-99b870afefa80a2fb4b4ac9252d7fdd5f977260d.zip |
Bug 535571: Allow Search.pm to accept "limit" and "offset" as parameters.
r=mkanat, a=mkanat (module owner)
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Search.pm | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index 2220abf1e..224193fbc 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -56,6 +56,7 @@ use Data::Dumper; use Date::Format; use Date::Parse; use List::MoreUtils qw(all part uniq); +use POSIX qw(INT_MAX); use Storable qw(dclone); # Description Of Boolean Charts @@ -718,12 +719,14 @@ sub sql { ? "\nHAVING " . join(' AND ', @$having_terms) : ''; my $order_by = $self->_sql_order_by ? "\nORDER BY " . join(', ', $self->_sql_order_by) : ''; + my $limit = $self->_sql_limit; + $limit = "\n$limit" if $limit; my $query = <<END; SELECT $select FROM $from WHERE $where -$group_by$having$order_by +$group_by$having$order_by$limit END $self->{sql} = $query; return $self->{sql}; @@ -918,6 +921,33 @@ sub _translate_order_by_column { return @items; } +############################# +# Internal Accessors: LIMIT # +############################# + +sub _sql_limit { + my ($self) = @_; + my $limit = $self->_params->{limit}; + my $offset = $self->_params->{offset}; + if (defined $offset and not defined $limit) { + $limit = INT_MAX; + } + if (defined $limit) { + detaint_natural($limit) + || ThrowCodeError('param_must_be_numeric', + { function => 'Bugzilla::Search::new', + param => 'limit' }); + if (defined $offset) { + detaint_natural($offset) + || ThrowCodeError('param_must_be_numeric', + { function => 'Bugzilla::Search::new', + param => 'offset' }); + } + return Bugzilla->dbh->sql_limit($limit, $offset); + } + return ''; +} + ############################ # Internal Accessors: FROM # ############################ |