Results from two queries at once in sqlite?
- by SF.
I'm currently trying to optimize the sluggish process of retrieving a page of log entries from the SQLite database.
I noticed I almost always retrieve next entries along with count of available entries:
SELECT time, level, type, text FROM Logs
WHERE level IN (%s)
ORDER BY time DESC, id DESC
LIMIT LOG_REQ_LINES OFFSET %d* LOG_REQ_LINES ;
together with total count of records that can match current query:
SELECT count(*) FROM Logs WHERE level IN (%s);
(for a display "page n of m")
I wonder, if I could concatenate the two queries, and ask them both in one sqlite3_exec() simply concatenating the query string. How should my callback function look then? Can I distinguish between the different types of data by argc?
What other optimizations would you suggest?