SQLite FMDB creating table - beginner iOS

pedros picture pedros · Nov 6, 2012 · Viewed 7.7k times · Source

I think this is a simple question but I didnt find the answer in the FMDB git page. When you use the command:

[database executeUpdate:@"create table T_table(name text primary key, age int)"];

does FMDB or SQLite make some kind of verification to see if the table already exists?

Can I call this method in my class initializer without creating more than one table?

Sorry if stupid question.

Answer

ccgus picture ccgus · Nov 6, 2012

Another solution is to change your query to:

create table if not exists test_table (test_no NUMBER, test_name TEXT);

or, you can check for the existence with:

select sql from SQLITE_MASTER where name = 'test_table'

And see if you get any results back.