> If I have 2 separate processes, 1 of which will attempt to Read and Write a
> Database (Process A)
> and the 2nd which will only Read the database (Process B), then if Process A
> is in the middle of a Write when Process B tries to read what will happen?

If Process A is in the middle of writing transaction but has not
actually written anything to disk yet (all changes are in cache) then
Process B will proceed reading unlocked. If Process A is in the middle
of committing transaction or it has written some changes to disk
(there're so many changes that they don't fit into cache) then API in
Process B will return SQLITE_BUSY error. But only unless you've called
sqlite3_busy_timeout() with non-zero value. In the latter case Process
B will return SQLITE_BUSY only after mentioned timeout has gone and
Process A does not finish transaction yet. And when SQLITE_BUSY is
returned then indeed it's up to you to try again later.

> And Vice versa, What happens if Process B is reading while A tries to write?

Process A will continue unblocked until it will have to actually write
to disk. At this point it will wait for Process B to finish its
reading and after that it will actually write everything it needs.


Pavel

On Fri, Aug 7, 2009 at 11:50 AM, JimmyKryptonite<[email protected]> wrote:
>
> I'm looking to start a project using SQLite to handle some database
> transactions.  I have question about how SQLite handles Concurrency.  I read
> up on SQLite.org about the file locking and concurrency but I didn't really
> get the info I wanted (at least I didn't walk away with an answer in the
> terms I wanted it).
>
> My question is the following:
>
> If I have 2 separate processes, 1 of which will attempt to Read and Write a
> Database (Process A)
> and the 2nd which will only Read the database (Process B), then if Process A
> is in the middle of a Write when Process B tries to read what will happen?
> Will the Read request be blocked and Process B will wait or will SQLite
> return some kind of Busy Error Code to process B and it is up to Process B
> to try again later?
>
> And Vice versa, What happens if Process B is reading while A tries to write?
> Same answer as above?
>
> I'm very much a newbie to SQLite so patience is requested.
>
> Thanks in advance
> --
> View this message in context: 
> http://www.nabble.com/Concurrency-Question-tp24867278p24867278.html
> Sent from the SQLite mailing list archive at Nabble.com.
>
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to