Android: SQLite Transaction Isolation Levels (ORMLite)

I am using ORMLite in my Android project. I know that Sqlite takes care of file level locking. Many threads can read, you can write. Locks prevent more than one letter. Can someone explain what will happen if one thread updates some record and another thread tries to read this record? Will the stream (which is trying to read) get stale data? Or will it be blocked until the first thread completes the write operation? As I know, there are 4 levels of transaction isolation: Serializable, Repeatable read, Read commit, Read uncommitted. And is there a way to change it in SQLite or ORMLite?

+5
source share
2 answers

SQLite has 5 different locking levels - http://www.sqlite.org/lockingv3.html : unlocked, shared, reserved, pending, exclusive. An important lock for this issue is Shared lock:

"SHARED - A database can be read but not written. Processes can hold SHARED locks at the same time, so there can be many simultaneous readers. But no other thread or process is allowed to write to the database file when one or more SHARED locks is active." .

Locks are the level of the table (therefore, doing something with one row in the database - the whole table is locked).

, , . : UNLOCKED → PENDING → SHARED → UNLOCKED ( ). , , -, - , .

- , , . autocommit /: UNLOCKED → PENDING → SHARED → RESERVED → PENDING → EXCLUSIVE → UNLOCKED. Exclusive, () . EXCLUSIVE. SQLite , PENDING . .

, - , , , . , . SQLite ACID, , , , .

- " SQLite", "".

+9

SQLite , .

http://www.sqlite.org/threadsafe.html

, Android SQLite Serialized . , , , :

http://www.sqlite.org/faq.html#q5

ORMLite hard , .

, , . , . . , .

, SQLite, Serialized, , , -uncommitted .

http://www.sqlite.org/sharedcache.html

ORMLite Dao.executeRaw(), :

dao.executeRaw("PRAGMA read_uncommitted = True;");

, , , , . .

, , , .

+3

All Articles