Results 1 to 2 of 2

Thread: Sqlite commit says no transaction is open

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Sqlite commit says no transaction is open

    Hello everyone ,

    I have a problem and I couldn't find why? this is my program but every time commit returns false it says commit without any open transaction.
    • I use sqlite.
    • I havent any open query
    • All functions has local QSqlQuery so they killed after finishing
    • Without transaction everything works fine



    Qt Code:
    1. // this is my sqlDB code
    2. // QSqlDatabase &DataManager::mainDB()
    3. //{
    4. // return db;
    5. //}
    6. //
    7.  
    8. CompanyMembersTable cmp(&sqlDB);
    9.  
    10. QString lerror;
    11. if(sqlDB.mainDB().transaction())
    12. {
    13. if(cmp.removeMembers(customer.nationalcode))
    14. {
    15. if(cst.updateEntity(customer.id(), &customer)) {
    16. for(int i=0; i<ui->lstCompMem->count(); i++) {
    17. QString nationlid = ui->lstCompMem->item(i)->data(Qt::UserRole).toString();
    18.  
    19. Customer cust;
    20. cust.nationalid = nationlid;
    21.  
    22. if(cmp.insertMember(&customer, &cust) <= 0)
    23. {
    24. lerror = cmp.lastError();
    25. break;
    26. }
    27. }
    28. if(lerror.isEmpty() && sqlDB.mainDB().commit() ) {
    29. QMessageBox::information(this, tr("Success Edit"), tr("Customer Updated successfully"));
    30. emit saved();
    31. return;
    32. }
    33. else if(lerror.isEmpty()) {
    34. lerror = sqlDB.mainDB().lastError().text();
    35. }
    36. }
    37. else lerror = cst.lastError();
    38. }
    39. else lerror = cmp.lastError();
    40. }
    41. else lerror = sqlDB.mainDB().lastError().text();
    42.  
    43. sqlDB.mainDB().rollback();
    44. QMessageBox::critical(this, tr("Edit Error"), tr("Error Happend.\n%1").arg(lerror), tr("OK"));
    45. return;
    To copy to clipboard, switch view to plain text mode 

    and I should mention that the below code work fine
    Qt Code:
    1. CustomerTable cst(&sqlDB);
    2. CompanyMembersTable cmb(&sqlDB);
    3.  
    4. sqlDB.mainDB().transaction();
    5. if(cst.insertEntity(&customer) > 0)
    6. {
    7. foreach (Customer cust, customer.members) {
    8. if(cmb.insertMember(&customer, &cust) <= 0)
    9. {
    10. goto ercust;
    11. }
    12. }
    13. if(sqlDB.mainDB().commit()) {
    14. QMessageBox::information(this, tr("Success Insert"), tr("Customer inserted successfully"));
    15. return;
    16. }
    17. }
    18.  
    19. ercust:
    20. QMessageBox::critical(this, tr("Error Insert"), tr("There is an error in inserting customer\n%1").arg(cst.lastError()));
    21. sqlDB.mainDB().rollback();
    To copy to clipboard, switch view to plain text mode 

    I want to know in witch situations a transaction would be canceled automatically.
    thanks in advance

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Sqlite commit says no transaction is open

    You'll need to post more of your code, I have no idea what Customer and CompanyMembersTable is doing for example
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Replies: 6
    Last Post: 17th January 2011, 22:56
  2. Qt Creator Mercurial - Cannot commit,status etc
    By Kerubu in forum Qt Tools
    Replies: 2
    Last Post: 12th August 2010, 15:58
  3. Unable to commit transaction
    By cydside in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 08:47
  4. SQLite - QSqlDatabase::transaction()
    By whitefurrows in forum Qt Programming
    Replies: 6
    Last Post: 5th May 2009, 17:06
  5. svn commit error on XP using Qt creator
    By yycking in forum General Discussion
    Replies: 3
    Last Post: 10th April 2009, 09:47

Tags for this Thread

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.