On 11 Jan 2016, at 7:06pm, Warren Young <wyml at etr-usa.com> wrote:

> On Jan 11, 2016, at 11:57 AM, Simon Slavin <slavins at bigfraud.org> wrote:
> 
>> Just do BEGIN IMMEDIATE immediately after you open the database.
> 
> Doesn?t that set up a race condition?  What prevents the other process from 
> opening the DB and running its own SQL if the OS?s scheduler happens to take 
> the CPU away from the legitimate process between sqlite3_open_v2() and 
> sqlite3_exec(?, ?BEGIN IMMEDIATE?, ?) ?

Okay, so your concern is that the other process intrudes between the _open() 
and the BEGIN.

If that's the case then I suggest that you create your new database (including 
schema and any initial data) with a different filename.  Then once this is 
complete, close it (as far as SQLite is concerned) then use your OS calls to 
rename the file to whatever your database is normally called.

My question is what the other process does.  Suppose your program opens the 
database and spots that there's no schema there (however you do it).  What does 
it do then ?  Is there only one process which can create the schema or should 
it close the file again and back off for a while ?

Simon.

Reply via email to