Search code examples
cselectsqlitecountmysql-num-rows

How get number of rows result a query in SQL (C ANSI)?


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?


Solution

  • 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