How to insert data coming from web service into sql database in iphone? - iphone

I am developing an app where I need to insert data coming from web service into sqlite3 database.Web service returns XML data with 5 tags.Now after XML parsing how to insert parsed data into sql database?
Can I code for this???
Thanks in advance..

Inserting XML data in sqlite database is no different that inserting any data. So there are 3 parts of the problem you are trying to solve:
Calling the web service and getting the data
Parsing the data and populating some object
Inserting that data in sqlite database which has columns as per your object structure
NSURLConnection and NSXMLParser are the classed you need to look at for solving first 2 problems. Third one would be solved using sqlite library. Without more information about object structure it is difficult to suggest anything else. But you should find enough documentation on using sqlite if you search around.

Related

How to convert sqlite data into xml file and xml file into sql data?

I am developing an application. In that I want to create an XML file with sqlite data and place another XML data into sqlite field. So please tell me how to do this.
Well hope you used Core Data to interact with your DB.
If you did so, just loop your Entities and use a NSMutableString to build your XML document.

Populate Core Data structure for iPhone/iPad with Sqlite3

I have a SQLite database. Should I put the DB in a data structure with Core Data. How can I do? My problem is "z relations" between tables.
It's possible?
Core Data isn't SQL even when it employs an SQLite store. Although it is theoretically possible to convert a standard SQLite file to the schema Core Data uses, that is difficult and risky especially given that Apple doesn't document the schema and can therefore change it without warning. You really need to translate the SQL data into Core Data objects.
The best way is to write a utility app containing you Core Data model. Read in the SQL data with the standard functions and then use that data and relationships to create the appropriate managed objects and object relationships in Core Data.
Usually you have code anyway for creating managed objects, populating attributes and setting relationships. Just use that code but instead of providing the data from the UI or a feed, provide it from the data provided by SQL.
I found a solution. In the future, should I use SQLite directly, but for those who have a similar problem to mine this solution works well.
Step 1: Core Data in your table add column headed gl'ID temporary relations of the original table.
Step 2: In the data in CSV add two columns. The first column contains the value 1 and refers to P_OPT of Core Data and the second column contains the identifier of the table and retrieved P_ENT generated by reading the SQLite Core Data in the table Z_PRIMARYKEY.
Step 3: With any editor Mac transfer your data in SQLite files generated by Core Data. Remember to attach gl'ID (relations) in the temporary columns.
Step 4: Through the use of the SQL UPDATE command (works with any SQL editor on the Mac) updates all ID columns of relations in Core Data with the value Z_PK. The value retrieved by the queries and the use of temporary columns.
Sorry for the bad English. I hope not to have been convoluted with the explanation and useful to others.

Synchronizing Core Data data with External Database

I have started working on an iPhone application that where I need to synchronize data with an external MySQL database. The current database scheme uses GUID/UUID fields as primary keys to maintain relationships between tables. I already have this working between a database app and the MySQL database, so this isn't a question regarding synchronization per say.
I've started going down the path of using Core Data, but I'm realizing that it maintains relationships between entities using it's own schema within the SQLite database.
Am I going down the wrong path using Core Data? If not how does one synchronize data between a Core Data store and an external database and still maintain the data relationships?
All you need to do is write the logic to translate entities from one db schema to another. You can fetch objects from the server and convert them to core data objects, and fetch object from core data and convert them to mysql entities when saving to the server. Nothing too difficult involved really
I agree with Griffo; simply translate the rows or entities you retrieve from the mysql database into managed objects (and visa versa).
If I understand what you are looking to correctly, I would definitely recommend using Core data. Translating the data between MySQL and Core Data isn't that hard, and if you use an NSFetchedResultsController to display your data in a UITableView, you practically don't have to write any code.
and you can always preserve the original GUIDs as, for example, optional externalIDs for the imported entities. This way you will be able troubleshoot your data imports easier and correlated the data between the to types of the data stores.

Combining a datastore with Mapkit

Does anyone have any advice on using a datastore with mapkit to provide a database of locations (Restaurants) that are query-able by location?
I would like to use Core data but importing the information into it seems like a project in itself. If anyone has good advice on converting an existing sqlite/cvs file to a coredata sqlite file that would be appreciated.
Is old-fashioned sqlite better than using core data for the task, or is it a case that I should create a web service for the job?
I would like to be able to query the locations based on the map zoom also.
Thanks if you have any advice on the matter.
If you write your object model correctly, you can just point it at an existing sqLite database and it will read it as if core data generated it in the first place.
For example, suppose you have an existing sqlite db of people with columns like firstName, lastName, phone# etc. You just create a core data model with a entity with attributes of firstName, lastName, phone# etc. Spell them the same and make sure they have the right type and then point the NSPersistentStoreCoordinator at the existing database. It will read it in fine.
Core data is always the way to go for any larger data management task. It makes everything so much easier once you learn it.
Edit01:
Never mind the above. I was thinking of Enterprise Objects. Core data won't easily import most existing SQL.
Instead, I would export the sqlite to csv and then use something like cCSVParse to convert to plist. Then you can read it in easily to an array or dictionary and use that to populate the core data db.
That will work easily for db's that don't depend on complex relationships. I think the future benefits of having core data will eventually easily pay for the few man hours spent converting.

Loading a CSV into Core Data managed sqlite db

I have a CSV file containing data.
I want to load it into a Core Data managed sqlite db.
I just ran one of the sample Core Data Xcode apps and noticed it created the db file.
I noticed table names all started with Z and the primary keys were stored in separate table so from this am I right in presuming that just importing the CSV data directly into the db using sqlite3 command line might mess up primary keys.
Do I need to write a program to read in the CSV line by line and then create objects for each row and persist them to the db.
Anyone got any code for this?
And can I write a desktop client to do this using Core Data. If so will the db be fine to use in IPhone core data app?
Can I then just include the prefilled db in my project and it will be deployed with the app correctly or is there something else I should do.
Use NSScanner to read your CSV file into the NSManagedObject instances in your Core Data store.
I have some categories on NSString for reading and writing CSV files from/to NSArrays. I'll post them online and edit my answer with a link to it.
edit
They're online here: http://github.com/davedelong/CHCSVParser