 |
 |
Importing CSV -> CoreDate
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Aug 2001
Location: Germany
Status:
Offline
|
|
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
|
|
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
|
|
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)filterArtikel  id)sender{
NSPredicate * predicate;
predicate = [NSPredicate predicateWithFormat:@"group like %@", @"100"];
[artikel setFetchPredicate  redicate];
}
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
|
|
have you tried:
yourInt = [yourString intValue];
yourFloat = [yourString floatValue];
yourDouble = [yourString doubleValue];
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2002
Status:
Offline
|
|
That's it exactly. Use NSStrings various conversion methods to convert the string data to the appropriate type.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|