unable to close due to unfinalized statements or unfinished backups

sqlite关闭时出错.

    int res = sqlite3_close(_sqliteDB);
    if(res)
    {
        cout << "can't close database: " << sqlite3_errmsg(_sqliteDB) << endl;
        return -1;
    }

其中 res = 5, errmsg是"unable to close due to unfinalized statements or unfinished backups".

查了下原因, 是因为

Applications must finalize all prepared statements and close all BLOB handles associated with the sqlite3 object prior to attempting to close the object. If sqlite3_close() is called on a database connection that still has outstanding prepared statements or BLOB handles, then it returns SQLITE_BUSY.

其实是代码里打开一个sqlite3_stmt/sqlite3_blob, 就要及时关闭, 否则就会报这个错误, 就像对象只创建, 没有析构会造成内存泄露一样.
sqlite3_prepare_v2 要对应一个sqlite3_finalize,
sqlite3_blob_open要对应一个sqlite3_blob_close.

Applications should finalize all prepared statements, close all BLOB handles, and finish all sqlite3_backup objects associated with the sqlite3 object prior to attempting to close the object. If sqlite3_close_v2() is called on a database connection that still has outstanding prepared statements, BLOB handles, and/or sqlite3_backup objects then it returns SQLITE_OK and the deallocation of resources is deferred until all prepared statements, BLOB handles, and sqlite3_backup objects are also destroyed.

https://stackoverflow.com/questions/2144757/sqlite3-close-returns-error-code-5
http://www.sqlite.org/c3ref/close.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值