Overcome the SQLite limit in the number of SQL variables that can be used in a single query

The code now goes through a loop to ensure that no more than 999 variables are used. As before, the results are simply pushed into the final array, which is returned by the method.