Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-20-2011, 12:02 PM   #1 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 69
Marco is an unknown quantity at this point
Default iOS Core Data Export Import

Can anyone suggest a way to Export records from an iOS Core Data database (is there a .dump command in Core Data whithout the create table statements?) then have the ability to import the export file back into the existing iOS Core Data database.

Thank you
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 08-20-2011, 01:13 PM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

for export in xml, read this snippet
Exporting from Core Data on iOS. : Scott Means

for import, parse it with NSXMLParser and add to core data normally.
__________________
dany_dev is offline   Reply With Quote
Old 08-20-2011, 07:06 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 25
rcirka is on a distinguished road
Default

The core data back-end database is just a sqlite file. Once you find the location of the file you can do anything you want with it. I am fond of firefox sqlite manager. You can also just do a command line dump: sqlite x.db .dump > output.sql

To find the location of the file, add the following to your command arguments:
-com.apple.CoreData.SQLDebug 1

When you load it in the simulator, look in the console and it should show something like this:
CoreData: annotation: Connecting to sqlite database file at "/Users/rcirka/Library/Application Support/iPhone Simulator/4.3.2/Applications/7DC5DD03-18DF-48FC-B532-F825C97CF464/Library/Caches/MYEQ.sqlite"
__________________
www.RonaldCirka.com
Equinox |TeamLiquid
Available for freelancing opportunities
rcirka is offline   Reply With Quote
Old 08-20-2011, 09:20 PM   #4 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 69
Marco is an unknown quantity at this point
Default

Thanks for the replies.

This Export and Import will be done by users in the iOS app. I was hoping to find a way from the iOS app to call a Core Data command to do a .dump (or something similar to it) what would export certain records (master/detail) into an sql file. Then if the user needs to restore that data, from the iOS app Core Data I would call that file that would import those records back into the existing database.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 08-21-2011, 03:13 AM   #5 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

I don't know where you want that the user put its file, however rcirka said you to obtain the sqlite database.....and seem to be what you are looking for
__________________
dany_dev is offline   Reply With Quote
Old 08-21-2011, 09:06 AM   #6 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 69
Marco is an unknown quantity at this point
Default

When they are running the iOS App I will save this export file to the App documents folder located in either the iPhone or iPad.

This will be a way for the user to backup certain filtered records. Then, if something goes wrong they can reimport this exported file back into the App.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 08-21-2011, 02:16 PM   #7 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 25
rcirka is on a distinguished road
Default

If you want to back up the whole database file, you can just copy it through the file system.

Code:
 [[NSFileManager defaultManager] copyItemAtPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"db.sqlite"] toPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"db_backup.sqlite"] error:nil];
If you want to just backup certain pieces of information, you may to create a new core data store and copy the info there.
__________________
www.RonaldCirka.com
Equinox |TeamLiquid
Available for freelancing opportunities
rcirka is offline   Reply With Quote
Old 08-21-2011, 04:38 PM   #8 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 69
Marco is an unknown quantity at this point
Default

rcirka, currently that is what I am doing with the app, copying the entire sqlite db. New requirements have changed this, because I need to just export portion of the data. But I like your suggestion to create a new sqlite db that just contains the portion of data that I need to export.

By doing it that way, the only worries I would have is when importing the data back in, the id's will change and the children id's will need to change also.

Thank you all for your suggestions.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org

Last edited by Marco; 08-21-2011 at 04:39 PM. Reason: Children worry.
Marco is offline   Reply With Quote
Old 08-21-2011, 05:47 PM   #9 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

seem that you should do as said here
iphone - How to force coredata to rebuild sqlite database model? - Stack Overflow
http://ablogontech.wordpress.com/200...iphone-os-3-0/
__________________
dany_dev is offline   Reply With Quote
Old 08-21-2011, 07:20 PM   #10 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 69
Marco is an unknown quantity at this point
Default

Thanks I am checking them out.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Reply

Bookmarks

Tags
core data, export, import, ios

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 396
13 members and 383 guests
7twenty7, chiataytuday, cristofercolmbos, dedeys78, fiftysixty, gmarro, iOS.Lover, jonathandeknudt, raymng, stanny, tymex, UMAD, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:12 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0