> 
> On 19 Sep 2014, at 8:34am, Paul <de...@ukr.net> wrote:
> 
> > if database file is missing it must be created and initialized. 
> > For that purpose I need to provide a guarantee that *on_create* callback 
> > will be called strictly once. 
> 
> Can you check to see whether the database file exists using file operations, 
> not SQLite operations ?
> 
> SQLite doesn't usually cope with the problem the way you described. It's more 
> usual to use the form
> 
> CREATE myTable/myIndex IF NOT EXISTS ...
> 
> that way if the datbase file already exists and has the right structures in 
> it, nothing is changed.
> 
> Simon.

I can. I think I ough to. You know, I must also provide locking to avoid races.
So I was just wondering if this is a common problem among sqlite users
and if there are tools for that.

Note: I cannot wrap *on_create* in transaction because I want to allow user who 
specifies his  own *on_create* callback to be able to use transactions there.

So the only solution I see not is to use sqlite3_opev_v2() with out 
SQLITE_OPEN_CREATE.
When database is missing I create lock file *db_name*.lock, lock it for writing,
check if lock file is not unlinked, perform init, unlink lock file and unlock.

What I hate is the fact that in the middle between 'create lock file' and 
'unlink lock file'
application may crash and leave trash behind. The worst still, It may leave 
database file
in uninited state. Of course I can init temporary database first and then 
rename upon succes.
But this still leaves the possibility of temporary database to hang around as 
trash.

So my motivation was to check if community has some standard solutions.

Thanks.
 
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to