Results 1 to 5 of 5

Thread: Problems with QSqlQuery update

  1. #1
    Join Date
    Jan 2006
    Location
    Kranj, Slovenia
    Posts
    34
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problems with QSqlQuery update

    Hi!

    In my code I have several QSqlQuery statements, each has different name and are used for selecting data and updating that data. When I select data from a table using the select query I caould not update that same table using update query until I cleared that query using QsqlQuery::clear(). Why is that necessary?

    Example code (not necessary working, just to see what I meant):
    Qt Code:
    1. QSqlQuery q_select1("SELECT * FROM table1 WHERE number LIKE '1'");
    2. int i_word = q_select1.record().value("word");
    3. q_select1.next();
    4. QString s_word = q_select1.value(i_word);
    5.  
    6. q_select1.clear();
    7.  
    8. QSqlQuery q_update1("UPDATE table1 SET word = 'new word' WHERE number = '1'");
    To copy to clipboard, switch view to plain text mode 
    Why the q_update1 did not work until i put q_select1 there?

    Thanks!
    Luka

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with QSqlQuery update

    Maybe SELECT statement locks the table? What database do you use?

  3. #3
    Join Date
    Jan 2006
    Location
    Kranj, Slovenia
    Posts
    34
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with QSqlQuery update

    i use sqlite 3. i also think that select lock the table, i just wanted to be sure that i am not doing something wrong and that this is the correct behaviour of the qt and sqlite. is it possible to do another select statement on the previously locked table but update would not work?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with QSqlQuery update

    Quote Originally Posted by whoops.slo
    i use sqlite 3. i also think that select lock the table, i just wanted to be sure that i am not doing something wrong and that this is the correct behaviour of the qt and sqlite.
    I don't use SQLite, but probably you can use "PRAGMA read_uncommitted = 1" as a workaround, but beware.

    Quote Originally Posted by whoops.slo
    is it possible to do another select statement on the previously locked table but update would not work?
    Yes, SELECT acquires a SHARED lock which allows only reading, but UPDATE tries to acquire an EXCLUSIVE lock which can't coexist with any other locks, thus it fails.

  5. #5
    Join Date
    Jan 2006
    Location
    Kranj, Slovenia
    Posts
    34
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Problems with QSqlQuery update

    thanks, that is what i wanted to know. now everything makes sence and my speculation was correct.

Similar Threads

  1. Replies: 9
    Last Post: 7th November 2006, 16:10
  2. Auto update module
    By munna in forum General Discussion
    Replies: 3
    Last Post: 26th September 2006, 15:52
  3. QTableWidget Update - slow
    By DPinLV in forum Qt Programming
    Replies: 16
    Last Post: 18th August 2006, 22:09
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 16:39
  5. Update a row
    By dragon in forum Newbie
    Replies: 9
    Last Post: 17th January 2006, 18:11

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.