SQLite DB corrupt while inserting the data in iOS application.
(1) By Ritesh Singh (Ritesh) on 2021-06-03 12:37:28 [link] [source]
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
(2) By Kees Nuyt (knu) on 2021-06-03 15:31:32 in reply to 1 [link] [source]
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?
(3) By Simon Slavin (slavin) on 2021-06-03 16:06:44 in reply to 1 [source]
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.