Re: SQLite Database 2 distinct database iphone.
Re: SQLite Database 2 distinct database iphone.
- Subject: Re: SQLite Database 2 distinct database iphone.
- From: Greg Reichow <email@hidden>
- Date: Mon, 07 Jun 2010 23:46:27 +0800
> Greetings.
>
> I'm building a iPhone application which is database driven.
> in that application i've designed it to have two databases.
> One database will be distributed with the application and is meant to be read only.
> the second database is meant to copy items to it for the user's safe keeping.
>
> the reason for this is that the application update will also include a refreshed database
> and as such if i only link to the records it might happen that the record that the user
> wished to keep would of been purged from the original database.
>
> evidently the structure is quite the same on both, with the exception of some additional fields
> in the user database.
>
> when the application starts it complains that it can not merge the two models.
> i've been looking on the net but found nothing of significance.
>
> is it possible to have two separate database in the same application on the iphone.
> and what are the steps to make it happen.
>
> do i have to duplicate the Core data initialization procedures and maintain 2 distinct managed object contexts?
I have a very similar application requirement. In my case, I am using 2 separate persistent stores. One is the user store located in their documents directory to maintain their unique copy of the database and edits to the provided data. The second is part of the application bundle. In this case, I use 2 separate MOC's and migrate data from the app persistent store to the user persistent store. Using the metadata that can be stored with the persistent stores, I check a version key I create and then if it is different, do a merge of the 2 stores. See the core data docs for a method for efficiently doing a large comparison and merge. This has worked quite well and allows for application database updates without messing up any unique changes the user has made to their own earlier copy.
Doing it this way also protects the user if the application is reloaded. The user data in the documents directory is backed up and can easily be restored.
As for model changes, if they are simple changes to the model between versions, you may be able to get away with lightweight migration. It is a simple option to add when loading the persistent store.
There very well may be a better approach but this has successfully worked for me.
Greg Reichow
MangoCode
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden