5

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.

4

2 回答 2

7

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

于 2013-01-23T00:26:23.080 回答
5

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

于 2013-01-23T09:49:53.577 回答