Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML - Error: database table is locked Unable to fetch row
Forum Updated to NodeBB v4.3 + New Features

QML - Error: database table is locked Unable to fetch row

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 7.8k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    externc
    wrote on last edited by
    #1

    Hi Guys,

    I have encountered a frustratring problem with my application that I cannot explain. Basically, when I start the application, I am able to do anything involving the database BESIDES dropping tables (reproducable upon restart). If I try to drop a table, I get "Error: database table is locked Unable to fetch row"... but after any three transactions (select, insert etc..) I am able to drop a table. The only documentation I could find about using a database from QML was http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeglobalobject.html, and it is not very detailed.

    "This":https://gitorious.org/harmttan/scenic/blobs/master/qml/main.qml is my main QML file. On line 14, I select * from my main table, "wallpapers" and get the results just fine in a Component.onCompleted field. The code is in a stateless javascript library (.pragma) and is located "here":https://gitorious.org/harmttan/scenic/blobs/master/qml/Database.js, but they all look pretty much like this:

    @var db = openDatabaseSync('scenic', '1.0', 'Wallpaper database', 100000); //global

    function getAllPacks (){

    var returnArray;
    db.transaction(
                function(tx){
                    tx.executeSql('CREATE TABLE IF NOT EXISTS wallpapers(pack TEXT, name TEXT, path TEXT, key TEXT UNIQUE)');
                    returnArray = tx.executeSql("select distinct pack from wallpapers")
                }
                )
    return returnArray
    

    }@

    I really have no idea why it complains about DB locking and I am not sure where to look for help... Any guidance would be greatly appreciated! This is the only thing stopping me from publishing.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      externc
      wrote on last edited by
      #2

      bumping to hopefully resolve...

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hassan Kassem
        wrote on last edited by
        #3

        Hi externc,
        I am facing the same problem, how did you solved that?

        1 Reply Last reply
        0
        • E Offline
          E Offline
          externc
          wrote on last edited by
          #4

          Unfortunately, I was never able to resolve this. I ended up moving my database code to a QSqlQueryModel where I have more control. I suspect the problem was a Qt bug where the database connection was not properly closed.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dicksonleong
            wrote on last edited by
            #5

            Not sure but try to convert the

            @
            var db = openDatabaseSync('scenic', '1.0', 'Wallpaper database', 100000);
            @

            into a function and call everytime you wanna do transaction() with the database.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hassan Kassem
              wrote on last edited by
              #6

              Thanks externc, that's what I am doing now, if you can share your class I will be very appreciated.
              @Dickson: I was doing that and it doesn't work, what we need is a close function so that we can close the database every time a write access is done so that we ensure that the DB isn't locked, but the Offline Storage API doesn't offer that so we are forced to implemented with c++.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                externc
                wrote on last edited by
                #7

                No problem. The specific file you want is https://gitorious.org/scenic/scenic/blobs/master/scenicdbmodel.h. All of the source code is there as well in case you wanted to have a look at it, but I think https://gitorious.org/rewards-manager would be more helpful; its a similar app of mine.

                In the second link, I implement the database code in c++, but without using the QSqlQueryModel. I also use the objects that I create from the database in the QML code, which I didn't know how to do when I created Scenic.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Hassan Kassem
                  wrote on last edited by
                  #8

                  Thank you externc, it was very useful.

                  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