Discussion:
[sqlite] Database is locked
Igor Korot
2016-07-09 23:06:25 UTC
Permalink
Hi,
Here is my situation.

I'm trying to write some software in C{++}. Everything works fine except
when I exit the program exit I get the error "Database is locked".
I am only trying to retrieve the information about the database (queries on
sqlite_master).

So here are my questions:
1. When the database file is locked does this mean that there is a
byte set somewhere in the db header? Most likely no, but I just want
to confirm
2. If the answer is no - is there a tool which will help identify which handle
is not closed/released?

Thank you.
Simon Slavin
2016-07-09 23:09:18 UTC
Permalink
Post by Igor Korot
I'm trying to write some software in C{++}. Everything works fine except
when I exit the program exit I get the error "Database is locked".
I am only trying to retrieve the information about the database (queries on
sqlite_master).
What command are you executing when you get "Database is locked" in return ?

Have you terminated your query properly ? Did you call sqlite_finalize() on it ? Did you get SQLITE_OK back from that call ?

Simon.
Igor Korot
2016-07-09 23:21:58 UTC
Permalink
Simon,
Post by Simon Slavin
Post by Igor Korot
I'm trying to write some software in C{++}. Everything works fine except
when I exit the program exit I get the error "Database is locked".
I am only trying to retrieve the information about the database (queries on
sqlite_master).
What command are you executing when you get "Database is locked" in return ?
sqlite3_close();
Post by Simon Slavin
Have you terminated your query properly ? Did you call sqlite_finalize() on it ? Did you get SQLITE_OK back from that call ?
Yes, everything is finalized. And no error on finalization is produced.
That's why I'm asking if there is a tool that can check what is open.

Thank you.
Post by Simon Slavin
Simon.
_______________________________________________
sqlite-users mailing list
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Dan Kennedy
2016-07-10 15:57:45 UTC
Permalink
Post by Igor Korot
Simon,
Post by Simon Slavin
Post by Igor Korot
I'm trying to write some software in C{++}. Everything works fine except
when I exit the program exit I get the error "Database is locked".
I am only trying to retrieve the information about the database (queries on
sqlite_master).
What command are you executing when you get "Database is locked" in return ?
sqlite3_close();
Post by Simon Slavin
Have you terminated your query properly ? Did you call sqlite_finalize() on it ? Did you get SQLITE_OK back from that call ?
Yes, everything is finalized. And no error on finalization is produced.
That's why I'm asking if there is a tool that can check what is open.
As I think you have surmised, you most likely have an unfinalized
statement handle hanging around somewhere. After sqlite3_close() fails,
use this:

https://www.sqlite.org/c3ref/next_stmt.html

to loop through any unfinalized statement handles. If you find such a
handle, this:

https://www.sqlite.org/c3ref/sql.html

can be useful for figuring out where it came from.

Dan.
Igor Korot
2016-07-10 17:54:05 UTC
Permalink
Dan,
Post by Igor Korot
Simon,
Post by Simon Slavin
Post by Igor Korot
I'm trying to write some software in C{++}. Everything works fine except
when I exit the program exit I get the error "Database is locked".
I am only trying to retrieve the information about the database (queries on
sqlite_master).
What command are you executing when you get "Database is locked" in return ?
sqlite3_close();
Post by Simon Slavin
Have you terminated your query properly ? Did you call sqlite_finalize()
on it ? Did you get SQLITE_OK back from that call ?
Yes, everything is finalized. And no error on finalization is produced.
That's why I'm asking if there is a tool that can check what is open.
As I think you have surmised, you most likely have an unfinalized statement
https://www.sqlite.org/c3ref/next_stmt.html
to loop through any unfinalized statement handles. If you find such a
https://www.sqlite.org/c3ref/sql.html
can be useful for figuring out where it came from.
Thank you.
The culprit was identified.

Now it is time to fix it.
Dan.
_______________________________________________
sqlite-users mailing list
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Continue reading on narkive:
Loading...