Permalink
Browse files

Accept limit offset,count syntax too.

Fixes Issue #31

Thanks to nicolasfranck for reporting this problem on GitHub, and sorry it took
so long to get it sorted.
  • Loading branch information...
1 parent d1e86fb commit 1075ba3d5284299564a50b42a5e1fe85d45ebb5b @bigpresh committed Sep 13, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/Dancer/Plugin/Database/Handle.pm
@@ -293,9 +293,13 @@ sub _quick_query {
# Add a LIMIT clause if we want to:
if (exists $opts->{limit}) {
- if ($opts->{limit} =~ /^\d+$/) {
+ my $limit = $opts->{limit};
+ $limit =~ s/\s+//g;
+ # Check the limit clause is sane - just a number, or two numbers with a
+ # comma between (if using offset,limit )
+ if ($limit =~ m{ ^ \d+ (?: , \d+)? $ }x) {
# Checked for sanity above so safe to interpolate
- $sql .= " LIMIT $opts->{limit}";
+ $sql .= " LIMIT $limit";
} else {
die "Invalid LIMIT param $opts->{limit} !";
}

0 comments on commit 1075ba3

Please sign in to comment.