@@ -181,7 +181,8 @@ bool Statement::executeStep()
181181{
182182 if (false == mbDone)
183183 {
184- int ret = sqlite3_step (mStmtPtr );
184+ int ret = sqlite3_step (mStmtPtr ) ;
185+ mStmtPtr .setLastStatus (ret);
185186 if (SQLITE_ROW == ret) // one row is ready : call getColumn(N) to access it
186187 {
187188 mbOk = true ;
@@ -200,7 +201,7 @@ bool Statement::executeStep()
200201 }
201202 else
202203 {
203- throw SQLite::Exception (" Statement need to be reseted " );
204+ throw SQLite::Exception (" Statement needs to be reset " );
204205 }
205206
206207 return mbOk; // true only if one row is accessible by getColumn(N)
@@ -212,6 +213,7 @@ int Statement::exec()
212213 if (false == mbDone)
213214 {
214215 int ret = sqlite3_step (mStmtPtr );
216+ mStmtPtr .setLastStatus (ret);
215217 if (SQLITE_DONE == ret) // the statement has finished executing successfully
216218 {
217219 mbOk = false ;
@@ -272,8 +274,9 @@ bool Statement::isColumnNull(const int aIndex) const
272274}
273275
274276// Check if aRet equal SQLITE_OK, else throw a SQLite::Exception with the SQLite error message
275- void Statement::check (const int aRet) const
277+ void Statement::check (const int aRet)
276278{
279+ mStmtPtr .setLastStatus (aRet) ;
277280 if (SQLITE_OK != aRet)
278281 {
279282 throw SQLite::Exception (sqlite3_errmsg (mStmtPtr ));
@@ -294,10 +297,11 @@ void Statement::check(const int aRet) const
294297Statement::Ptr::Ptr (sqlite3* apSQLite, std::string& aQuery) :
295298 mpSQLite (apSQLite),
296299 mpStmt (NULL ),
297- mpRefCount (NULL )
300+ mpRefCount (NULL ),
301+ mLastStatus (SQLITE_OK)
298302{
299- int ret = sqlite3_prepare_v2 (apSQLite, aQuery.c_str (), static_cast <int >(aQuery.size ()), &mpStmt, NULL );
300- if (SQLITE_OK != ret )
303+ mLastStatus = sqlite3_prepare_v2 (apSQLite, aQuery.c_str (), static_cast <int >(aQuery.size ()), &mpStmt, NULL );
304+ if (SQLITE_OK != mLastStatus )
301305 {
302306 throw SQLite::Exception (sqlite3_errmsg (mpSQLite));
303307 }
@@ -315,7 +319,8 @@ Statement::Ptr::Ptr(sqlite3* apSQLite, std::string& aQuery) :
315319Statement::Ptr::Ptr (const Statement::Ptr& aPtr) :
316320 mpSQLite (aPtr.mpSQLite),
317321 mpStmt (aPtr.mpStmt),
318- mpRefCount (aPtr.mpRefCount)
322+ mpRefCount (aPtr.mpRefCount),
323+ mLastStatus (SQLITE_OK)
319324{
320325 assert (NULL != mpRefCount);
321326 assert (0 != *mpRefCount);
@@ -341,7 +346,7 @@ Statement::Ptr::~Ptr() noexcept // nothrow
341346 // as no Statement not Column objet use it anymore
342347 int ret = sqlite3_finalize (mpStmt);
343348 // Never throw an exception in a destructor
344- SQLITECPP_ASSERT (SQLITE_OK == ret, sqlite3_errmsg (mpSQLite)); // See SQLITECPP_ENABLE_ASSERT_HANDLER
349+ SQLITECPP_ASSERT (( SQLITE_OK == ret || mLastStatus == ret) , sqlite3_errmsg (mpSQLite)); // See SQLITECPP_ENABLE_ASSERT_HANDLER
345350
346351 // and delete the reference counter
347352 delete mpRefCount;
0 commit comments