Results 1 to 5 of 5

Thread: SQLITE Transactions

  1. #1
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default SQLITE Transactions

    Hi all,

    I've noticed that QSqlDatabase::transaction() and QSqlDriver::beginTransaction() don't work when using QSQLITE driver.

    Using QSqlQuery::exec("BEGIN TRANSACTION") work correctly.

    It's a bug?

    PS. both QSqlDatabase::transaction() and QSqlDriver::beginTransaction() return true for correct execution

    Example code
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2.  
    3. db.transaction(); // returns true
    4. for (int i = 0; i < 1000; ++i)
    5. {
    6. // INSERT data
    7. }
    8. db.commit(); // returns true
    To copy to clipboard, switch view to plain text mode 
    doesn't work

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2.  
    3. QSqlQuery q(db);
    4. q.exec("BEGIN TRANSACTION");
    5. for (int i = 0; i < 1000; ++i)
    6. {
    7. // INSERT data
    8. }
    9. q.exec("COMMIT");
    To copy to clipboard, switch view to plain text mode 
    works correctly.
    A camel can go 14 days without drink,
    I can't!!!

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLITE Transactions

    yes, it doesnt work cuz for SQLite driver, in the transaction() function, Qt only executes "BEGIN" instead of "BEGIN TRANSACTION"..now why they did that is unclear..i think even PostgreSQL also has that limitation..dont clearly remember..ciao

  3. #3
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: SQLITE Transactions

    HI,

    AFIAK there is no difference in sqlite using "BEGIN" or "BEGIN TRANSACTION"

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLITE Transactions

    hmm..i checked it on my end again and guess what, its working..i went through the code for sqlite in Qt and confirmed they R executing just BEGIN..so i guess, there must be something missing in your code..

  5. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SQLITE Transactions

    q.exec("BEGIN TRANSACTION");
    for (int i = 0; i < 1000; ++i)
    {
    // INSERT data
    }
    q.exec("COMMIT");
    why dont u try executing just "BEGIN" at the start of the loop, just like sqlite does and see what happens

Similar Threads

  1. Good practices for export<->import SQLite datas
    By oscar in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2009, 04:24
  2. Qt SQLite user functions
    By cevou in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2009, 19:43
  3. sqlite version in Qt
    By janus in forum Newbie
    Replies: 4
    Last Post: 5th February 2009, 14:18
  4. SQLite
    By cyberboy in forum Installation and Deployment
    Replies: 1
    Last Post: 15th April 2008, 19:46
  5. sqlbrowser and sqlite
    By janus in forum Installation and Deployment
    Replies: 2
    Last Post: 31st March 2008, 14:59

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.