views:

1314

answers:

1

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();

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!

+3  A: 

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

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

From the sqlite3 documentation here

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.

Noah