Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
In my iOS application, I am parsing an XML from a SOAP based webservice and I am storing it into the SQLITE database. The problem that I am facing it is that, it is very slow. It takes about 18 seconds for about 310 rows of data.
if (saveObj == FALSE) { NSLog (@\"Error: %@\", error); } } else if ([elementName isEqualToString:@\"batteryID\"] && [mainElement isEqualToString:@\"return\"]) { objLabPanel.labPanelBatteryId = elementValue; } // getting other values from the xml . . . }
Hence for every return tag I encounter, I do a save to the database and so for my 310 or so records, I would be saving it 310 times. So by doing a [managedObjectContext save:&error]; , I guess that it opens the database, saves the data and closes the database and hence it takes a lot of time. Am I right in thinking this way?
Is there a way I can save all the objLabPanel's to an array and then do a bulk insert to the database i.e. bulk insert the entire array of objLabPanel's into the SQLITE database at once?
It would be great if someone could help me out with this.
You should save the managedObjectContext only once , after all your inserts are done. That will speed up the process a lot. If you expect the number of entries to grow in the future, you can save your context every 500 records added or so, to be on the safe side.
Thank you very much.. I just tried that and found out it is working.. one question.. how would I save it every 500 records or so? I would need to keep a kind of counter or something right?
nobre84;385641 said:
You should save the managedObjectContext only once , after all your inserts are done. That will speed up the process a lot. If you expect the number of entries to grow in the future, you can save your context every 500 records added or so, to be on the safe side.
If the data itself doesn't have any numbering info you can use, you can declare a static int inside the function to count it... Every time you reach 500 , you save the context and set it to zero. Be sure to still save the context at the end of the parsing, because you could be in the middle of a 500-batch and still didn't save before finishing
yeah.. that was what I was thinking about doing too.. thank you for the reply...
nobre84;385683 said:
If the data itself doesn't have any numbering info you can use, you can declare a static int inside the function to count it... Every time you reach 500 , you save the context and set it to zero. Be sure to still save the context at the end of the parsing, because you could be in the middle of a 500-batch and still didn't save before finishing
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeone question.. how would I save it every 500 records or so? I would need to keep a kind of counter or something right?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomethank you for the reply...
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome