I am learning Core Data for iPhone application. I defined .xcdatamodel. But I have the following questions:
Is it possible to make .sqlite file
from the .xcdatamodel file ?
If not, what is the correct
procedure to prepare .sqlite ?
If it is necessary to use external
tool, is there any FREE tool to make
.sqlite ?
Thanks.
Your questions 1 & 2 have already been answered but here's a comprehensive overview for Q3:
http://www.barefeetware.com/sqlite/compare/?ch
I personally use a (free) Firefox add-on called SQLite Manager - you can download it from here https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/
Is it possible to make .sqlite file
from the .xcdatamodel file ?
Well, when you create a Core Data stack and set your store to an SQLite store, the persistent store coordinator will create a .sqlite file configured for the model attached to the store.
If not, what is the correct procedure
to prepare .sqlite ?
Before iOS 3.0, you couldn't use Core Data so there were several libraries out there for using SQLite. However, I don't think any of them have been updated because there is not much point when using Core Data.
If it is necessary to use external
tool, is there any FREE tool to make
.sqlite ?
SQLite comes standard as part of MacOS X so you can use the command line or scripting languages like Ruby, Python, Perl (also standard) to create any SQLite database you want.
But honestly, I wouldn't bother. Unless your app's data is very simple and largely static, you will end up reinventing the wheel and effectively reproducing most of Core Data just to interface SQLite with the rest of the app.
Core Data's SQLite structure really isn't designed to be handled by anything other than Core Data. Even if you have your persistent store use the SQLite data format, if you open it in a generic SQLite tool you're going to get a cryptic mash of nothing-you-can-reliably-mess-with.
I'm guessing your goal is to have pre-populated data in your database? The right way to do that is to write some “importer” code that reads in whatever existing data you have and creates objects in the persistent store corresponding to those. Keep a copy of that persistent store—maybe in your app bundle, to be copied out to a temporary directory for writing—and you've got yourself a starting data set.
Related
I am developing iPhone app for a web application currently running online. Current web application is big and complex and uses SQL to store vital information like member details, login credentials etx. Other stuffs like info about several sections, groups, sub groups and other information related to each are saved in txt. Current system uses its own standard to keep data in files and also made custom algorithm to read and write data in it. Each txt file is below 1 mb size. There are lot of data manipulations going on.
Custom algorithm created just read those files and put all data in cache as records (same as in core data managedobjectcontext) and whenever there is a change in data the whole file is overwritten.
So while implementing the same what I want to choose for iPhone app? In apple website they said that 'SQLite is perfect for low-level relational database work' https://developer.apple.com/technologies/ios/data-management.html But in my case it is high level.
So please help me to make a decision. Do I want to manage data in files or sqlite database using core data?
I would also like to know whether it is possible to import those classes and algorithms currently in webserver to iOS, so I don't want to rewrite the same algorithm for iOS? Current server codes are in C#
In the rare case that you need to do low-level relational database work use SQLite. In the 99% other cases use Core Data. Don't ever store relational stuff into txt files. It'll just be a pain.
Your use case sounds like a good match for Core Data.
Often misunderstood, Core Data is an object store that happens to use sqlite for persistence. You don't manipulate the sqlite underneath it, Core Data manage the sqlite for you. You do not write SQL. The closest match to it in .NET is EDM and the Entity Framework in ADO.NET.
Assuming the classes and algorithm you want to import in the webserver is in C#, sadly those needed to be ported to Obj-C.
i have a .sqlite file with all the data i want to be used with my iPhone app .
but i feel i should be using Core data for what i want done.
is it possible to some how move all the data that is held within my .sqlite file to core data's .sqlite file ?
i have created only 2 fields in my .sqlite file and 2 attributes in the core data file, but i don't think i can replace the coreData's sqlite file as core data added additional fields to it.
what is the best way to handle this .
thanks
Since you generated the database yourself, the best way to move the data into a Core Data store is to use Core Data itself to re-generate the data. You can do this either through a throw-away app or within your app itself.
The fact that Core Data on the iPhone uses SQLite as a backing store is an implementation detail. Trying to recreate the core data store yourself may to cause very obscure bugs, you'll be much safer by allowing Core Data to generate the database.
#ExtremeCoder's answer is an option, but even writing an app to read from SQLite and store into Core Data would be a better choice than what that blog suggests.
Check this out: http://ablogontech.wordpress.com/2009/07/13/using-a-pre-populated-sqlite-database-with-core-data-on-iphone-os-3-0/
I have a simple table that I'm pulling from our existing sql database. Its just a 1mb Vehicle table. It contains enough information that I don't want to create it from scratch, but I can not find a definitive answer on how to import this table into my sqlite environment on the mac.
I've seen a few posts about python scripts that import to Core Data but I don't think thats the way to go.
The table I saved out as .rpt file. Any direction other than the one I'm traveling would be great.
The most correct (and pretty easy) way to do this is to write a little Mac OS X command line tool program that reads the data from your SQLite database and uses Core Data to load the data into a Core Data persistent store.
That persistent store -- the resulting Core Data schema'd SQLite file -- can be added as a resource to your iOS app project and it'll "just work".
Checkout Christian Kienle's Core Data Editor, which let's you import data from CSV files into Core Data: http://christian-kienle.de/CoreDataEditor
It is also useful after the data is imported for debugging.
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?
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.
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.
These might help: http://www.sqlite.org/cvstrac/wiki?p=ManagementTools
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.
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.
I am fairly new to core data technology and i searched a lot on how to add the database to a core data application.so can anybody guide me on how to integrate the database layer? i have seen the iphone tutorial on core data (i.e books example) but i am not able to understand how to .sqlite file has been included in that application
The SQLLite file is automatically generated at startup by core data, by the persistent store manager.
If you have a project generated to start with Core Data, look in the App Delegate at the persistentStoreCoordinator method - that's where it manages the file created and sets the path where it will exist. If there's an existing one it will make use of it, though you'd have to copy over a pre-loaded one into the writable path it sets up for the database.
Core Data is NOT a database, it is a persistent object store. You have no control over how the data is stored in the file. (So trying to get it to use your own designed database is a bad idea.) You only get to chose wether it uses XML, binary or sqlite as its backstore.
To see how your app gets the data from the file, look in the app delegate. (That is where most sample code put it.) You'll find some methods for the managed object context, and the persistent store coordinator. The latter will create the file if needed. Besides the save call during quit, or other relevant times, you don't have to do much with it. (You can do some stuff, but I can't recommend that when you're new to Core Data.)