阅读文档后,似乎函数 sqlite3_column_count 的功能完全相同,但没有 sqlite3_data_count 的限制。
为什么我要使用 sqlite3_data_count 而不是 sqlite3_column_count?谢谢!
最佳答案
我已经查找了这两个函数的来源:
/*
** Return the number of columns in the result set for the statement pStmt.
*/
SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt){
Vdbe *pVm = (Vdbe *)pStmt;
return pVm ? pVm->nResColumn : 0;
}
/*
** Return the number of values available from the current row of the
** currently executing statement pStmt.
*/
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt){
Vdbe *pVm = (Vdbe *)pStmt;
if( pVm==0 || pVm->pResultSet==0 ) return 0;
return pVm->nResColumn;
}
现在很清楚区别是什么,所以 NickD 是对的。
顺便说一句,文档很糟糕:"The sqlite3_data_count(P) the number of columns in the of the result set of prepared statement P."这甚至不是正确的英文,函数定义附带的注释要好得多。
关于c - 在 SQLite C API 中使用 sqlite3_data_count() 而不是 sqlite3_column_count() 有什么好处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2228159/