There is also a PRAGMA user_version (see http://www.sqlite.org/pragma.html#pragma_schema_version) which will let you store a number in the database header so you can keep track of what version of the "user schema" you have implemented in the database. Initially, when the database is created empty, the value is zero.
pragma user_version; returns a single row with a single value which is the version, and the command, pragma user_version=n; lets you change it to n. Perhaps you can use this as a flag to tell yourself that you are working with an uninitialized database (value is 0), that another process is updating the database schema (change it to -1), or that it is at some internal revision number known to your program (it has a value > 0) such that you do not need to change the schema or initialize it. >> 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 _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users