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

SQL Anywhere 17 » MobiLink - Server Administration » MobiLink events » Synchronization events

begin_publication connection event

Provides useful information about the publication(s) being synchronized. This script may also be used to manage generation numbers for file-based downloads.


In the following table, the description provides the SQL data type. If you are writing your script in Java or .NET, use the appropriate corresponding data type.

In SQL scripts, you can specify event parameters by name or with a question mark. Using question marks has been deprecated. Use named parameters instead. 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 are going 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)


INTEGER. This is an INOUT parameter. If your deployment does not use file-based downloads, this parameter can be ignored. The default is 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


VARCHAR(128). The MobiLink user name.



VARCHAR(128). The name of the publication.



TIMESTAMP. The time of the last successful upload of this publication.



TIMESTAMP. The last download time for the publication.



VARCHAR(128). The remote subscription ID.


s.script_version VARCHAR(128). Optional IN parameter to specify that the MobiLink server passes the script version string used for the current synchronization to this parameter. Question marks cannot be used to specify this parameter. Not applicable
Default action

The default generation number is 1. If no script is defined for this event, the generation number sent to the remote database is always 1.


This event lets you design synchronization logic based on the publications currently being synchronized. This event is invoked in the same transaction as the begin_synchronization event, and is invoked after the begin_synchronization event. It is invoked once per publication being synchronized.

One potential use for this event is to affect what is downloaded based on the publication used. For example, consider a table that is part of both a priority publication (PriorityPub) and a publication for all tables (AllTablesPub). A script for the begin_publication event could store the publication names in a Java class or a SQL variable or package. Download scripts could then behave differently based on whether the publication being synchronized is PriorityPub or AllTablesPub.

If an UltraLite remote database is synchronizing with UL_SYNC_ALL, this event is invoked once with the publication name 'unknown'.

Generation number

The generation_number parameter is specifically for file-based downloads. The output value of the generation number is passed from the begin_publication script to the end_publication script. The meaning of the generation_number depends on whether the current synchronization is being used to create a download file, or whether the current synchronization has an upload.

In file-based downloads, changes to generation numbers are used to force an upload before the download. While generation numbers remain unchanged, remote databases can process many file-based downloads without requiring an upload. The number is stored in the download file. During a synchronization that has an upload, one generation number is output for every subscription to a publication. They are sent to the remote database in the upload acknowledgement, and stored in SYSSYNC.generation_number.

SQL example

You may want to record the information for each publication being synchronized. The following example calls ml_add_connection_script to assign the event to a stored procedure called RecordPubSync.

CALL ml_add_connection_script(
 '{CALL RecordPubSync( 
    {ml s.generation_number}, 
    {ml s.username}, 
    {ml s.publication_name}, 
    {ml s.last_publication_upload}, 
    {ml s.last_publication_download}, 
    {ml s.subscription_id} )}' );
Java example

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

CALL ml_add_java_connection_script( 
 'ExamplePackage.ExampleClass.beginPublication' )

The following is the sample Java method beginPublication. It saves the name of each publication for later use.

package ExamplePackage; 
public class ExampleClass
    java.util.ArrayList<String> _publicationNames;
    int				_numPublications = 0;

    public void beginPublication(	generation_number,
				  String				user,
				  String				pub_name ) 
	_publicationNames.add( pub_name );
.NET example

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

CALL ml_add_dnet_connection_script( 

The following is the sample .NET method BeginPub. It saves the name of each publication for later use.

using System.Collections.Generic;
namespace TestScripts
    class Test
	List<string>	_publicationNames = new List<string>();
	int		_numPublications  = 0;

	public void BeginPub( ref int	generation_number,
			      string	user,
			      string	pub_name ) 
	    _publicationNames.Add( pub_name );