Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FMDB: is It good remaininig open database during the whole life cycle of ios app?

Tags:

ios

fmdb

I am confused about database open and close operation for FMDB wrapper class.

Is it creating issue if i open database in applicationDidFinishLoading method of AppDelegate class and do not close until application will terminate ?

Thanks.

like image 778
Nikh1414 Avatar asked Jan 22 '13 10:01

Nikh1414


2 Answers

There's no reason to close it unless you change the schema. So keep it open.

like image 154
ccgus Avatar answered Sep 29 '22 07:09

ccgus


From the Official FMDB documentation:

Opening

Before you can interact with the database, it must be opened. Opening fails if there are insufficient resources or permissions to open and/or create the database.

if (![db open]) {
[db release];
return;
}

Closing

When you have finished executing queries and updates on the database, you should close the FMDatabase connection so that SQLite will relinquish any resources it has acquired during the course of its operation.

[db close];

So, every time your query the Database, you should have a pair of open and close calls on your database.

In short, open a DB connection when you require things from database and close it when you are done using the database.

Link to documentation : https://github.com/ccgus/fmdb

like image 36
Ravi Raman Avatar answered Sep 29 '22 09:09

Ravi Raman