views:

346

answers:

5

I've seen tutorials in books and on websites that offer .sqlite files for download. The sqlite files are used for Core Data.

How do I get a .sqlite file FROM an app or core data store on TO my desktop?

A: 

These might help: http://www.sqlite.org/cvstrac/wiki?p=ManagementTools

iWasRobbed
A: 

I like to use this Firefox plugin: https://addons.mozilla.org/en-US/firefox/addon/5817/

You can create a new .sqlite file, change existing databases, and browse through your data.

nimblegorilla
A: 

There's a command line program download-able from sqlite.org (in the standard download) that can be used to create a blank database with a schema. Usually the database file is compatible across operating systems and devices.

Jay
+4  A: 

If you are going to create a pre-populated sqlite file to be used with Core Data then you must create it with Core Data. It is trivial to create a basic desktop application for data entry and use that to create the file and then embed it in your iOS device.

Do not attempt to duplicate the data structure or linkage within the file by hand. You might get it to work but you will spend way more time trying to get it to work and it is going to eventually fail. The internal structure of a Core Data sqlite file should be considered like a private API. The structure is not public and can change without notice.

Marcus S. Zarra
Please explain.
Moshe
He means that the sqlite files you are downloading were themselves created by Core Data. To create your own, you set up your Core Data stack and then import data to it. While in theory, you could create a sqlite file that Core Data could use from scratch using only SQL commands, in reality it's a difficult and fragile way to get the datafile. The Core Data SQL API is private and changeable. It is virtually impossible to duplicate. It's always easier and cleaner to generate the file with the Core Data you would use to read the file.
TechZen
So I generate Core Data models and classes in XCode and then somehow export a sqlite file from that? How so?
Moshe
Create a trivial desktop app for data entry or a command line app that you can import the data into. Depends on where the data is coming from to determine the best route.
Marcus S. Zarra
A: 

If you are specifically trying to create a Core Data store, you use this method:

NSPersistentStoreCoordinator 
    addPersistentStoreWithType:(NSString*)storeType 
    configuration:(NSString*)configuration
    URL:(NSString*)storeURL 
    options:(NSDictionary*)options
    error:(NSError**)error

You must have already associated a NSManagedObjectModel with your persistent store coordinator object. If the store at storeURL does not exist, it will be created; otherwise it will be opened.

Seamus Campbell