After reading the docs, it seems the the function sqlite3_column_count does all the same, but doesn't have the restrictions that sqlite3_data_count has.
Why would I ever want to use sqlite3_data_count over sqlite3_column_count? thanks!
After reading the docs, it seems the the function sqlite3_column_count does all the same, but doesn't have the restrictions that sqlite3_data_count has.
Why would I ever want to use sqlite3_data_count over sqlite3_column_count? thanks!
sqlite3_data_count
returns the number of values (columns) of the currently executing statement.
With no results it returns 0.
sqlite3_column_count
on the other hand, returns always the number of columns, with or without results.
Which one you'll use depends on whether you must get the number of columns or not.
I've looked up the sources of the two functions:
/*
** 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;
}
Now it is clear what the difference is, so NickD was right.
By the way, the documentation is horrible: "The sqlite3_data_count(P) the number of columns in the of the result set of prepared statement P." That's not even correct English, the comments that come with the function definitions are much better.