On Mon, May 14, 2012 at 2:55 PM, Baruch Burstein <bmburst...@gmail.com> wrote:
> Assuming that sqlite knows how many rows are in a result set without having
> to sqlite3_step over each row, can there be an api like:

As Jay Kreibich says, SQLite3 does not know a priori how many rows a
SELECT statement will produce.  (It can know for SELECTs with no table
sources, but that's not the case you're interested in, because you'd
know the answer there trivially too.)

There are select statements with table sources where SQLite3 could
trivially determine a *maximum* number of rows, such as statements of
this form: select ... from some_table where some_unique_column =
some_value.  You can imagine various variants (e.g., unions of such
queries) where the maximum number of result rows can be determined
just from the statement and current schema.  But outside such
statements the only way to know the number of rows they return is to
actually step through them.  You could wrap the query in a select
count(your_query_here), but SQLite3 will be stepping the sub-query
anyways, so if that leads you to running the query twice, effectively,
then you're wasting resources.

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

Reply via email to