Implement limiting of results

Added support for limiting the number of results from a query. this
is implemented by filtering the results ruturned from the Query on the db
Is it safe to use the MAX macro here as both values are NSUInteger? I think the logic could be clearer here.

Also it looks like you can create a range which is outside the bounds of the array, which will apparently throw an exception.