One of the app I am building uses SQLite to store data that was downloaded from a server.
The app itself uses multi threading so as the app launches, the app downloads data in the background while it also presents the UI to the user.
The user at this point in time can begin navigating the app, tapping on table rows to drill into detail pages.
Sometimes when I tap on a table row, the app crashes at one of the many sqlite3_prepare_v2() function calls. It happened a lot more frequent when I allow more than 1 max concurrent operation for my NSOperationQueue. However, it has happened a lot less now that I have limited the max concurrent operation count to 1.
When my app launches, I am opening a database connection and I am keeping it open until the app needs to terminate, then I close the connection.
Here is a sample line it crashes at:
if(sqlite3_prepare_v2(objDatabase, [strGet cStringUsingEncoding:NSUTF8StringEncoding], -1, &stmtGet, NULL) == SQLITE_OK)
{
...
}
Error says EXEC_BAD_ACCESS
Like 1 out of 20 or 1 out of 30 app runs, it would crash. So that means my SQL statement works 99% of the time.
Anyone ever had this happen before?
I had this same problem. Go carefully over all the calls to sqlite3_prepare_v2 instructions and make sure that the matching sqlite3_finalize is called for each one of them. In my case, I had a location where sqlite3_finalize was not being called, causing the crash the next time sqlite3_prepare_v2 was called. It does not always crash, and it's hard to debug like crazy. I hope this comment might help you.
You might really find helpful to write stub functions for sqlite3_prepare_v2 and sqlite3_finalize which log these actions to NSLog. That will help verify the matching calls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With