Re: [sqlite] proposal for api

2012-05-14 Thread Nico Williams
On Mon, May 14, 2012 at 2:55 PM, Baruch Burstein  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


Re: [sqlite] proposal for api

2012-05-14 Thread Jay A. Kreibich
On Mon, May 14, 2012 at 10:55:35PM +0300, Baruch Burstein scratched on the wall:
> Assuming that sqlite knows how many rows are in a result set without having
> to sqlite3_step over each row,

  It doesn't.

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable." -- Angela Johnson
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] proposal for api

2012-05-14 Thread Baruch Burstein
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:

sqlite3_in64 sqlite3_rows(sqlite3_stmt *stmt)

which would run the query (if sqlite3_step has not been called on this stmt
object yet), and return the number of rows in the result set?

Or is my assumption that sqlite has this information wrong?

-- 
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.  - Rich Cook
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users