为什么不推荐SQLite C接口中的接口sqlite3_get_table

pkt*_*yue 5 c c++ sqlite

sqlite3_get_table 定义如下:

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 */
);
Run Code Online (Sandbox Code Playgroud)

正如文档中所述,它可以方便地获得结果表,并作为sqlite3_exec()的包装器实现.

但现在不推荐:

这是一个保留用于向后兼容的传统接口.建议不要使用此界面.

但是如果我使用sqlite3_exec,我需要编写一个额外的回调函数.它更复杂.

所以我的问题是这个界面的主要问题是什么?为什么需要弃用?

有关更多信息,请访问http://www.sqlite.org/c3ref/free_table.html.

CL.*_*CL. 5

问题sqlite3_get_table是所有值都转换为字符串,并且必须为所有结果记录分配内存.

您应该使用sqlite3_prepare_v2/sqlite3_step/sqlite3_column_xxx/sqlite3_finalize函数.