A data script that defines a cursor to select rows to download and insert or update in the given table in the remote database.
In the following table, the description provides the SQL data type. If you are writing your script in Java or .NET, you should use the appropriate corresponding data type. See SQL-Java data types and SQL-.NET data types.
In SQL scripts, you can specify event parameters by name or with a question mark. Using question marks has been deprecated and it is recommended that you use named parameters. You cannot mix names and question marks within a script. If you use question marks, the parameters must be in the order shown below and are optional only if no subsequent parameters are specified (for example, you must use parameter 1 if you want to use parameter 2). If you use named parameters, you can specify any subset of the parameters in any order.
Parameter name for SQL scripts | Description | Order (deprecated for SQL) |
---|---|---|
s.last_table_download |
TIMESTAMP. The last download time for the table. |
1 |
s.remote_id | VARCHAR(128). The MobiLink remote ID. You can only reference the remote ID if you are using named parameters. | Not applicable |
s.username |
VARCHAR(128). The MobiLink user name. |
2 |
None.
The MobiLink server uses the script to open a read-only cursor to fetch a list of rows to download to the remote database.
You can have one download_cursor script for each table in the remote database.
To optimize performance of the download stage of synchronization to UltraLite clients, when the range of primary key values is outside the current rows on the device, you should order the rows in the download cursor by primary key. Downloads of large reference tables, for example, can benefit from this optimization.
Each download_cursor script must contain a SELECT statement or a call to a procedure that returns a result set. The MobiLink 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.
To avoid downloading unnecessary rows, consider using timestamp-based downloads. When using timestamp-based downloads, include a line similar to the following in the WHERE clause of your download_cursor script:
AND last_modified >= {ml s.last_table_download} |
This script must be implemented in SQL. For Java or .NET processing of rows, see Direct row handling.
If you are considering using READPAST table hints in download_cursor scripts because you are doing lots of updates that affect download performance, consider using snapshot isolation for downloads instead. The READPAST table hint can cause problems if used in download_cursor scripts. When using timestamp-based downloads, the READPAST hint can cause rows to be missed, and can cause a row to never be downloaded to a remote database. For example:
A row is added to the consolidated database and committed. The row has a last_modified column with a time of yesterday.
The same row is updated but not committed.
A remote database with a last_download time of last week synchronizes.
A download_cursor script attempts to select the row using READPAST, and skips the row.
The transaction that updated the row is rolled back. The next last download time for the remote is advanced to today.
From this point on, the row is never downloaded unless it is updated. A possible workaround is to implement a generate_next_last_download_timestamp or modify_next_last_download_timestamp script and set the last download time to be the start time of the oldest open transaction.
The following example comes from an Oracle installation, although the statement is valid against all supported databases. This example downloads all rows that have been changed since the last time the user downloaded data, and that match the user name in the emp_name column.
CALL ml_add_table_script( 'Lab', 'ULOrder', 'download_cursor', 'SELECT order_id, cust_id, prod_id, emp_id, disc, quant, notes, status FROM ULOrder WHERE last_modified >= {ml s.last_table_download} AND emp_name = {ml s.username}' ) |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |