【问题标题】:Why the interface sqlite3_get_table in SQLite C Interface is not recommended为什么不推荐使用 SQLite C 接口中的接口 sqlite3_get_table
【发布时间】:2013-02-14 03:24:16
【问题描述】:

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 */
);

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

但现在不推荐了:

这是为向后兼容而保留的旧接口。不推荐使用此接口。

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

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

欲了解更多信息,请参阅http://www.sqlite.org/c3ref/free_table.html

【问题讨论】:

    标签: c++ c sqlite


    【解决方案1】:

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

    你应该使用sqlite3_prepare_v2/sqlite3_step/sqlite3_column_xxx/sqlite3_finalize函数。

    【讨论】:

    • 但是我们可以使用sqlite3_free_table来发布结果记录,是吗?
    • 是的,但是内存必须一次性分配。
    • 一次性分配对程序影响太大吗?
    猜你喜欢
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 1970-01-01
    • 2012-01-21
    • 2018-07-04
    相关资源
    最近更新 更多