Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

"database table is locked Unable to fetch row"



  • Hello, I seem to be having issues with QSql.

    I am using QT 5.7 with mingw 32 compiler. When I try to drop a database table sql.exec() Return false and I receive the following error in lastError()->text(); "database table is locked Unable to fetch row".

    My SQL to delete the table is

    bool result = sql.exec("drop table SYSTEM_PROPERTIES"); // Always returns false and sets the above error.
    

    I can execute the above sql statement in a database manager without failure however.

    Thanks for any light you can shed on the matter.

    Chris--


  • Lifetime Qt Champion

    Hi,

    How many threads do you have in your application ?



  • Hi, not creating any threads so I assume the answer is just the main one.

    Thanks


  • Lifetime Qt Champion

    Any pending request on that table ?



  • @SGaist None that I know of, in fact I can make that the first call right after the database is opened and it fails. I am going to install the latest version of QT and see if the problem goes away. I'll post the results when this is completed.

    Thanks..


  • Lifetime Qt Champion

    What backend are you using ? MySQL, PostgreSQL ? SQLite ?



  • MySQL, but I found the problem, in my code I call select * from a database but I only wanted to get the first entry of the database so instead of letting the sql statement finish with a while(sql.next()) I called if(sql.next()) then processed my data thus not allowing sql to finish. As soon as I added sql.finish() my problem went away. What I don't understand is the select I was calling was on a different table than the one I Was trying to work with.

    Anyways, I'm in the process of updating all of my code to call sql.finish() on all sql statements.

    Thanks for your help on this.


  • Lifetime Qt Champion

    If you only want the first entry, why not use the LIMIT keyword with your query ? That way to don't have to resort to workaround like you are doing.



  • That's a good idea, thanks.


Log in to reply