1

I need get the number of row result a query in SQLite in C Example:

SELECT name, age FROM test WHERE age > 18

How i can get the number of rows this query in SQLite C.

I see the command sqlite3_total_changes() to affected row (When use INSERT, UPDATE, DELETE), sqlite3_column_count() to get the number of column, but i need the number of rows, sqlite3_column_bytes().

I need a function equal mysql_num_rows from PHP.

case the example return 3 lines, how i can get 3 lines SQLite?

masoud
  • 55,379
  • 16
  • 141
  • 208
Sileno Brito
  • 449
  • 1
  • 13
  • 31

1 Answers1

1

This is probably what you want:

SELECT Count(name) FROM test WHERE age > 18

This will count all rows in test where age > 18 and name is not null. If you want to count the ones with null name then use

SELECT Count(*) FROM test WHERE age > 18

Here is some documentation:

http://www.sqlite.org/lang_aggfunc.html

Hogan
  • 69,564
  • 10
  • 76
  • 117
  • do not can count the statment or buffer and div by return of sqlite3_column_bytes() ? is really necessary execute two sql? – Sileno Brito Mar 08 '13 at 21:10
  • Yes it is necessary -- or you can cache the results as a table and do a count on that. In most cases this will perform worse. – Hogan Mar 08 '13 at 21:25
  • SQLite calculates the currently returned rows on the fly while you're stepping through them; the total number is never known. – CL. Mar 08 '13 at 21:28