Quoth Philip Graham Willoughby <phil.willoug...@strawberrycat.com>, on 2011-03-22 10:18:08 +0000: > Yes, I had this problem - if sqlite3_open_v2 had an equivalent to > O_EXCL it would make this a lot easier: you would only try to run > your schema/prepopulating SQL if the exclusive open worked. If it > failed you would retry a non-exclusive open and then assume the > database was initialised. If such a flag is added it would be > helpful for it to implicitly get an exclusive lock on the database > it creates so that no-one else can try any queries before the schema > is there.
If you control the database schema, user_version is a convenient place to put such markers, albeit not a foolproof one; you can set it to a magic number after initializing the DB structure, then query it on open. The main failure mode is if someone hands you a completely unrelated database that already has schema elements in it that collide with yours. Querying page_count or doing « SELECT COUNT(*) FROM sqlite_master » may also allow you to determine whether you have just created a database, though it's also not foolproof since there's no interface guarantee linking the two. You probably want to do a BEGIN EXCLUSIVE before loading the schema in most cases. (The EXCLUSIVE may not strictly be necessary, but I find it makes things clearer.) ---> Drake Wilson _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users