sqlite3:由于未完成的语句而无法关闭 [英] sqlite3:Unable to close due to unfinalised statements

查看:386
本文介绍了sqlite3:由于未完成的语句而无法关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个sqlite连接,执行如下(CMyDatabase是sqlite3的派生类):

I have two sqlite connections and execute like below(CMyDatabase is a derived class of sqlite3):

CMyDatabase* dbConnection1 = new CMyDatabase;
dbConnection1->OpenDataBase(CQCommon::GetModulePath() + L"test.db");

CMyDatabase* dbConnection2 = new CMyDatabase;
dbConnection2->OpenDataBase(CQCommon::GetModulePath() + L"test.db");

dbConnection2->BeginTrans();
CString updateStr("update ImageAlbumEntry set ImageID = 2 where ID = 1;");
dbConnection2->ExecNoQuery(updateStr);
CString queryStr("select ImageID from ImageAlbumEntry where ID = 1;");
CppSQLite3Query queryResult;
dbConnection2->ExecQuery(queryStr, queryResult);
cout<<queryResult.getIntField(0)<<endl;
dbConnection2->EndTrans(TRUE);

dbConnection2->CloseDataBase();
dbConnection1->CloseDataBase();

现在,当我调用dbConnection1-> CloseDataBase()时。我遇到了错误消息由于未完成的陈述而无法关闭。谁能解释问题的原因和解决方法?谢谢!

Now when I invoke dbConnection1->CloseDataBase(). I met with the error stated as 'Unable to close due to unfinalised statements'. Can anyone explain the reason and resolve method of the problem? Thank you!

推荐答案

取决于您使用的包装器。我猜您正在使用与 cppSQLite3

Depends on which wrapper you are using. I'm guessing you are using one similar to cppSQLite3

如果是这样,那么您需要发出 CppSQLite3Query :: finalize 命令来告诉sqlite3您已完成操作查询。

If that is true, then you need to issue a CppSQLite3Query::finalize command to to tell sqlite3 that you are done with your query.

从sqlite3文档中此处

From the sqlite3 documentation here

sqlite3_finalize()

此例程销毁由对sqlite3_prepare()的先前调用创建的准备好的语句。为了避免内存泄漏,必须使用对此例程的调用销毁每个准备好的语句。

sqlite3_finalize()
This routine destroys a prepared statement created by a prior call to sqlite3_prepare(). Every prepared statement must be destroyed using a call to this routine in order to avoid memory leaks.

这篇关于sqlite3:由于未完成的语句而无法关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆