Results 1 to 9 of 9

Thread: rollback issue with database

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default rollback issue with database

    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 :

    Qt Code:
    1. if ((transaction=m_dbm->DBM_setTransaction(this))==true)
    2. {
    3. if (m_dbm->DBM_updateTestCase(testCase,this))
    4. //in update TestCase is several insertions and updates called. I execute in this function several queries
    5. {
    6. if (m_dbm->DBM_commit(this))
    7. QMessageBox::information(this,"Message", QString("TestCase table has been successfully updated"),
    8. QMessageBox::Ok, QMessageBox::NoButton );
    9. }
    10. else
    11. {
    12. m_dbm->DBM_callRollback(this);
    13. QMessageBox::information(this,"Message", QString("Update of TestCase table has failed"),
    14. QMessageBox::Ok, QMessageBox::NoButton );
    15. }
    16. }
    17. else
    18. {
    19. if (m_dbm->DBM_updateTestCase(testCase,this))
    20. QMessageBox::information(this,"Message", QString("TestCase table has been successfully updated"),
    21. QMessageBox::Ok, QMessageBox::NoButton );
    22. else
    23. QMessageBox::information(this,"Message", QString("Update of TestCase table has failed"),
    24. QMessageBox::Ok, QMessageBox::NoButton );
    25. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by jacek; 16th February 2007 at 11:40. Reason: wrapped too long lines

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. updating database
    By locus in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2007, 05:54
  3. Database access issue
    By Gayathri in forum Newbie
    Replies: 3
    Last Post: 23rd November 2006, 07:41
  4. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.