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

SQL Anywhere 11.0.1 (Français) » MobiLink - Server Administration » MobiLink Events » Synchronization events

 

modify_last_download_timestamp connection event

The script can be used to modify the last download time for the current synchronization.

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_download

TIMESTAMP. The last download time for any synchronized table. This is an INOUT parameter.

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

Use this script when you want to modify the last_download timestamp for the current synchronization. If this script is defined, the MobiLink server uses the modified last_download timestamp as the last_download timestamp passed to the download scripts. A typical use of this script is to recover from losing data on the remote; you can reset the last_download timestamp to an early time such as 1900-01-01 00:00 so that the next synchronization downloads all the data.

SQL scripts for the modify_last_download_timestamp event must be implemented as stored procedures. The MobiLink server passes in the last_download timestamp as the first parameter to the stored procedure, and replaces the timestamp by the first value passed out by the stored procedure.

This script is executed just before the prepare_for_download script, in the same transaction.

See also
SQL example

The following SQL statement creates a stored procedure. The following syntax is for Oracle consolidated databases:

CREATE PROCEDURE ModifyDownloadTimestamp(
        download_timestamp  OUT DATE,
        user_name   IN VARCHAR )
        AS
        BEGIN
         -- N is the maximum replication latency in the consolidated cluster
        download_timestamp := download_timestamp - N;
        END;

The following syntax is for SQL Anywhere, Adaptive Server Enterprise, and SQL Server consolidated databases:

CREATE PROCEDURE ModifyDownloadTimestamp
        @download_timestamp DATETIME OUTPUT,
        @t_name    VARCHAR( 128 )
        AS
        BEGIN
         -- N is the maximum replication latency in consolidated cluster
        SELECT @download_timestamp = @download_timestamp - N
        END

The following syntax is for DB2 mainframe consolidated databases:

CREATE PROCEDURE modify_ldts( 
        OUT ts      TIMESTAMP,
        IN  t_name  VARCHAR(128) )
        LANGUAGE SQL
        BEGIN
            set ts = TIMESTAMP_FORMAT('2000-01-02 03:04:05','YYYY-MM-DD HH24:MI:SS');
        END

The following call to a MobiLink system procedure assigns the ModifyDownloadTimestamp stored procedure to the modify_last_download_timestamp event. The following syntax is for a SQL Anywhere consolidated database:

CALL ml_add_connection_script(
  'my_version',
  'modify_last_download_timestamp',
  '{CALL ModifyDownloadTimestamp(
   {ml s.last_download}, 
   {ml s.username} ) }' )
Java example

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

CALL ml_add_java_connection_script(
  'ver1',
  'modify_last_download_timestamp',
  'ExamplePackage.ExampleClass.modifyLastDownloadTimestamp' )

The following is the sample Java method modifyLastDownloadTimestamp. It prints the current and new timestamp and modifies the timestamp that is passed in.

public String modifyLastDownloadTimestamp(
     Timestamp lastDownloadTime,
     String userName ) {
   java.lang.System.out.println( "old date: " +
    lastDownloadTime.toString() );
   lastDownloadTime.setDate(
    lastDownloadTime.getDate() -1 );
   java.lang.System.out.println( "new date: " +
    lastDownloadTime.toString() );
   return( null ); 
}
.NET example

The following call to a MobiLink system procedure registers a .NET method called ModifyLastDownloadTimestamp as the script for the modify_last_download_timestamp connection event when synchronizing the script version ver1.

CALL ml_add_dnet_connection_script(
  'ver1',
  'modify_last_download_timestamp',
  'TestScripts.Test.ModifyLastDownloadTimestamp' )

The following is the sample .NET method ModifyLastDownloadTimestamp.

public string ModifyLastDownloadTimestamp(
  DateTime lastDownloadTime,
  string userName ) {
  System.Console.WriteLine( "old date: " +
   last_download_time.ToString() );
  last_download_time = DateTime::Now;
  System.Console.WriteLine( "new date: " +
   last_download_time.ToString() );
  return( null );
}