MobiLink Synchronization User's Guide
Writing Synchronization Scripts
Writing scripts to download rows
You write download_cursor scripts to download information from the consolidated database to your remote database. You must write one of these scripts for each table in the remote database for which you want to download changes. You can use other scripts to customize the download process, but no others are necessary.
Each download_cursor script must contain a SELECT statement or a call to a procedure that contains a SELECT statement. The MobiLink synchronization server uses this statement to define a cursor in the consolidated database.
The script must select all columns that correspond to the columns in the corresponding table in the remote database. The columns in the consolidated database can have different names than the corresponding columns in the remote database, but they must be of compatible types.
The columns must be selected in the order that the corresponding columns are defined in the remote database. This order is identical to the order of the columns in the reference database.
The following script could serve as a download_cursor script for a remote table that holds employee information. The MobiLink synchronization server would use this SQL statement to define the download cursor. This script downloads information about all the employees.
SELECT emp_id, emp_fname, emp_lname FROM employee
The MobiLink synchronization server passes specific parameters to some scripts. To use these parameters, you include a question mark in your SQL statement. The MobiLink synchronization server substitutes the value of the parameter before executing the statement against the consolidated database. The following script shows how you can use these parameters:
call ml_add_table_script( 'Lab', 'ULOrder', 'download_cursor', 'SELECT o.order_id, o.cust_id, o.prod_id, o.emp_id, o.disc, o.quant, o.notes, o.status FROM ULOrder o WHERE o.last_modified >= ? AND o.emp_name = ?' )
In this example, the MobiLink synchronization server replaces the question mark with the value of the parameter to the download_cursor script.
Row values can be selected from a single table or from a join of multiple tables.
The script itself need not include the name of the remote table. The remote table need not have the same name as the table in the consolidated database. The name of the remote table is identified by an entry in the ml_table table. In Sybase Central, the remote tables are listed together with their scripts.
The rows in the remote table must contain the values of emp_id, emp_fname, and emp_lname. The remote columns must be in that order, although they can have different names. The columns in the remote database are in the same order as those in the reference database.
UltraLite tipThe example scripts list the columns in the order that they are defined in the reference database. Inspect the example_download_cursor and example_upload_cursor scripts to see the column order. |
All cursor scripts must select the columns in the same order as the columns are defined in the remote database. Where column names or table structure is different in the consolidated database, columns should be selected in the correct order for the remote database, or equivalently, the reference database. Columns are assigned to columns in the remote database based on their order in the SELECT statement.
When you build an UltraLite application, the UltraLite generator creates a sample download script for each table in your UltraLite application. It inserts these sample scripts into your reference database. The example scripts assume that the consolidated database contains the same tables as your application. You must modify the sample scripts if your consolidated database differs in design, but these scripts provide a starting point.