AppsDev
AppsDev

Reputation: 12499

Sqlite database modifications and app updates in iOS

I'm using a sqlite database in my iOS app. I have all its tables definitions in an .sqlite file I've placed in the "Supporting Files" group of the Xcode project, and in code I copy this file to "Documents" to be able to perform database operations. While developing, I've found that, when I need to add/remove a table or change its fields and I remove the .sqlite file from "Supporting Files" to add the new one, then I need to uninstall the app from the device or the simulator and build again to get the new database.

How could I make changes in database tables by replacing the .sqlite file without having to uninstall the app? When the app will be submitted to the App Store, will the users have to reinstall the app when a new update with changes in database is available?

EDIT. Is it possible to replace the database and to keep/copy the data the user had in the old one? Or will user loose all the stored data when downloading an app update from the Store where the .sqlite database is replaced, as if he were installing the app from scratch?

I've never submitted an app to the Store yet, I need some guidelines about how to handle app updates if I need to make changes in database tables when having such database in an .sqlite file. I'm not using Core Data.

Thanks

Upvotes: 3

Views: 2102

Answers (1)

Hindu
Hindu

Reputation: 2914

for it, you need to modify database by using programmatically. Means, if you want to create/add new table in database then you need to add code like Create Table.... In this case, you can't use predefine database in code.

But if you want to use database instead of writing code, then you need to rename your database and copy all old database data to new database programmatically.

Thanks

Upvotes: 2

Related Questions