On 2/22/2018 5:54 AM, Nick wrote:
I use sqlite3_open() to open two connections, and I have configured
journal_mode=WAL, threadsafe=2.

Connection 1 is doing:
sqlite3_exec(db1, "BEGIN", 0, 0, &zErrMsg);
sqlite3_exec(db1, "SELECT * FROM t1;", 0, 0, &zErrMsg);
sqlite3_exec(db1, "INSERT INTO t1 VALUES(1, 1, \"aa\”)”, 0, 0, &zErrMsg);
sqlite3_exec(db1, "COMMIT", 0, 0, &zErrMsg);

I got that SQLITE_BUSY as connection 2 was writing the db at the same time.
I have called sqlite3_busy_timeout() but I find that it does not work if
INSERT runs after a SELECT within BEGIN and COMMIT.

Is it expected?

Yes. See http://sqlite.org/c3ref/busy_handler.html , the part about a deadlock. 
See also the discussion of BEGIN IMMEDIATE and BEGIN EXCLUSIVE here: 
http://sqlite.org/lang_transaction.html ; either will avoid deadlocks.
Igor Tandetnik

sqlite-users mailing list

Reply via email to