When to close SQLite database (using FMDB)
Asked Answered
I

1

6

When should you close the connection to an SQLite database (using [db close] in FMDB)?

Right now I am closing it after running every batch of related queries, but should I rather close when my app closes? What are the pros/cons of doing either way?

Thanks

Inflatable answered 30/3, 2013 at 15:35 Comment(2)
#6061536 refer to this questionHummingbird
Okay, thanks, didn't see that. But those 2 answers have no votes/comments and don't really answer my question (what are the pros/cons)Inflatable
F
36

I'm the guy who wrote FMDB.

Keep it open unless you change your schema. That's the only reason to close it, and constantly re-opening it is a little hit on performance / battery life.

Fishwife answered 30/3, 2013 at 20:9 Comment(3)
@Fishwife Thanks.. FMDB is really good. but may time app is crash due to this. Error : "database is currently in use". On each operation first i open db. than some place i close it also.. so is it good idea to close each time ? its good to close when app is gone in backgroud mode ? Please give me suggestion... Its really appricited..Hauck
@Fishwife Should we close the database when the app goes into the background?Heretic
I don't do much iOS programming- so take my answer with a grain of salt. But no, I don't think you need to close it. If the fd is still around in SQLite, then it should all be good. I guess try it, and let us know what you find out :)Fishwife

© 2022 - 2024 — McMap. All rights reserved.