This is not a complete answer, but may at least provide you with some ideas ...
The question you ask (and the problem you are trying to address) does not apply to Google Gears and remains valid with other solutions, such as HTML 5 or systems or Flash / Air.
Over the past month, ZendCon made a presentation about this subject, and slides are available on the slide show: Planning for synchronization with the browser -Local databases
Going through the thoses slides, you will see notes on several possibilities that may come to mind (some really come to your mind or in other answers):
- Using GUID
- Composite Keys
- Primary key pool (i.e. reserve a range of keys in advance)
Of course, for each of them there are advantages ... and disadvantages - I will not copy them: take a look at the slides; -)
Now, in your situation, which solution will be the best? Itβs hard to say, actually - and the sooner you think about synchronization, the better / easier it will be: adding material to the application is much easier when this application is still at the development stage ^^
First, it may be interesting to determine:
- Your application is usually connected, and its disconnection is rare.
- Or, if your application is usually disconnected and only connects from time to time.
Then what are you going to sync?
- Data?
- Like "This is a list of all the commands made by this user."
- With this data replicated to each separately connected device, of course, each of which can change it.
- In this case, if one user deletes a row and another adds a row , how do you know who has the βtrueβ data?
- Or actions taken from this data?
- Like "I am adding an entry to the list of commands made by this user"
- In this case, if one user deletes a row and another adds a row, it is easy to synchronize, because you just need to synchronize these two actions with the central database
- But this is not so easy to implement, especially for a large application / system: every time an action is performed, you need to register it!
There is also a special problem that we usually donβt think about until it happens: especially if your synchronization process may take some time (if you have a lot of data, if you do not synchronize often ...), what to do if synchronization is stopped when it is not finished yet?
For example, what if:
- The user on the train has access to the network, with some 3G card
- Sync begins
- there is a tunnel - and the connection is lost.
Semi-synchronized data may not be as good in most situations ...
So, you should also find a solution to this problem: in most cases, synchronization should be atomic!