views:

138

answers:

2

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
The OP specifically asked for a way to *avoid* `COUNT`.
dan04
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
Thanks dan, incrementing the variable seems to be the easiest way.
Christopher Brady