"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--
-
Hi,
How many threads do you have in your application ?
-
Any pending request on that table ?
-
-
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.
-
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.