Reject ranges that start beyond last item

This commit is contained in:
Joe Nelson
2014-09-07 12:47:07 -07:00
parent db7ccda74d
commit fcdc37d20b
4 changed files with 33 additions and 13 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ data RangedResult = RangedResult {
, rrTo :: Int
, rrTotal :: Int
, rrBody :: BL.ByteString
}
} deriving (Show)
type QuotedSql = (String, [SqlValue])
@@ -44,7 +44,7 @@ getRows schema table qq range conn = do
r <- quickQuery conn query []
return $ case r of
[[_, _, SqlNull]] -> RangedResult 0 0 0 ""
[[total, _, SqlNull]] -> RangedResult offset 0 (fromSql total) ""
[[total, limited_total, json]] ->
RangedResult offset (offset + fromSql limited_total - 1)
(fromSql total) (fromSql json)