Results 1 to 6 of 6

Thread: SQLite sometimes doens't INSERT into database

  1. #1
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default SQLite sometimes doens't INSERT into database

    Hi folks,

    I have a weird problem with SQLite in Qt.

    First, here is my code:
    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("INSERT INTO details (parentid,value) VALUES(?,?)");
    3. query.bindValue(0,parenid);
    4. query.bindValue(1,value);
    5. query.exec();
    To copy to clipboard, switch view to plain text mode 

    Sometimes this query doesn't save the entry in the database. The value is then available for an SELECT Statement while the program is running but if I close the program and start it again the value isn't there anymore. I'm not using a memory database and other statements are saved in the DB. The weird thing ist, that sometimes the query saves the entry and sometimes it doesn't.

    So does anybody know how to solve this?

  2. #2
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SQLite sometimes doens't INSERT into database

    Hi, I met the same problem. In a nutshell your INSERT go to journal file (read this) and you see the data until you are connected with the database(after a restart you probably won't see the data). In order to avoid that behavior you have to release all the resources like the QSqlQueryModel using the clear() function before updating the DB and refresh the Model/View after that.

  3. #3
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    29
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SQLite sometimes doens't INSERT into database

    Thank you for that little hint.
    Everything works fine now.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: SQLite sometimes doens't INSERT into database

    If you put the insert into a transaction and then commit it everything should be written to disc. Do you still get lost data?

  5. #5
    Join Date
    Oct 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SQLite sometimes doens't INSERT into database

    On some operating systems (windows) I have found that the commit will fail (leaving a journal file) if any of your sql statements are still active. It is necessary to use the clear() function on all active sql statements before the commit.

  6. #6
    Join Date
    May 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: SQLite sometimes doens't INSERT into database

    Hello Cydside, I'm facing the very same problem, but i don't understand your hint. Can you please post some code? Thx Merkura

Similar Threads

  1. Insert unicode in SQlite
    By Kastagne in forum Qt Programming
    Replies: 3
    Last Post: 11th October 2011, 14:07
  2. How can I send a SQLite :memory: database connection ?
    By georgep in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2009, 12:07
  3. Replies: 1
    Last Post: 26th March 2009, 15:25
  4. Bulk insert into SQLite
    By munna in forum Qt Programming
    Replies: 6
    Last Post: 19th November 2007, 03:56
  5. SQLITE database problems
    By phoenix in forum Newbie
    Replies: 3
    Last Post: 30th April 2007, 21:38

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.