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!
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With