Fixed #21160 -- in_bulk on SQLite with more than 999 ids

SQLite has 1000 query parameters limit, so fetching more than 999
objects in a single query doesn't work. This caused in_bulk() to fail
when issued more than 1000 ids. The in_bulk() method now fetches objects
in correctly sized batches to avoid the parameter limit problem.

Patch based on work done by Trac alias NiGhTTraX.