Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Importing CSV -> CoreDate

Importing CSV -> CoreDate
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 4, 2005, 09:19 AM
 
Hi,

I justed started using CoreData and think it's quite useful.

I've used to code in Delphi, Visual Basic and a littlebit in Java but now I started learning Objective-C.

Now I stick with the following problem.

I've a Database at my office and I want to export the interesting tables and use them (with their relationships) on the road.

I've done an export and created a csv-file for every table. Then I've imported these files in my App.
Importing the entities ist quite fast but,
first question: how do I convert my csv String to float or int values?
second question: Is there a ability to rebuild relationships similar to primary Keys in SQL?
I've tried to rebuild my relationships by searching in one Entity and adding this Entity in the other one but that's extremly slow!!

How do you solve these problems?

Thanks in Advance

Mark
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jul 4, 2005, 10:39 PM
 
First answer: see documentation for the NSScanner class, and you might also like to look at: -[NSString componentsSparatedByString:@","]

Second answer: CoreData looks after all the relationships itself, without you having to worry about keys. If you need to rebuild relationships that ARE based on keys from the files, you can do this by checking the keys fields, and then assigning the correct relationships manually using the usual coreData -[object setValue:ForKey:] method for to-one relationships or -[[object mutableSetValueForKey:] addObject:] for to-many relationships.
I assume this is what you've already done, and are saying it's very slow. I don't know of any other way, though.
     
Fresh-Faced Recruit
Join Date: Aug 2001
Location: Germany
Status: Offline
Reply With Quote
Jul 5, 2005, 01:34 AM
 
Originally Posted by Brass
First answer: see documentation for the NSScanner class, and you might also like to look at: -[NSString componentsSparatedByString:@","]

Second answer: CoreData looks after all the relationships itself, without you having to worry about keys. If you need to rebuild relationships that ARE based on keys from the files, you can do this by checking the keys fields, and then assigning the correct relationships manually using the usual coreData -[object setValue:ForKey:] method for to-one relationships or -[[object mutableSetValueForKey:] addObject:] for to-many relationships.
I assume this is what you've already done, and are saying it's very slow. I don't know of any other way, though.

I've imported the csv by componentsSeparatedByString and importing of String-Attributes are fine but I just don't know how to convert them to float or int value. I know it's a simple question but I just haven't found an answer.

Second answer: It's just as you wrote, the setValue:ForKey is extremely slow while importing thousends of records. I've just tried another way:

I import the Keys from my SQL Database, work without Relationships and do the linking by the following sample code:

- (IBAction)filterArtikelid)sender{
NSPredicate * predicate;
predicate = [NSPredicate predicateWithFormat:@"group like %@", @"100"];
[artikel setFetchPredicateredicate];
}

For example I create a TableView with all Artikelgroups and then I creae an action which filters all Artikel with the group I've selected.

It's quite not the best way or the way coredata comments it but it works and I only want to read my data not change them. Like that I can live with this solution.


Makr
     
Fresh-Faced Recruit
Join Date: Feb 2001
Location: Cape Canaveral, FL
Status: Offline
Reply With Quote
Jul 5, 2005, 08:40 PM
 
have you tried:

yourInt = [yourString intValue];
yourFloat = [yourString floatValue];
yourDouble = [yourString doubleValue];
     
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Jul 5, 2005, 11:12 PM
 
That's it exactly. Use NSStrings various conversion methods to convert the string data to the appropriate type.
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 09:19 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2