Results 1 to 5 of 5

Thread: SQLite + journal + lock

  1. #1
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default SQLite + journal + lock

    Hey @all,

    i use SQLite for my application. Currently it seems that a database lock occurs.

    What i'm trying to do is to delete multiple rows from the database. When I'm doing this, a FILE-journal file is created. But this file aren't removed when the delete process is finished. So it seems that this is a database lock.
    When i restart the application, the rows that I removed before are still there.

    I use a editable QSqlQueryModel for this.

    Hope someone can help me

    Thanks in advance

    Best Regards
    NoRulez

  2. #2
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SQLite + journal + lock

    Hi, see my answer here. Looks like your problem as well.
    Cheers,
    -- Tanuki

  3. #3
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: SQLite + journal + lock

    Thank you, i've tried it, but it didn't solve the problem.

    The filesize of the journal is, of the application is running 0 kb.
    When I exit the application the file size of the journal file is >= 2kb and <= 23 kb.
    The changes are also not made, after i restart the application

    Best Regards
    NoRulez

  4. #4
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: SQLite + journal + lock

    Ok, I think the problem has to do with the following message i noticed, when I exit the application:
    [4580] QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.

    How can i find out, on which point the database connection is still alive?

    Best Regards
    NoRulez

  5. #5
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SQLite + journal + lock

    Nope. You see that message because database plugins in Qt implemented as static singletons. It is just warns you that it closes the db and will cease all current connections used by your app. But anyway, it is extremely strange if you cannot write anything in db because of locks. So if you will answer a couple of questions then maybe I could suggest you something.
    1. Does your app the only one who use that db?
    2. Which else apps are using it?

    If your app is the only one, try to open just one connection with non-default name (see SessionName parameter in QSqlDatabase::addDatabase) and try to perform some stupid insert there. And don't forget to process the query errors. May be you have wrong syntax in query itself. Another possible issue is that if you use transactions - please be sure you either commit or rollback that before jumping to some other place of your app. So make it consistent like that:

    Qt Code:
    1. QSqlDatabase m_db = QSqlDatabase::addDatabase("QSQLITE", "MyTestConnection");
    2.  
    3. // ... database verification code. I skip that but you can see the example in qt examples or my previous post.
    4.  
    5. // And query itself
    6. bool batch = m_db.transaction ();
    7. // ... Your batch queries
    8. if (batch)
    9. m_db.commit();
    To copy to clipboard, switch view to plain text mode 

    If you leave transaction block when you already started transaction and didn't finish it - yeah it will block. That's logical.

    Best regards,
    -- tanuki

Similar Threads

  1. sqlite read lock.
    By gilgm in forum Qt Programming
    Replies: 6
    Last Post: 18th June 2010, 05:58
  2. QSqlite database lock + Delegate + QSqlQueryModel
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2009, 11:52
  3. steps to connect to SQLite from Q
    By Qt Coder in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2009, 12:12
  4. Qt SQLite user functions
    By cevou in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2009, 19:43
  5. sqlite version in Qt
    By janus in forum Newbie
    Replies: 4
    Last Post: 5th February 2009, 14:18

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.