Lesson 3: Creating scripts for your synchronization

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

  • upload_insert   To define how data inserted into the remote database is to be applied to the consolidated database.

  • download_cursor    To define what data should be downloaded from the consolidated database.

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

To add a script version
  1. Connect to the cons database using the MobiLink plug-in for Sybase Central:

    1. In the left pane of Sybase Central, select MobiLink 11.

    2. Choose Mode » Admin.

    3. Choose File » Connect.

    4. Click the Identification tab.

    5. Click ODBC Data Source Name, and type sa_cons. Click OK.

  2. Add the script version ver1:

    1. In the left pane, right-click Versions and choose New » Version.

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

    3. Click Finish.

To add synchronized tables to your consolidated database
  1. In the left pane in the MobiLink 11 list, right-click Synchronized Tables » New » Synchronized Table.

  2. Click Choose A Table In The Consolidated Database With The Same Name As The Remote Table.

  3. On the Which User Owns The Table You Want To Synchronize list, click DBA.

  4. In the Which Table Do You Want To Synchronize list, click Product.

  5. Click Finish.

  6. Add a new table script for each upload and download to the consolidated database

To add table scripts for the Product table
  1. In the left pane in the MobiLink 11 list, expand Synchronized Tables.

  2. Right-click the Product table and choose New » Table Script.

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

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

  5. Click Finish.

  6. In the right pane of Sybase Central, type the following SQL statement:

    INSERT INTO Product( name, quantity, last_modified )
      VALUES( ?, ?, ? )

    The upload_insert event determines how data inserted into the remote database should be applied to the consolidated database. For more information about upload_insert, see upload_insert table event.

  7. Choose File » Save.

  8. Repeat steps 1 to 5 for the download_cursor event using the following SQL statement:

    SELECT name, quantity, last_modified
      FROM Product where last_modified >= ?

    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.

Further reading

For more information about the scripts you just created, see upload_insert table event and download_cursor table event.

For more information about script versions, see Script versions.

For more information about adding scripts, see Adding and deleting scripts.

For more information about writing table scripts, see Table scripts.

For more information about writing synchronization scripts, see Writing synchronization scripts.

For a complete list of the events that you can program to customize your synchronization, see Synchronization events.