Wassim Gr
Wassim Gr

Reputation: 588

QSqlError("5", "Unable to fetch row", "database is locked")

I am getting this error "QSqlError("5", "Unable to fetch row", "database is locked")"

I have done my research and I think the problem arises from the fact that I am executing an INSERT query while the SELECT query is still active, which locks the database. Now I'd imagine people run into this problem often since it is common to write to a database based on the output of a SELECT query, so I wanted to ask what is the best way to solve this? Would I be able to fetch the query (using query.next()) after closing it with query.finish() to unlock the database? Or should I store the result in a temporary container, close the query then iterate over the temporary container?

Thank you very much in advance

Upvotes: 0

Views: 3052

Answers (1)

Higgsy
Higgsy

Reputation: 324

Do you have a database reader on when you run this? I had a similar issue that only occurred when I had DB Browser for SQLite running. Make sure that you don't have any other software that has your database file open. I don't always have this issue with using DB Browser for SQLite but when I do, closing the program fixes it.

It addition, I tend to run query.finish() after each query is complete, to ensure no interaction.

I hope this helps you out!

Upvotes: 1

Related Questions