Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » MobiLink - Server Administration » Synchronization Techniques » Handling conflicts » Resolving conflicts

Resolving conflicts Next Page

Resolving conflicts with resolve_conflict scripts


When the MobiLink server detects a conflict using an upload_fetch script, the following events take place.

For more information, see resolve_conflict table event.

Example

In the following example, you create scripts for six events and then you create a stored procedure.

EventScript
begin_synchronization
CREATE TABLE #contact_new( 
   id  INTEGER,
   location CHAR(36),
   contact_date DATE);
CREATE TABLE #contact_old(
   id  INTEGER,
   location CHAR(36),
   contact_date DATE)
upload_fetch
SELECT id, location, contact_date
   FROM contact
   WHERE id = {ml r.id}
upload_old_row_insert
INSERT INTO #contact_new( id, location, contact_date ) 
  VALUES ( {ml r.id}, {ml r.location}, {ml r.contact_date} )
upload_new_row_insert
INSERT INTO #contact_old( id, location, contact_date )
  VALUES ( {ml r.id}, {ml r.location}, {ml r.contact_date} )
resolve_conflict
CALL MLResolveContactConflict( )
end_synchronization
DROP TABLE #contact_new;
DROP TABLE #contact_old

The stored procedure MLResolveContactConflict is as follows:

CREATE PROCEDURE MLResolveContactConflict( )
BEGIN
  --update the consolidated database only if the new contact date
  --is later than the existing contact date
  UPDATE contact c
    SET c.contact_date = cn.contact_date
      FROM #contact_new cn
      WHERE c.id = cn.id
        AND cn.contact_date > c.contact_date;
  --cleanup
  DELETE FROM #contact_new;
  DELETE FROM #contact_old;
END