Search code examples
iosobjective-csqlitefmdb

Sqlite3 database in objective-c [need advice]


I am using FMDB lib to store messages (chat application). It's a objective-c wrapper for sqlite3. I have singleton where all queries implemented.

Just example:

NSString *query = [NSString stringWithFormat:@"UPDATE table_name SET some_col = some_value;"];

[database open];
[database executeUpdate:query];
[database close];

So, should I open database and close for every query, or open only once when my singleton initialized and close when application terminated?

Also, What's the best way to store data (messages)?


Solution

  • You should open and close for every query. It looks like a lot of work for the device but it will save you from tons of bug.