c++ - 为什么不推荐SQLite C接口(interface)中的接口(interface)sqlite3_get_table

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

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

但现在不推荐:

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

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

所以我的问题是这个接口(interface)的主要问题是什么?为什么需要弃用它?

有关详细信息,请参阅 http://www.sqlite.org/c3ref/free_table.html .

最佳答案

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

你应该使用 sqlite3_prepare_v2/sqlite3_step/sqlite3_column_xxx/sqlite3_finalize功能。

关于c++ - 为什么不推荐SQLite C接口(interface)中的接口(interface)sqlite3_get_table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15127029/

相关文章:

c++ - 一个简单的 C++ 函数,在不同的计算机上有不同的答案

c++ - 没有看到 qInfo() 的输出

database - 在 SQLite 数据库中存储行的详细信息

c++ - 是否可以内联 lambda 表达式?

c++ - 如何在 asmjit 中获取当前指令?

c - scanf或getchar一次10000次然后程序在c中停止

c - 静态变量声明 (C)

c - 需要加密文件我已全部写入但读取文件时出错

android - 对数据库中的元素进行排序

Android 无法调用 SQLite WHERE column LIKE '%?%' The statement has 0 parameters