A data script that defines a cursor to select rows that are to be deleted 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 opens a read-only cursor to fetch a list of rows to download, and then delete from the remote database. This script must contain a SELECT statement that returns the primary key values of the rows to be deleted from the table in the remote database.
You can have one download_delete_cursor script for each table in the remote database.
If the download_delete_cursor has nulls for the primary key columns for one or more rows in a table, then MobiLink tells the remote to delete all the rows in the table. See Deleting all the rows in a table.
Note that rows deleted from the consolidated database can not appear in a result set defined by a download_delete_cursor event, and so are not automatically deleted from the remote database. One technique for identifying rows to be deleted from remote databases is to add a column to the consolidated database table identifying a row as inactive.
To avoid downloading unnecessary rows to delete, consider using timestamp-based downloads. Include a line similar to the following in the WHERE clause of your download_delete_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.
It can be problematic using READPAST table hints in a download_delete_cursor. For details, see the download_cursor event.
This example is taken from the Contact sample and can be found in Samples\MobiLink\Contact\build_consol.sql. It deletes from the remote database any customers who have been changed since the last time this user downloaded data (Customer.last_modified >= {ml s.last_table_download}
), and either
do not belong to the synchronizing user (SalesRep.username != {ml s.username}
), or
are marked as inactive in the consolidated database (Customer.active = 0
).
CALL ml_add_table_script( 'ver1', 'table1', 'download_delete_cursor', 'SELECT cust_id FROM Customer key join SalesRep WHERE Customer.last_modified >= {ml s.last_table_download} AND ( SalesRep.username != {ml s.username} OR Customer.active = 0 )') |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |