views:

919

answers:

2

Hello,

I have a situation where I need to store the data in local (iphone) and the same data will be in the web server to be accessed by other users (like sending messages) .

For the web server part I am not worrying, I created all the tables and relations. but I am worrying about Iphone side data storage and sync both sides correctly.

Here is an example of how I want to use A table in both sides (iphone and web server)

Messages table with : message ID (primary key with incremental) , user ID c(12) and message text C(100) I can able to send the user ID and message text to the web server(by using URL) and get the primary key of the message ID from the web server.

Now my dilemma is populating the unique ID's(primary key) for each record in each table (will be an Integer ) weather in iphone side or In web server database ?

Thanks In advance. Sridhar

+1  A: 

you might be able to have your webserver generate a sqlite file for your app to download? Since sqlite is available for almost anything this might be a useful optimization; a sync would be a simple upload/download of a file.

Kevlar
+6  A: 

Since you can't control the internal keys in CoreData, and because CoreData requires a VERY specific schema to work at all, AND you don't want to mess with CoreData's SQL directly (it has all kinds of flags on each row that aren't docuemnted), you'll want to have a different database schema on the server from the iPhone.

For the unique ID, you'll want to just add your own column to CoreData, and make sure you throw an index on it.

If you're going to be generating new rows on both the iPhone AND the web server, you'll want to use some scheme to ensure the keys are unique on both - the easiest one would be to generate a UUID using CFUIIDCreate() and related functions, and store that in your table as a string.

-Wil

Wil Shipley
Thank you for the reply, I did by using one auto inc column in web server and then get the uinique ID from the web server and fill it in iphone core data column.
Sridhar