Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a pre-existing sqlite file into Core Data?

I need to import a .sqlite file into Core Data, I searched on the internet and found:

Core Data Tutorial: How To Preload/Import Existing Data

It is creating a Python script to populate this database by reading in the contents of our old database, and creating the appropriate rows in the new database. But my sqlite database is too large in term of number of tables and columns, this may cost me a considerable amount of time.

I also found this:

Using a Pre-Populated SQLite Database with Core Data on iPhone OS 3.0

But I don't quite understand it, it looks like it's copying old database to a new one, then how does it add Z_ suffix to all the table and column names? Also, it asks me to create entities and attributes, is there anyway this can be done automatically(from sqlite dabase file)?

Thanks!

like image 298
hzxu Avatar asked Jul 05 '11 00:07

hzxu


People also ask

How do I connect to an existing SQLite database?

Use the connect() method To establish a connection to SQLite, you need to pass the database name you want to connect. If you specify the database file name that already presents on the disk, it will connect to it. But if your specified SQLite database file doesn't exist, SQLite creates a new database for you.

What is difference between SQLite and Core Data?

The short answer is simple. Core Data is a framework for managing an object graph. SQLite is a relational database. Continue reading if you are interested in the long answer.


1 Answers

This answers here might be useful (mine is one of them)

Pre-populate Core Data

 /**
 Returns the path to the application's Documents directory.
*/
      - (NSString *)applicationDocumentsDirectory {
          return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES) lastObject];
      }

sample code

like image 182
Oscar Gomez Avatar answered Sep 20 '22 20:09

Oscar Gomez