Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain data in an SQLite Database on an iPhone at a version update of the application?

I have an SQLite database in the first version of my iPhone application (which is on the app store). Now I want to roll out the second version of the application, which also has an SQLite db in it.

I understood that upon update, the SQLite database is removed and then the new one is added. I don't want this to happen, since that database holds some information that the user has saved. It wouldn't be good if it is deleted upon update.

Question is, how do I transfer the data from the old SQLite (old version) database into the new one? And how can I test the version update process that would happen on the App Store?

Any help would be greatly appreciated. Thanks.

like image 678
Alex Avatar asked Aug 30 '10 09:08

Alex


People also ask

How do you access SQLite using iOS mobile application?

Step 1 − Open Xcode -→ Single View Application -→ Let's name is DBSqlite. Step 2 − Let's develop our UI, Open Main. storyboard and add one text field and two buttons as shown below. Step 3 − Create @IBAction for both the buttons and @IBOutlet for text field and name them btnInsert, btnShowData and name respectively.

How SQLite manage data in iOS apps?

Step 1 − Create a simple View based application. Step 2 − Select your project file, then select targets and then add libsqlite3. dylib library in choose frameworks. Step 3 − Create a new file by selecting File→ New → File...

Does SQLite work on iPhone?

SQLite Mobile allow you to access your SQLite databases. You can manage your data with a very clean and simple iOS user interface. PRO FEATURES (with in-app purchase): Table creation menu.

What version of SQLite does iOS use?

The iPhone uses SQLite for most (all?) of its database storage. To find the version, type sqlite3 -version in a terminal app such as MobileTerminal or NewTerm or via SSH.


1 Answers

The answer is: implement versioning in your app from the very start :-)

In this case, you can consider an app with no version information to be version 1. What I would do is store the version of the database somewhere (probably inside the database itself). When the database is opened, check its version against what version the app expects, then make any schema changes as needed and update the stored version number.

If you haven't copied the database to the app's Documents directory, then this is all moot because it would be read only anyway. Otherwise, the contents of the Documents directory are preserved between updates.

To test the update, just start with a fresh copy of the previous version on your device. Then install the new one (build and run will do just fine). You do keep old versions of your app, right?

like image 128
Brian Avatar answered Sep 22 '22 21:09

Brian