first commit

I think here you need to figure out how to get the right number of records in the first place.  For example, if I want to retrieve 199 records I know that there must be two queries if the offset is equal to 100:

query 1: offset = 0, count = 100
query 2: offset = 100, count = 99

You could write a bit of code that knows how to do this...