Dave Hayden wrote:
I'm running into a deadlock, as the subject says, when doing updates on
a table in one thread while another thread is inserting into the same
table. (Oh, and this is on 3.0.4, compiled with --enable-threadsafe)
The update thread returns from its UPDATE command (within a transaction)
with SQLITE_BUSY when it sees a pending lock. The insert thread returns
SQLITE_BUSY from END TRANSACTION when it can't get an exclusive lock.
Attached is a simple C program that demonstrates this. I open two
database handles on the same file (with a table "test" with a single
column "num") and do:
db1: BEGIN TRANSACTION;
db2: BEGIN TRANSACTION;
db1: INSERT INTO test VALUES ( 1 );
At this point, both of these return SQLITE_BUSY:
db2: UPDATE test SET num = 2 WHERE num = 1;
db1: END TRANSACTION;
Is this a bug? Or do I have to do something with sqlite 3 I didn't with 2?
After the db1 transaction ends, the db2 UPDATE should be able to
complete. In version 2, db2 would have blocked when it tried to
begin the transaction. Version 3 allows db2 to continue future,
but you still cannot have two threads changing the same database
at the same time, so it also eventually blocks.
Works as designed.
--
D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565