I am developing an application for IPhone and using sqlite to connect to db. I am trying to use the singleton pattern for connecting to the db and retrieving the data.
I would like to know which is the best way to maintain the connection, should I keep the connection open till the application is closed or should I open and close the connection for every call that I make ?
SQLite must re-parse the database schema each time a new connection is made. This can be time consuming. Leaving the connection open also provides opportunities for SQLite to cache data. Since you get ACID transactions even without closing the connection, there is little reason to close it. So, keep the SQLite connection open until the application is closed.