1

I am calling 1000 records a time using for loop from a database using API (paging through data) and want that if the database record reaches its limit, the loop should terminate.

I am using limit and offset in url but i failed to stop at last record instead it start appending record from first unless loop terminates.

Note: range end is unknown.

Raj
  • 77
  • 2
  • 5
  • Without knowing how many records exist, or knowing more details about the API (is this an implementation of SQL, for example? Which?), I'm not sure this question is answerable. You either need to know the number of records, or the API must support some form of indication that you've reached the end. – Gareth Pulham Apr 17 '17 at 00:11

1 Answers1

0

From my understanding, you're looping through the data you got from Socrata, so here's what you could do:

  1. Instead of blindly looping through paginated data, you can select the total number of rows that exist in a dataset and then loop based off that number. Here's an example query you'd use to get the count.

    https://host.socrata.com/resource/four-four.json??$select=COUNT(*)
    
  2. Second way, if you don't want to get the row count before, at some point during your looping through Socrata's data, you'll just receive an empty array of data if you paginate too far so you can break out of your loop at that point.

allejo
  • 2,076
  • 4
  • 25
  • 40