Fix Statement destructor since addition of the move constructor

This commit is contained in:
Sébastien Rombauts 2019-03-05 07:15:06 +01:00
parent f2b1017710
commit 50425142fe

View File

@ -466,30 +466,32 @@ Statement::Ptr::Ptr(Ptr&& aPtr) :
aPtr.mpStmt = NULL; aPtr.mpStmt = NULL;
aPtr.mpRefCount = NULL; aPtr.mpRefCount = NULL;
} }
#endif #endif
/** /**
* @brief Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0 * @brief Decrement the ref counter and finalize the sqlite3_stmt when it reaches 0
*/ */
Statement::Ptr::~Ptr() Statement::Ptr::~Ptr()
{ {
assert(NULL != mpRefCount); if (NULL != mpRefCount)
assert(0 != *mpRefCount);
// Decrement and check the reference counter of the sqlite3_stmt
--(*mpRefCount);
if (0 == *mpRefCount)
{ {
// If count reaches zero, finalize the sqlite3_stmt, as no Statement nor Column objet use it anymore. assert(0 != *mpRefCount);
// No need to check the return code, as it is the same as the last statement evaluation.
sqlite3_finalize(mpStmt);
// and delete the reference counter // Decrement and check the reference counter of the sqlite3_stmt
delete mpRefCount; --(*mpRefCount);
mpRefCount = NULL; if (0 == *mpRefCount)
mpStmt = NULL; {
// If count reaches zero, finalize the sqlite3_stmt, as no Statement nor Column objet use it anymore.
// No need to check the return code, as it is the same as the last statement evaluation.
sqlite3_finalize(mpStmt);
// and delete the reference counter
delete mpRefCount;
mpRefCount = NULL;
mpStmt = NULL;
}
// else, the finalization will be done later, by the last object
} }
// else, the finalization will be done later, by the last object
} }