Discussion:
[sqlite] database table is locked
Marcel Strittmatter
2005-03-16 17:05:51 UTC
Permalink
Hi all

When I try to insert data into a table, sqlite3 responses with
SQLITE_ERROR and the error message: "database table is locked". I
searched already for unfinalized statements but couln't find any. The
insert statement is not executed while a query is active...

The problem exists only on Windows (local storage), on Linux everything
(except known nfs problems) works well (same code).

My question: Is there a "easy" way to test if a table is locked? Are
there other possibilities to help debug such a problem (I already tried
sqlit3_trace, but this doesn't help much because I don't see if a query
is finalized or not).

Marcel
Jakub Adamek
2005-03-16 21:40:57 UTC
Permalink
Hello,

I had a similar experience, but there was too much code to create a
simple bug report. Surprisingly, the error disappeared if I first made a
"SELECT FROM table" before the "INSERT INTO table" on the same table.
Also the error description "database TABLE is locked" is sometimes wrong
because it is the whole database which is locked. Perhaps another error
code/message should be created for "database is locked" (e.g. with open
cursors).

Jakub
Post by Marcel Strittmatter
Hi all
When I try to insert data into a table, sqlite3 responses with
SQLITE_ERROR and the error message: "database table is locked". I
searched already for unfinalized statements but couln't find any. The
insert statement is not executed while a query is active...
The problem exists only on Windows (local storage), on Linux everything
(except known nfs problems) works well (same code).
My question: Is there a "easy" way to test if a table is locked? Are
there other possibilities to help debug such a problem (I already tried
sqlit3_trace, but this doesn't help much because I don't see if a query
is finalized or not).
Marcel
D. Richard Hipp
2005-03-16 21:45:43 UTC
Permalink
Post by Jakub Adamek
Also the error description "database TABLE is locked" is sometimes wrong
because it is the whole database which is locked. Perhaps another error
code/message should be created for "database is locked" (e.g. with open
cursors).
There are two different errors:

SQLITE_BUSY - another process has the whole database locked
SQLITE_LOCKED - one sqlite3_step() is trying to read (or write)
the same table that another sqlite3_step() is
writing (or reading) using the same DB handle.

It sounds as if Mr. Strittmatter is getting the second error.
The cause of SQLITE_LOCKED is usually because you failed to
sqlite3_finalize() the previous statement.
--
D. Richard Hipp <drh-***@public.gmane.org>
Marcel Strittmatter
2005-03-16 23:06:45 UTC
Permalink
Post by D. Richard Hipp
SQLITE_BUSY - another process has the whole database locked
SQLITE_LOCKED - one sqlite3_step() is trying to read (or write)
the same table that another sqlite3_step() is
writing (or reading) using the same DB handle.
It sounds as if Mr. Strittmatter is getting the second error.
The cause of SQLITE_LOCKED is usually because you failed to
sqlite3_finalize() the previous statement.
Yes. That's right. I found the missing sqlite3_finalize() command. But
why did it work on Linux and failed on Windows? Maybe because I work
with nfs on Linux? Whatever... my problem is solved. Thanks for the
help!

Marcel

Loading...