On 18 Sep 2017, at 10:41am, David Wellman <dwell...@ward-analytics.com> wrote:

> So to answer my original question: there isn't an api that gives this value 
> ** because ** SQLite doesn't build the full answer set before returning from 
> that first sqlite3_step function call.

Correct.  SQLite knows how many results it will return only when you tell it to 
take another sqlite3_step() and it cannot find any more rows which fit your 
"WHERE" clause.

This is because SQLite was designed to be small and work on tiny embedded 
computers (i.e. a handheld recording device or nowdays a watch) and storing the 
complete result-set before returning the first row might take a lot of memory.  
It might have thousands of rows in.

If you want to know how many rows will be returned, use

SELECT COUNT(*) WHERE whatever

This returns just one row, and does its calculation without having to store 
each row that satisfies the WHERE clause.  With an appropriate index it can be 
surprisingly fast and might let your application work the way you had expected.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to