前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >unable to close due to unfinalized statements or unfinished backups

unable to close due to unfinalized statements or unfinished backups

作者头像
望天
发布2019-03-13 16:38:01
2.7K0
发布2019-03-13 16:38:01
举报
文章被收录于专栏:along的开发之旅along的开发之旅

版权声明:欢迎传播,请标明出处。

https://cloud.tencent.com/developer/article/1402721

sqlite关闭时出错.

代码语言:javascript
复制
    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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年02月19日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档