KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: The Last Step in Replication: Touch Your Data
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: November 1, 2010

Enabling replication for a 4D table is a fairly easy process. Simply define a primary key and then enable replication. But these two steps alone won't send any data when performed on an existing table. There is one somewhat subtle final step; the existing data must be "touched" so that replication data can be generated for those existing records. This is much like any other structure change in 4D (e.g. changing the type of a field does not modify the data; each record must be loaded and saved in order to apply the change).

In other words the complete process to enable replication for an existing table would look something like this:

  • Define a primary key.
  • Enable replication.
  • Touch all the existing data.

Here is an example for a table named "Groups":

Begin SQL
   ALTER TABLE Groups ADD PRIMARY KEY (Group_ID);
   ALTER TABLE Groups ENABLE REPLICATE;
   UPDATE Groups SET Group_ID = CONCAT(Group_ID,'');
End SQL


The first SQL statement defines the Group_ID field as the primary key for this table. Note that this is not creating a field.

The next statement, of course, enables replication. At this point if you replicated or synchronized the table no data would be sent to the local database.

The last statement "touches" all the data, which causes replication data to be generated (stamps in particular). Subsequent replication or synchronization calls would then get all the data (presuming you start at stamp 0).

It can be useful to provide a way to "reset" replication data for an existing table. Continuing the above example, here is code to reset the replication data for the Groups table:

Begin SQL
   ALTER TABLE Groups DISABLE REPLICATE;
   ALTER TABLE Groups ENABLE REPLICATE;
   UPDATE Groups SET Group_ID = CONCAT(Group_ID,'');
End SQL


As mentioned in the Tech Tip on replication files, do not delete the 4DSyncHeader nor 4DSyncData files. This will not "reset" the replication, it will break it.