On 7 Aug 2011, at 9:19pm, skywind mailing lists wrote: > A few user have reported that when the iPhone/iPad runs out of batteries the > SQLite3 database may become corrupted. I have received one database back and > it is indeed defect and unrecoverable. Does anybody have an idea what is > going wrong? I tried to reproduce the error by myself but I did not have any > luck so far. > For information: only the main thread is writing to the database. There is no > other thread having access to the database and there is also no read > operation from the main thread. The write operation is not within an explicit > transaction.
Don't worry about transactions, your key question is when you run sqlite3_close(). If your database is being corrupted by low-battery-shutoff then you are failing to correctly trap the 'application will quit' notification, because the iPhone sends this to all apps before it shuts down due to low batteries. (Following is for those less used to iOS development.) There are two common tactics for iPhone apps. One is to close database handles whenever the application is notified it will be switched to the background. The other is to close your database handles whenever your application gets notified that it will be terminated. There are notifications for both of these, and they're easy to react to. It's possible those users have found an obscure bug in some version of iOS where it's not notifying apps properly, but I think this is unlikely. I've not seen such problems reported elsewhere. Since you say only your main thread writes to the database your best tactic comes down to whether your app is one that has background functionality (like something that logs your GPS movements while you're doing other things) or one which only really has functionality when it's the front app. Simon. _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

