7

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?

1
  • 1
    If you're asking for a method to create CoreData SQLite stores, be wary of answers suggesting SQLite tools. You'll need to write or adapt a CoreData app to import data from another format (eg. flat file, CSV, etc.), probably using NSScanner. Commented Jul 27, 2010 at 22:10

5 Answers 5

14

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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.
So I generate Core Data models and classes in XCode and then somehow export a sqlite file from that? How so?
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.
I would like to direct future readers to a pretty good answer to the same question: stackoverflow.com/questions/7057622/… In order to get it to your desktop, run it in Simulator and find the *.sqlite in the app Package Contents.
Data entry in the simulator is more painful than writing a trivial OS X application to create the data. While it is useful to know how to retrieve the sqlite file I would not recommend that as a good way to generate a pre-populated database.
4

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.

Comments

1

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

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.