Hi sqlite folk!

I had a (hard to reproduce) problem with SQLITE_LOCKED errors and I
was hoping someone could help me identify the issue (I'm using sqlite3
version 3.5.7 in a C++ program running in linux).

First, no other process is using the database, and my process has only
one database connection. All accesses are serialized through a big
lock in my program.

All my SQL statments are executed by a function that looks like this:

sqlite3_exec(_db, "BEGIN IMMEDIATE", NULL, NULL, &errMsg);
followed by either
        sqlite3_exec(_db, code, NULL, NULL, &errMsg);
or (if code is or ends in a select):
        sqlite3_get_table(_db, code, rawResult, &nRow, &nCol, &errMsg)
and finally:
sqlite3_exec(_db, "COMMIT", NULL, NULL, &errMsg);
(and if get_table was used, copy the values and free_table).

As far as I understand the documentation, I should NEVER get
SQLITE_LOCKED when using sqlite3 this way (serialized calls to the
above function), correct?

I got the error when running statements such as the following, each
separately (i.e. four calls to the function above):

call 1: INSERT OR ROLLBACK INTO TableX (a, b) VALUES (5, 'y');

call 2: UPDATE OR ROLLBACK TableY SET c = LAST_INSERT_ROWID() WHERE d == 'x';

call 3: SELECT * FROM TableY WHERE d == 'x';

call 4: UPDATE OR ROLLBACK TableX SET u = 'mm' , v = 'kk' WHERE key == 13;

The last command fails with SQLITE3_LOCKED (I'm not sure which of the
three sqlite3_ calls returns that though). Further accesses to the
database work correctly.

Sorry for the long email. Hopefully someone can shed some light as to
what might be happening (or what I might be doing wrong).

Thank you very much!

Best,
Radu
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to