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

SAP Sybase SQL Anywhere 16.0 » MobiLink - Getting Started » MobiLink tutorials » Tutorial: Synchronizing with XML


Lesson 4: Adding synchronization scripts

In this lesson, you add scripts to your consolidated database for SQL row handling and direct row handling.


This lesson assumes you have completed all preceding lessons. See Lesson 1: Setting up an XML data source.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Synchronizing with XML.

Contexte et remarques

SQL row handling allows you to synchronize remote data with tables in your MobiLink consolidated database. SQL-based scripts define:

  • How data that is uploaded from a MobiLink client is to be applied to the consolidated database.

  • What data should be downloaded from the consolidated database.

In this lesson, you write synchronization scripts for the following SQL-based upload and download events:

  • upload_insert   This event defines how new orders inserted in a client database should be applied to the consolidated database.

  • download_cursor   This event defines the orders 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.

You use direct row handling to add special processing to a SQL-based synchronization system. In this lesson, you register method names corresponding to the handle_UploadData, download_cursor, and download_delete_cursor events. You create your own Java class in Lesson 5: Creating a Java class for MobiLink direct row handling.

  1. Connect to your consolidated database in Interactive SQL if you are not already connected.

    Run the following command:

    dbisql -c "DSN=mlxml_db"
  2. Use the ml_add_table_script stored procedure to add SQL-based table scripts for the upload_insert, download_cursor and download_delete_cursor events.

    Execute the following SQL statement in Interactive SQL. The upload_insert script inserts the uploaded order_id, product_id, quantity, and order_status into the MobiLink consolidated database. The download_cursor script uses timestamp-based filtering to download updated rows to remote clients.

    CALL ml_add_table_script( 'default', 'RemoteOrders', 
        'INSERT INTO RemoteOrders( order_id, product_id, quantity, order_status)
        VALUES( {ml r.order_id}, {ml r.product_id}, {ml r.quantity}, {ml r.order_status} )' );
    CALL ml_add_table_script( 'default', 'RemoteOrders',
        'SELECT order_id, product_id, quantity, order_status
        FROM RemoteOrders WHERE last_modified >= {ml s.last_table_download}');
    CALL ml_add_table_script( 'default', 'RemoteOrders',
        'download_delete_cursor', '--{ml_ignore}');
  3. Register the Java method for the handle_UploadData event.

    Execute the following SQL statement in Interactive SQL:

    CALL ml_add_java_connection_script( 'default', 
        'handle_UploadData', 'MobiLinkOrders.GetUpload' );

    Interactive SQL registers the GetUpload method for the handle_UploadData event. You create the GetUpload method, which retrieves inserted data from the OrderComments table in the MobiLink client database, in an upcoming lesson.

  4. Register the download_cursor and download_delete_cursor events.

    Execute the following SQL statements in Interactive SQL:

    CALL ml_add_table_script( 'default', 'OrderComments',
        'download_cursor', '--{ml_ignore}');
    CALL ml_add_table_script( 'default', 'OrderComments',
        'download_delete_cursor', '--{ml_ignore}');

    The download_cursor and download_delete_cursor events must be registered for the OrderComments table when using scripts because the synchronization is bi-directional and not upload-only. See Required scripts.

  5. Commit your changes.

    Execute the following SQL statement in Interactive SQL:

  6. Close Interactive SQL.


Method names corresponding to the handle_UploadData, handle_DownloadData, end_download, download_cursor, and download_delete_cursor events are registered.

 See also