SQLite DB corrupt while inserting the data in iOS application.
In our iOS application, we have provided the data Downloading feature from the API. Here we first delete the data from the local SQLite database and then insert the newly fetched data from the API into SQLite DB. It works fine for the 1st and 2nd time when we install the app on iOS. But after that, we get a "database file is corrupt" error every time we try to download the data.
Sometimes it shows the following error instead of the above one: "database disk image is malformed" error
Your question might be more appropriate in some iOS app developer forum, but anyway ...
we have provided the data Downloading feature from the API.
Do you close the database when your app loses focus?
Wouldn't it be easier to just remove the database from the filesystem and create a new instance for your data Downloading feature?
Does your application close all SQLite connections before it quits ? It could do this on quitting time or every time it's switched into the background.
How are you deleting existing data ? Are you using
DELETE FROM commands ? Or are you deleting and copying the closed database file ?
As a temporary measure for diagnostic purposes, pease have your application run the command
and look at the results each time it's about to delete existing data and insert newly fetched data. This should tell you with more precision when the database is getting corrupted.