Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Sqlite and concurrency
QtWS25 Last Chance

[Solved] Sqlite and concurrency

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 6.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    portoist
    wrote on last edited by
    #1

    I know this isn't going to be much of Qt question. I have sqlite database open from my Qt application and i want to update sqlite database outside Qt app (ie from terminal, with Qt app running), if I try so i will get Error: database locked as database is locked by running Qt application. Is there any way to open sqlite database from Qt in a way it would support concurrent access? Or is this impossible?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      Sounds like you have an uncommited transaction in your qt application. The short answer should be: no. However, I'm not an expert of sql lite, I can suggest to have a look "here":http://sqlite.org/lockingv3.html.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        portoist
        wrote on last edited by
        #3

        I'v tried to open database with:
        @
        db.setConnectOptions("QSQLITE_OPEN_READONLY");
        @
        So that database should be opened only for reading by Qt. But if I run sqlite3 in terminal on same database file and do update I am still getting same error.
        However if I opened two terminals and run sqlite3 in each one of them with same database I am able to do updates and select on the same database without any errors...

        1 Reply Last reply
        0
        • P Offline
          P Offline
          portoist
          wrote on last edited by
          #4

          I found out what I did wrong. I have instanciated QSqlQuery, executed it and didn't destroyed it when it was done, so that might be it...
          [quote author="fluca1978" date="1319445374"]Sounds like you have an uncommited transaction in your qt application.[/quote]
          This lead me there, thanks!:-)

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            The problem probably lies in the "next":http://doc.qt.nokia.com/latest/qsqlquery.html#next method (and others like this). Usually queries are managed using cursors (it should be true also for qt), and a set of results are retrieved (and sometimes cached) from the database. Now this lead to the fact that the cursor provides a read lock on the tuples you wanted to update from the other terminal. And this leads to the error you were experiencing. Destroyng the query object means releasing the cursor, so the lock, and the trick is done.
            More complex databases use approaches like "MVCC" to allow a better concurrency even in this scenario.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved