how to query sqlite for certain rows, i.e. dividing it into pages (perl DBI) how to query sqlite for certain rows, i.e. dividing it into pages (perl DBI) sqlite sqlite

how to query sqlite for certain rows, i.e. dividing it into pages (perl DBI)


Using the LIMIT/OFFSET construction will show pages, but the OFFSET makes the query inefficient, and makes the page contents move off when the data changes.

It is more efficient and consistent if the next page starts the query at the position where the last one ended, like this:

SELECT *FROM mytableORDER BY mycolumnWHERE mycolumn > :lastvalueLIMIT 25

This implies that your links are not /webapp?Page=N but /webapp?StartAfter=LastKey.

This is explained in detail on the Scrolling Cursor page.


You should do something like this:

SELECT column FROM table ORDER BY somethingelse LIMIT 0, 25

and when the user clicks on page 2, you should do:

SELECT column FROM table ORDER BY somethingelse LIMIT 25, 50

and so on..


You'd most likely be using the LIMIT and OFFSET keywords, something like this:

$sth->prepare("SELECT foo FROM bar WHERE something LIMIT ? OFFSET ?");$sth->execute($limit, $offset);while ( my @row = $sth->fetchrow_array ) { # loop contains 25 items

The $limit and $offset variables would be controlled by the parameters passed to your script by html/cgi/whatever features.