Re: [sqlite] Create table if not exists and insert seed data

2011-03-22 Thread BareFeetWare
On 22/03/2011, at 9:04 AM, 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

Re: [sqlite] Create table if not exists and insert seed data

2011-03-22 Thread A Gilmore
On 11-03-22 10:40 AM, Simon Slavin wrote: > > Or just do a 'SELECT id FROM whatever LIMIT 1'. If you get any error, it > doesn't exist, so create it and fill it. > > Or look in sqlite_master for an entry for the TABLE. > > Simon. Could also use INSERT OR IGNORE statements for the seed data if

Re: [sqlite] Create table if not exists and insert seed data

2011-03-22 Thread Simon Slavin
On 22 Mar 2011, at 1:38pm, Pavel Ivanov wrote: > You can use a simple CREATE TABLE (without IF NOT EXISTS clause). If > it succeeds then you populate table with data (remember to do that in > the same transaction where you created the table). If CREATE TABLE > fails then you don't insert your

Re: [sqlite] Create table if not exists and insert seed data

2011-03-22 Thread Drake Wilson
Quoth Philip Graham Willoughby , on 2011-03-22 10:18:08 +: > 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.

Re: [sqlite] Create table if not exists and insert seed data

2011-03-22 Thread Pavel Ivanov
You can use a simple CREATE TABLE (without IF NOT EXISTS clause). If it succeeds then you populate table with data (remember to do that in the same transaction where you created the table). If CREATE TABLE fails then you don't insert your data. Pavel On Mon, Mar 21, 2011 at 6:04 PM, Erich93063

Re: [sqlite] Create table if not exists and insert seed data

2011-03-22 Thread Max Vlasov
On Tue, Mar 22, 2011 at 1:04 AM, 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.

Re: [sqlite] Create table if not exists and insert seed data

2011-03-22 Thread Philip Graham Willoughby
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

[sqlite] Create table if not exists and insert seed data

2011-03-22 Thread Erich93063
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