MobiLink Synchronization User's Guide
Synchronization Techniques
Handling conflicts
How conflicts are detected
When using upload_update scripts, conflict detection is carried out in one of the following circumstances:
An upload_fetch script is supplied.
The upload_fetch script typically selects a single row of data from a table corresponding to the row being updated. A typical upload_fetch script would conform to the following syntax:
SELECT col1, col2, ...
FROM table-name
WHERE pk1 = ? AND pk2 = ? ...
For more information, see upload_fetch table event.
The upload_update script provides a parameter for each element on the row.
The parameters for an upload_update event are arranged so that statements with the following syntax update rows correctly:
UPDATE table-name
SET col1 = ?, col2 = ?, ...
WHERE pk1 = ? AND pk2 = ? ...
In this statement, col1, col2 and so on are the non-primary key columns, while pk1, pk2 and so on are primary key columns.
For a conflict to be detected, the syntax must be as follows:
UPDATE table-name
SET col1 = ?, col2 = ?, ...
WHERE pk1 = ? AND pk2 = ? ...
AND col1 = ? AND col2 = ? ...
For more information, see upload_update table event.
The MobiLink synchronization server processes each uploaded update using the following procedure.
MobiLink synchronization server detects conflicts only if an upload_fetch or appropriate upload_update script is applied:
If an upload_fetch script is supplied, the MobiLink synchronization server compares the old uploaded values to the values of the row returned by the upload_fetch statement with the same primary key values.
If an upload_update script of the above form is supplied, the MobiLink synchronization server compares the old uploaded values to the values of the row returned in the final set of parameters.
If any of the old uploaded values do not match the current consolidated values, the MobiLink synchronization server detects a conflict.
The MobiLink synchronization server inserts the old values as defined by the upload_old_row_insert script.
For more information, see upload_old_row_insert table event.
The MobiLink synchronization server inserts the new values as defined by the upload_new_row_insert script.
For more information, see upload_new_row_insert table event.
The MobiLink synchronization server executes the resolve_conflict script. In this script you can either call a stored procedure, or define a sequence of steps to resolve the conflict as appropriate.
For more information, see resolve_conflict table event.
You can resolve conflicts as they occur using the resolve_conflict script, or you can resolve all conflicts at once using the table's end_upload script.
For an example of conflict resolution using statement-based uploads, see Synchronizing products in the Contact sample.