I am using SQLITE database in my iPhone app. I have a refresh button on my home screen and on click of that refresh button I usually fetch the data from my web service and store it into my database. In normal scenario it works fine but when I click my refresh b开发者_运维知识库utton 4-5 times frequently my app crashes and My app log Shows "Unable to open the database" I am not sure why I am getting this SQLLITE error. Is there any restriction on inserting number of rows in SQLITE database?
It sounds like your app was downloading data from the webservice, writing it to the database and then repeating those steps when you pressed the button frequently.
Depending on how your app is architected, you may be attempting to write to the database more than once from different threads - which is prohibited by the sqlite library.
Without seeing some code, there's no way to tell what is going on.
Ideally you should be setting up queues for writing to your database, and in Cocoa/Cocoa Touch this can be easily achieved by using NSOperation
and NSOperationQueue
. Using those classes you can encapsulate the behaviour of downloading data, parsing it into model objects and writing it to the database into different "operations" which can then be places on the queue. You can also set up dependencies so that one operation will not run if another is not yet finished. All of this is configurable.
Keep in mind though that using NSOperation enters the world of multithreading, and if you're updating the user interface at any point, you'll need to do it on the main thread since UIKit is not threadsafe.
精彩评论