#134 wxSQLite3Transaction doesn't report error if Commit failed

closed-fixed
None
3
2011-07-06
2011-05-25
Anonymous
No

First I would like to congratulate for your great job with wxSQLite3.

I'm starting using it and with exception and wxWidgets supports, SQLite3 is really simple to use.
I'm lookinbg for transaction and I found your wxSQLite3Transaction that make the job even an exception is raised, my function use it like :

bool CMyDatabase::ExecuteUpdateWithTransaction(wxString _strSQL) throw(wxSQLite3Exception)
{
bool bRet = false;

if (IsOpened())
{
wxSQLite3Transaction transaction(m_pDatabase);
m_pDatabase->ExecuteUpdate(_strSQL);
transaction.Commit();
bRet = true;
}

return bRet;
}

But I have a question : why Commit function doesn't return a boolean or throw another exception ? Because if the commit failed no error and the transaction is roolback and the programmer think it is good.

Why don't do ?

void wxSQLite3Transaction::Commit()
{
try
{
m_database->Commit();
}
catch (wxSQLite3Exception &_rException)
{ // Propagate exception, destructor will make rollback
throw;
}
catch (...)
{ // Throw unknown exception (strange to catch ...), destructor will make rollback
throw wxSQLite3Exception(-1, wxT("Unknown error while execute commit"));
}
m_database = NULL;
}

What do you think about this evolution ?
Best regards,
Stéphane Château / Feneck91 (French).

Discussion

  • Ulrich Telle

    Ulrich Telle - 2011-05-26
    • assigned_to: nobody --> utelle
    • priority: 5 --> 3
    • status: open --> open-later
     
  • Ulrich Telle

    Ulrich Telle - 2011-05-26

    IMHO this isn't a severe bug since under most circumstances the class wxSQLite3Transaction works as expected. But I'll investigate the code to check whether applying your proposed changes would be useful.

     
  • Ulrich Telle

    Ulrich Telle - 2011-07-06

    The class wxSQLite3Transaction has been modified to be exception safe. In case the automatic rollback of a transaction fails the error state of the last rollback can be queried in the exception handling code.

     
  • Ulrich Telle

    Ulrich Telle - 2011-07-06
    • status: open-later --> closed-fixed
     

Log in to post a comment.