Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit of using sqlite3_data_count() over sqlite3_column_count() in the SQLite C API?

Tags:

c

sqlite

api

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!

like image 641
Alex Jenter Avatar asked Dec 02 '22 06:12

Alex Jenter


1 Answers

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.

like image 181
Alex Jenter Avatar answered Jan 18 '23 23:01

Alex Jenter