Skip to content
On this page

sqlite3 C API


标签:clang/package  

📣 只含有最常用几条,详细的查看:https://www.sqlite.org/capi3ref.html

sqlite3_open

打开一个数据库。如果数据库不存在,将先创建数据库,并打开。

https://www.sqlite.org/capi3ref.html#sqlite3_open

c
int sqlite3_open(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb          /* OUT: SQLite db handle */
);
参数:
  char *filename:指定要打开的数据库的路径以及名字;
  sqlite3 **ppDb:该二级指针指向的一级指针中最终会被填充上,
                  被打开的数据库的首地址;
返回值:
    成功,返回SQLITE_OK,其实就是0;
    失败,返回error_code,其实就是非0;

sqlite3_close

https://www.sqlite.org/capi3ref.html#sqlite3_close

c
功能:关闭数据库,释放其在内存中的空间
    int sqlite3_close(sqlite3 *db);
参数:   
    sqlite3 *db:数据库的首地址;
返回值:
    成功,返回SQLITE_OK,其实就是0;
    失败,返回error_code,其实就是非0;

sqlite3_errmsg

https://www.sqlite.org/capi3ref.html#sqlite3_errcode

c
功能:根据error_code打印错误信息
    const char *sqlite3_errmsg(sqlite3 *db);
返回值:
    错误信息的字符串;

sqlite3_errcode

https://www.sqlite.org/capi3ref.html#sqlite3_errcode

c
功能:获取数据库提供的错误码,error_code;
    int sqlite3_errcode(sqlite3 *db);
返回值:
    错误码,error_code

sqlite3_exec

sqlite3_exec

sqlite3_get_table

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

sqlite3_mprintf

函数原型

功能:格式化字符串并动态分配内存

cpp
char* sqlite3_mprintf(const char *zFormat, ...);
  • 参数:
    • zFormat: 格式化字符串
    • ...:可变参数列表,对应格式化字符串中的占位符
  • 返回值:
    • char*: 动态分配的字符串指针

注意事项

  • sqlite3_mprintf() 函数使用与printf()函数相同的格式规范来格式化输出
  • 释放所分配的内存需要使用 sqlite3_free() 函数

Last updated: