count rows result set data

前端 未结 2 426
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 09:06

I have a SELECT query, and I would like to know the number of rows.

I tried:

sqlite3_data_count(statement);

but it always returns 0

相关标签:
2条回答
  • 2020-12-22 09:49

    SQLite computes the result rows on the fly, so you the number of rows is not known before you have actually read all those rows.

    You could execute a separate query SELECT COUNT(*) FROM (original query), but this would mean that the query is executed twice.

    Instead, you should use a data structure that grows dynamically.

    0 讨论(0)
  • 2020-12-22 10:09

    sqlite3_data_count is not counts row but counts columns.

    sqlite3_data_count returns the number of values (columns) of the currently executing statement. With no results it returns 0.
    LINK HERE
    You can verify it in .h doc for sqlite3_data_count().

    To count number of rows you can use following:

    SELECT COUNT(*) FROM "mytable"

    0 讨论(0)
提交回复
热议问题