Is there any easy way to get the number of rows returned by a sqlite statement? I don't want to have to go through the process of doing a COUNT() first. Thanks.
A:
To count all entries in a table, you can use the following SQL statement:
SELECT COUNT(*) FROM "mytable" where something=42;
Or just the following to get all entries:
SELECT COUNT(*) FROM "mytable";
In case you have already done the query, and just want the number of entries returned you can use sqlite3_data_count()
and sqlite3_column_count()
depending on what you want to count.
Claus Broch
2010-05-12 21:12:13
The OP specifically asked for a way to *avoid* `COUNT`.
dan04
2010-05-13 00:44:50
A:
On each call to sqlite_step
, increment a variable by 1.
If you want the row count in advance, then there's no easy way.
dan04
2010-05-13 00:53:38
Thanks dan, incrementing the variable seems to be the easiest way.
Christopher Brady
2010-05-14 14:26:25