Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

migration - Migrate normal sqlite3 database to core data?

I have a normal pre-populated database. I want to migrate it to core data for my app. What is the best way to achieve this. By the way I have done these things, copied the recipes.sqlite database from apple's sample.exported a table sql. Rename the column names according to the core data table columns(something like this - id "primary key" with Z_PK). filled that table with my values. But i am unable to understand the columns names Z_ENT and Z_OPT. Does some one knows how do i migrate my prepopulated sqlite3 database to core data easily.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do not try and manually create a Core Data SQLite file. That is a road to failure; every time.

If you have a pre-existing SQLite file then use straight SQLite tools to access it and import it into Core Data using Core Data. Once you have the data in a Core Data stack, save out that file and then use the resulting SQLite file.

The internal structure of the Core Data SQLite file is designed to be opaque and should not be reverse engineered. Apple makes no guarantee that the file structure will stay the same. They have changed it several times already since Core Data was released.

Import

To do the import, it would be just like any other file:

  1. You stand up the core data stack.
  2. You walk through each table and each row in the non-Core Data database.
  3. Create a new Core Data object for each row.
  4. Insert the data from the old row into the new object.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...