On 21 Mar 2011, at 22:04, Erich93063 wrote:

> I am trying to create a SQLite database if it doesn't exist, which I
> know I can use 'CREATE TABLE IF NOT EXISTS", but more importantly, I
> need to initially populate the database with seed data if it doesn't
> exist. If I use CREATE TABLE IF NOT EXISTS, it will obviously create
> the table if it doesn't exist, but if I follow that up with insert
> statements, those would ALWAYS get ran. I only want to enter the seed
> data if the database does not exist. ???

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.

To answer your question: you can use a normal CREATE TABLE (without IF NOT 
EXISTS) and then only populate it if that worked - you will get an error 
because the table exists otherwise.

Best Regards,

Phil Willoughby
-- 
Managing Director, StrawberryCat Limited

StrawberryCat Limited is registered in England and Wales with Company No. 
7234809.

The registered office address of StrawberryCat Limited is:

107 Morgan Le Fay Drive
Eastleigh
SO53 4JH

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

Reply via email to