table data row synchronization between two computers

From: Tim Smith <timasmith_at_hotmail.com>
Date: 24 Oct 2002 15:36:13 -0700
Message-ID: <a7234bb1.0210241436.394641ff_at_posting.google.com>



Hi,

   Can you check over the following algorithm I used for an app to synchronize table data. The premise is that I have a local computer (usually my laptop) and a remote computer (my website). If I update data on my laptop I want to update the website and vice versa. If there are conflicts then I want to always have resolution (since I'm too lazy to check out the conflicts :-) and so I designate my laptop as the 'master' who always wins on a conflict.

   Potentially I would like to have this work for my desktop PC too - such that the same rules work between PC and website and PC and laptop. My head starts to boggle at trying to figure out all the scenarios for that too but in any case here it is.

   I use two dates and a primary key as the pertinent fields for each row.
Both dates are filled out with default values on insert. local_date_time: This is updated by the computer who did the update. import_date_time: This is filled out when rows are imported with the remote computers local_date_time
unique_id: Identifier that designates from which computer this row came from
primary_key: Table specific but has both a unique number identifying the computer and a unique identifier for the table row.

On import for each row:

   If search_local_table(remote_primary_key) == NOT_FOUND

      if unique_id was from this computer
          then the row must have been deleted - skip it 
      else
          insert into local_table, setting the local and import
date/time
          to be equal to the remote date time
   else if local_date_time = remote_date_time
          there is not change - skip it
   else
        if local_date_time = remote_import_date_time 
             I have not changed the data since last import - update
the row
        else if local_date_time = local_import_date_time
             I have not changed the data since last import - update
the row
        else if I am the master 
             skip I keep the data
        else if the remote is the master
             update 
        else if the remote has a more recent local date/time
             update with most recent
        else
             skip since I have more recent copy

There you have it. If there is a paper or other academic solution to what must be a common problem please let me know.

thanks!

Tim Received on Fri Oct 25 2002 - 00:36:13 CEST

Original text of this message