Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 04-12-2009, 10:44 PM   #9 (permalink)
smontgomerie
New Member
 
Join Date: Mar 2009
Posts: 5
Default

Quote:
Originally Posted by jtara View Post
XML is almost certainly overkill. Not sure why everybody is so XML-crazy. XML is slow, difficult to parse, and bloaty.

CSV is light and simple. With XML you are sending several times the number of bytes over the air. (Unless you compress, in which case the advantage of CSV may be minimal in terms of bytes transmitted, as XML's bloat is primarly in redundancy.)

You can use a timestamp, or you could use revision numbers. You might prefer a timestamp, because it might be useful for internal auditing. But a revision number is lighter. The revision numbers would have to be GLOBAL within the database, just like a timestamp would be. (That is, not "revision 2 of record 10", but revision 2, period. Each record changed increments the global revision number.)

You need a table in the database that keeps track of the highest revision number (or timestamp) that each user has. Or you could keep track of that in the client.

Updates and new records are easy. Deletions are a bit more complicated, but not very much so - you can't ever really delete a record on the server. Have a "deleted" column in the master database. When you "delete" a record, you set the deleted column true, and the client needs to know when it gets an update, if the deleted column is true, to delete the record. (You CAN delete records on the client side, just not on the server side.)

When the client makes a request to the web service for an update, the server will do a database query for all records with a revision number (or timestamp) greater than the largest revision number/timestamp which the client already has.

There you go, there's your sync. Or, actually, replication.

Now, did you really mean "sync", or just "replicate"? Because if you meant "sync" that is more complicated. That is, will clients be making changes to the database, and those need to be uploaded too?
jtara,
I was more thinking of a framework for doing this kind of thing - it has to be a common task on the iPhone. But thanks for the suggestions on how to do this, as I suspect I'll be writing my own framework.

I was more thinking of sync (as in, client makes changes on iPhone, they are reflected in a database, which can be changed via another medium, like a web interface, re-synced back to the iPhone - so 2-way sync). I imagine it would be similar to the structure that you propose, where each table in each database (client and remote) has a timestamp, and each record must be diff'd against each other record that has changed since the last sync time.

In terms of protocols, I'm more partial to JSON. It's very lightweight, easy to parse, and much more object-friendly than CSV. And there are both great client-side libraries and server-side support for the protocol, but yeah, XML is way too heavy.
smontgomerie is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,722
Threads: 89,182
Posts: 380,506
Top Poster: BrianSlick (7,125)
Welcome to our newest member, idny99
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:57 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.