When you use download acknowledgement, this script provides a place to record the information that a download has been applied successfully, or to trigger business logic that depends on the download being confirmed as applied.
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.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. |
1 |
s.last_download |
TIMESTAMP. This is the last download time for the current synchronization. |
2 |
This event lets you record the time when the download was successfully applied at the remote database.
This event is only called when using download acknowledgement. The download transaction is committed and the synchronization ends when the download is sent. This event is called when the synchronization client acknowledges a successful download. This event is called on a new connection, after the end_synchronization script of the original synchronization. The actions of this event are committed along with an update to the download time in the MobiLink system tables.
Due to the special nature of this script, any connection-level variables set during the synchronization are not available when this event is executed.
If the download is unsuccessful or if the network connection is dropped, there is no acknowledgement and this script is not invoked. If timely download acknowledgement is critical to your business needs, you should use the last_download parameter of the prepare_for_download script or the last_publication_download parameter of the begin_publication script as backups for your download acknowledgement processing.
The following script adds a record to the table download_pubs_acked. The record contains the remote ID, the first authentication parameter, and the download timestamp.
INSERT INTO download_pubs_acked( rem_id, auth_parm, last_download ) VALUES( {ml s.remote_id}, {ml a.1}, {ml s.last_download} ) |
The following call to a MobiLink system procedure registers a Java method called confirmDownload as the script for the nonblocking_download_ack event when synchronizing the script version ver1.
CALL ml_add_java_connection_script( 'ver1', 'nonblocking_download_ack', 'ExamplePackage.ExampleClass.confirmDownload' ) |
The following is the sample Java method confirmDownload. It calls a Java method to perform business logic based on the download being confirmed, up to the given timestamp, for the given user.
package ExamplePackage; import ianywhere.ml.script.*; import java.sql.*; public class ExampleClass { DBConnectionContext _cc; public ExampleClass( DBConnectionContext cc ) { _cc = cc; } public void confirmDownload( String user, Timestamp ts ) throws SQLException { Connection conn = _cc.getConnection(); PreparedStatement stmt = conn.prepareStatement( "INSERT INTO download_pubs_acked( rem_id, last_download ) " + "VALUES( ?, ? )" ); stmt.setString( 1, _cc.getRemoteID() ); stmt.setTimestamp( 2, ts ); stmt.executeUpdate(); stmt.close(); } } |
The following call to a MobiLink system procedure registers a .NET method called ConfirmDownload as the script for the nonblocking_download_ack connection event when synchronizing the script version ver1.
CALL ml_add_dnet_connection_script( 'ver1', 'nonblocking_downlolad_ack', 'TestScripts.Test.ConfirmDownload' ) |
The following is the sample .NET method ConfirmDownload. It calls a .NET method to perform business logic based on the download being confirmed, up to the given timestamp, for the given user.
using System; using iAnywhere.MobiLink.Script; namespace TestScripts { public class Test { DBConnectionContext _cc; public Test( DBConnectionContext cc ) { _cc = cc; } public void ConfirmDownload( string user, DateTime dt ) { DBConnection conn = _cc.GetConnection(); DBCommand cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO download_pubs_acked( rem_id, last_download ) " + "VALUES( ?, ? )"; cmd.Parameters[0] = _cc.GetRemoteID(); cmd.Parameters[1] = dt; cmd.ExecuteNonQuery(); } } } |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |