Another solution to those already given: Create just once another database containing the numbers 1 to 4000 and use the SQL command <code>ATTACH</code> to make it look like this is part of the database you're checking. <https://www.sqlite.org/lang_attach.html>