In my current app I have nearly 10 scenarios of inserting, updating , deleting and selecting the data into and from the sqlite3 database. Now for every query Iam opening the database and closing the database this makes my app very slow.
I have tried other way like opened the database at the launch of app (applicationDidBecomeActive:)
and closed the database when app terminates(applicationWillResignActive/ applicationWillTerminate:)
only once.
This is working only when we install the app first time.Once i deleted the current build and relaunching the app is not working. The error is Database is locked. Please help me. which way is the better one.
4 Answers
Instead of opening your database every time
What you can do
1) Initialize an instance of NSMutableArray in your AppDelegate Class and set its property strong and nonatomic.
for example @property(strong,nonatomic)NSMutableArray *temp;
2) Take a backup of your database in temp i.e NSMutableArray object
3) Perform an operation inserting, updating , deleting and selecting the data into temp i.e. NSMutableArray object
4) In background, perform same operation in your database. So, this will block your UI section.
Through this process, you are performing all your operation in an array not directly to your database. This will help not to open your database every time and will make your application little bit faster.
Are you sure your database was closed correctly ?
If it was not closed correctly, your database can become corrupted. The file should not be locked by the OS anymore past the end of the application (if this application is not configured to run in background of course).
When you close your database, are you sure that all statements are finished and finalized ?