Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the interface sqlite3_get_table in SQLite C Interface is not recommended

Tags:

c++

c

sqlite

sqlite3_get_table is defined as below:

int sqlite3_get_table(
  sqlite3 *db,          /* An open database */
  const char *zSql,     /* SQL to be evaluated */
  char ***pazResult,    /* Results of the query */
  int *pnRow,           /* Number of result rows written here */
  int *pnColumn,        /* Number of result columns written here */
  char **pzErrmsg       /* Error msg written here */
);

As it said in the document, it can get a result table convenient and is implemented as a wrapper around sqlite3_exec().

But it is now not recommended:

This is a legacy interface that is preserved for backwards compatibility. Use of this interface is not recommended.

But if I use sqlite3_exec, I need to write a extra callback function. It is more complex。

So my question is what the main problem of this interface is? Why it need to be deprecated?

For more information see http://www.sqlite.org/c3ref/free_table.html.

like image 203
pktangyue Avatar asked Feb 28 '13 03:02

pktangyue


1 Answers

The problems with sqlite3_get_table are that all values are converted to strings, and that memory must be allocated for all result records.

You are supposed to use the sqlite3_prepare_v2/sqlite3_step/sqlite3_column_xxx/sqlite3_finalize functions.

like image 117
CL. Avatar answered Sep 19 '22 23:09

CL.