Sqlite3 C API 行数 [英] Sqlite3 C API number of rows
问题描述
我可以在 C 程序中使用 SELECT COUNT(*) from tableName
吗?
Can I use SELECT COUNT(*) from tableName
in a C program?
如果是这样,我如何获取结果?我不想使用循环,因为我只想要行数,而不是数据.
If so, how do I fetch the results? I don't want to use a loop because I only want the number of rows, not the data.
推荐答案
当您执行查询 SELECT COUNT(*) from tableName
时,结果与其他查询一样是一个表,但是那个结果table只有一列只有一行,包含计数值.
When you execute the query SELECT COUNT(*) from tableName
, the result is a table like with other queries, but that result table has only one column and only one row, which contains the count value.
正常调用sqlite3_prepare_v2
,然后是sqlite3_step
,它会步进到第一(也是唯一)行.调用 sqlite3_column_int
获取值.下一次调用 sqlite3_step
将返回 SQLITE_DONE
.
Call sqlite3_prepare_v2
normally, then sqlite3_step
, which steps to the first (and only) row.
Call sqlite3_column_int
to get the value.
The next call to sqlite3_step
will then return SQLITE_DONE
.
这篇关于Sqlite3 C API 行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!