Results from two queries at once in sqlite?

Posted by SF. on Stack Overflow See other posts from Stack Overflow or by SF.
Published on 2010-04-23T08:53:48Z Indexed on 2010/04/23 21:43 UTC
Read the original article Hit count: 172

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about sqlite

Related posts about sql