On 4 May 2015, at 4:09pm, Brandon <brandon at cogent3d.com> wrote:

> We are using SQLite in an iOS app. We are not using the 'built-in' SQLite, we 
> are compiling from source. We have been battling an issue where the database 
> becomes 'malformed'. This occurs when iOS completely crashes (blue screen, 
> flickering, then restart). It's a pretty hard core crash. As a result - the 
> db often becomes malformed. My question is - is there anything I can do to 
> help prevent this? I have enabled 'WAL' mode. At this point, we are at a 
> loss. I am just not sure what our next step is.

You've hit a problem with iOS.  iOS is a phone OS.  It's not designed to crash, 
because the rules about phones say that they must always be available for 
calling the emergency number, so they mustn't crash.  Given the no-crash rule 
for real-world performance and released Apps, it doesn't matter what happens if 
your App can crash the OS, because if it can crash the OS Apple will never 
approve it.

So a phone OS often does things that computer OS would never do, like 
aggressive caching which doesn't bother to update main storage until the App 
backgrounds or quits.  And this can lead to the type of corruption you're 
seeing.  And since SQLite is doing everything it can to write to storage 
correctly, your fix cannot be done inside something SQLite is doing.

So your 'treatment' for this problem is not to do with making SQLite more 
trustworthy.  It's to figure out how you're crashing iOS and stop doing it.  
You're going to have to do that sooner or later anyway, because your App will 
never get through Apple's approval process for App distribution if it crashes 
iOS.

If you think one of your SQLite calls is causing the crash we can help you.  Do 
you have any idea what you're calling and under what circumstances it's 
happening ?  If the thing crashing iOS is not to do with SQLite then you might 
be better off asking elsewhere.

Simon.

Reply via email to