Lesson 3: Adding synchronization scripts

This lesson assumes you have completed all preceding lessons. See Lesson 1: Setting up your MobiLink consolidated database.

You can view, write, and modify synchronization scripts using Sybase Central. In this lesson, you write the following synchronization scripts:

  • upload_insert   This event defines how new client-side data should be applied to the consolidated database.

  • download_cursor   This event defines the data that should be downloaded to remote clients.

  • download_delete_cursor   This event is required when using synchronization scripts that are not upload-only. You set the MobiLink server to ignore this event for the purpose of this tutorial.

Each script belongs to a designated script version. You must add a script version to the consolidated database before you add scripts.

 Add synchronization scripts
  1. Click View » Folders.

  2. In the left pane of Sybase Central under MobiLink 12, expand mlreplay_project, Consolidated Databases, cons - DBA.

  3. Right-click Versions and choose New » Version.

  4. In the What Do You Want To Name The New Script Version field, type MLReplayDemo.

  5. Click Finish.

  6. In the left pane of Sybase Central under MobiLink 12, expand mlreplay_project, Consolidated Databases, cons - DBA.

  7. Right-click Synchronized Tables and click New » Synchronized Table.

  8. Click the Choose A Table In The Consolidated Database With The Same Name As The Remote Table option.

  9. In the Which User Owns The Table You Want To Synchronize list, click DBA.

  10. In the Which Table Do You Want To Synchronize list, click T1.

  11. Click Finish.

    The T1 table is registered as a synchronization table and you can add scripts to that table.

  12. In the left pane of Sybase Central under MobiLink 12, expand mlreplay_project, Consolidated Databases, cons - DBA, Synchronized Tables.

  13. Right-click T1 and click New » Table Script.

  14. In the For Which Version Do You Want To Create The Table Script list, click MLReplayDemo.

  15. In the Which Event Should Cause The Table Script To Be Executed list, click upload_insert and click Next.

  16. Click Finish.

  17. In the right pane of Sybase Central, use the following SQL script for the upload_insert event:

    INSERT INTO T1 VALUES( cast({ml s.remote_id} as INTEGER), {ml r.2}, {ml r.3} );

    The upload_insert event determines how data inserted into the remote database should be applied to the consolidated database. See upload_insert table event.

  18. Click File » Save.

  19. Repeat steps 13 to 16, specifying the download_cursor event instead of the upload_insert event in step 15.

  20. In the right pane of Sybase Central, use the following SQL script for the download_cursor event:

    SELECT pk1, pk2, c1 FROM T1;

    The download_cursor script defines a cursor to select consolidated database rows that are downloaded and inserted or updated in the remote database. For more information about download_cursor, see download_cursor table event.

  21. Click File » Save.

  22. Repeat steps 13 to 16, specifying the download_delete_cursor event instead of the upload_insert event in step 15.

  23. In the right pane of Sybase Central, use the following SQL script for the download_delete_cursor event:

    --{ml_ignore}
  24. Click File » Save.

  25. Proceed to Lesson 4: Starting the MobiLink server to record.

 See also