Djony
16th February 2007, 11:24
I am developing Qt application which connects to MySQL database. I want to use rollback() method when insertion of some table fails (for example, if insertion of new record in table goes ok, but insertion of record in relation table fails for some reason, I would like to rollback insertion of succesfully inserted record in table). Now, this is my code :
if ((transaction=m_dbm->DBM_setTransaction(this))==true)
{
if (m_dbm->DBM_updateTestCase(testCase,this))
//in update TestCase is several insertions and updates called. I execute in this function several queries
{
if (m_dbm->DBM_commit(this))
QMessageBox::information(this,"Message", QString("TestCase table has been successfully updated"),
QMessageBox::Ok, QMessageBox::NoButton );
}
else
{
m_dbm->DBM_callRollback(this);
QMessageBox::information(this,"Message", QString("Update of TestCase table has failed"),
QMessageBox::Ok, QMessageBox::NoButton );
}
}
else
{
if (m_dbm->DBM_updateTestCase(testCase,this))
QMessageBox::information(this,"Message", QString("TestCase table has been successfully updated"),
QMessageBox::Ok, QMessageBox::NoButton );
else
QMessageBox::information(this,"Message", QString("Update of TestCase table has failed"),
QMessageBox::Ok, QMessageBox::NoButton );
}
Now, when my insertion fails (which i know by qsqlquery messages) shown code doesn't rolls back data inserted in function DBM_updateTestCase. I don't know what am I doing wrong. Thanx for any reply.
if ((transaction=m_dbm->DBM_setTransaction(this))==true)
{
if (m_dbm->DBM_updateTestCase(testCase,this))
//in update TestCase is several insertions and updates called. I execute in this function several queries
{
if (m_dbm->DBM_commit(this))
QMessageBox::information(this,"Message", QString("TestCase table has been successfully updated"),
QMessageBox::Ok, QMessageBox::NoButton );
}
else
{
m_dbm->DBM_callRollback(this);
QMessageBox::information(this,"Message", QString("Update of TestCase table has failed"),
QMessageBox::Ok, QMessageBox::NoButton );
}
}
else
{
if (m_dbm->DBM_updateTestCase(testCase,this))
QMessageBox::information(this,"Message", QString("TestCase table has been successfully updated"),
QMessageBox::Ok, QMessageBox::NoButton );
else
QMessageBox::information(this,"Message", QString("Update of TestCase table has failed"),
QMessageBox::Ok, QMessageBox::NoButton );
}
Now, when my insertion fails (which i know by qsqlquery messages) shown code doesn't rolls back data inserted in function DBM_updateTestCase. I don't know what am I doing wrong. Thanx for any reply.