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

SQL Anywhere 11.0.0 » MobiLink - Server Administration » MobiLink Events » Synchronization events

 

download_delete_cursor table event

Defines a cursor to select rows that are to be deleted in the remote database.

Parameters

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, but 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

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

Default action

None.

Remarks

The MobiLink server opens a read-only cursor with which to fetch a list of rows to download, and then insert or update in 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 data in the table. See Deleting all the rows in a table.

Note that rows deleted from the consolidated database do 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, you should include the following line in the WHERE clause of your download_delete_cursor script:

AND last_modified > '1900/1/1'

For Java and .NET applications, this script must return valid SQL.

It can be problematic using READPAST table hints in a download_delete_cursor. For details, see the download_cursor event.

See also
SQL example

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 )')
Java example

The following call to a MobiLink system procedure registers a Java method called downloadDeleteCursor as the script for the download_delete_cursor event when synchronizing the script version ver1.

CALL ml_add_java_table_script(
   'ver1',
   'table1',
   'download_delete_cursor',
   'ExamplePackage.ExampleClass.downloadDeleteCursor' )

Following is the sample Java method downloadDeleteCursor. It calls a Java method that generates the SQL for the download delete cursor.

public String downloadDeleteCursor( 
  Timestamp ts,
  String user ) {
  return( getDownloadCursor( _curUser, _curTable ) ); 
}
.NET example

The following call to a MobiLink system procedure registers a .NET method called DownloadDeleteCursor as the script for the download_delete_cursor table event when synchronizing the script version ver1 and the table table1.

CALL ml_add_dnet_table_script(
  'ver1',
  'table1',
  'download_delete_cursor',
  'TestScripts.Test.DownloadDeleteCursor'
)

Following is the sample .NET method DownloadDeleteCursor. It calls a .NET method that generates the SQL for the download delete cursor.

public string DownloadDeleteCursor(
  DateTime timestamp,
  string user ) {
  return( GetDownloadCursor( _curUser, _curTable ) ); 
}