sqliteconcurrencydatabase-concurrency

Does transaction assures dirty reads do not happen?


I've been reading a lot lately and I am now very confused how transactions and locking are working and how are related to each other.

When working with SQLite, imagine the following flow:

  1. begin SQLite transaction
  2. run a select statement on a SQLite connection to return values
  3. if condition is met on the returned values, go to step #4, otherwise go to step #5
  4. do the update
  5. commit SQLite transaction

If two threads run same code, is there a possibility that in one of the threads could get what is called a "dirty read" meaning, between the step #3 and step #4, the other thread could run the update (step #4)?


Solution

  • Yes, it's called isolation level: https://www.sqlite.org/isolation.html