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'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.