samedi 2 avril 2016

SQLite3 and releasing of locks

SQLite has different levels of locks: UNLOCKED, SHARED, RESERVED, PENDING, EXCLUSIVE.

I can't find information which calls to SQLite API acquire and release that locks.

As I understand lock acquired when sqlite3_step called. Type of lock depends on expression of prepared statement. Also this command can escalate lock in write operations inside a custom transaction.

As I understand write lock released also by sqlite3_step - this func returns SQLITE_DONE or the error code. I didn't find any docs but seems reasonable that this function should release RESERVED/PENDING/EXCLUSIVE at the end of execution.

But I do not understand what happens with read operations. To get all queried rows we need to call sqlite3_step several times - each call gives us one row.

I found SQLite docs about OS cache and citation from Unlock-notify API: it is not possible for one call to sqlite3_step() to return SQLITE_ROW and then the next SQLITE_LOCKED

I assume that in read operations first call to sqlite3_step acquires SHARED lock and loads data from the file to OS cache. Lock released if sqlite3_step returned anything except SQLITE_ROW (i.e. SQLITE_DONE or error code).

Is it right?

How we can manually release acquired lock for read operation? sqlite3_reset?

Aucun commentaire:

Enregistrer un commentaire