SQLite Forum

Prepared Statements
Somewhere after creating the connection you need to call sqlite3_prepare() passing "SELECT <fieldlist> FROM <table> WHERE rowid between ? and ?;" and keep the statement handle somewhere convenient. You should be using an explicit field list to cater for schema changes and retrieve only the fields your application requires.

Before retrieving the first set of records, you need to call sqlite3_bind_integer() to set the lower and upper bounds.

Then you can retrieve the rows in a loop by calling sqlite3_step() as long as SQLITE_ROW is returned.

When you have retrieved all the rows you want, or have exhausted the available rows (SQLITE_DONE was returned), you need to call sqlite3_reset() to re-initialize the statement.

You can now go back to binding the parameters for the next result set.

When you are done with the statement, call sqlite3_finalize() to free up the resources held by the statement.

Consider using "SELECT <fieldlist> FROM <table> WHERE rowid > ? limit ?" to cater for deletions and return a specific number of rows. This also allows you to set the window size just once.