Why not create it under a random name, and then rename after creation?

Noah Hart
 

-----Original Message-----
From: Ron Stevens [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 13, 2007 10:59 AM
To: sqlite-users@sqlite.org
Subject: Re: [sqlite] Atomically creating a database and bootstrapping
its tables

> No, you have to do that in your application.
>
> In pseudo code your create function could do this:
>
>     open the database file
>     begin an exclusive transaction (since you may need to write to 
> initialize the tables)
>     read the user_version
>     if the user version is not zero
>        create the tables (read SQL script into a string and pass the 
> string to sqlite3_exec)
>        set the user version to a non zero value
>     endif
>     commit the transaction
>
> Only one process will succeed in getting the write lock while opening 
> the transaction. That process will create the tables and set the 
> user_version so no other process will try to reinitialize the tables
latter.

That solves the problem of two processes bootstrapping the database, but
is it possible for the second process to open the database while the
first is in the process of creating it (creating the header pages, the
system tables, etc) and view the database as corrupt since it isn't
fully created yet? I imagine there is at least a small window between
when the file is first created and when the file lock is acquired on it,
but I'm wondering how big that window is (or does it not exist?).

------------------------------------------------------------------------
-----
To unsubscribe, send email to [EMAIL PROTECTED]
------------------------------------------------------------------------
-----




CONFIDENTIALITY NOTICE: 
This message may contain confidential and/or privileged information. If you are 
not the addressee or authorized to receive this for the addressee, you must not 
use, copy, disclose, or take any action based on this message or any 
information herein. If you have received this message in error, please advise 
the sender immediately by reply e-mail and delete this message. Thank you for 
your cooperation.




-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to