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

resolve_conflict table event

Defines a process for resolving a conflict in a specific table.


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)
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 table name.


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



When a row is updated on a remote database, the MobiLink client saves a copy of the original values. The client sends both old and new values to the MobiLink server.

When the MobiLink server receives an updated row, it compares the original values with the present values in the consolidated database. The comparison is done using the upload_fetch script.

If the old uploaded values do not match the current values in the consolidated database, the row conflicts. Instead of updating the row, the MobiLink server inserts both old and new values into the consolidated database. The old and new rows are handled using the upload_old_row_insert and upload_new_row_insert scripts, respectively.

Once the values have been inserted, the MobiLink server executes the resolve_conflict script. It provides the opportunity to resolve the conflict. You can implement any scheme of your choosing.

This script is executed once per conflict.

Alternatively, instead of defining the resolve_conflict script, you can resolve conflicts in a set-oriented fashion by putting conflict-resolution logic either in your end_upload_rows script or in your end_upload table script.

You can have one resolve_conflict script for each table in the remote database.

SQL example

The following statement defines a resolve_conflict script suited to the CustDB sample application for an Oracle installation. It calls a stored procedure ULResolveOrderConflict.

exec ml_add_table_script(
   'custdb', 'ULOrder', 'resolve_conflict',
   'begin ULResolveOrderConflict();
end; ') 
  new_order_id integer;
  new_status   varchar(20);
  new_notes   varchar(50);
  -- approval overrides denial
  SELECT order_id, status, notes
    INTO new_order_id, new_status, new_notes
    FROM ULNewOrder
   WHERE syncuser_id = SyncUserID;
  IF new_status = 'Approved' THEN
    UPDATE ULOrder o
       SET o.status = new_status, o.notes = 
     WHERE o.order_id = new_order_id;
Java example

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

CALL ml_add_java_table_script(
   'ExamplePackage.ExampleClass.resolveConflict' )

The following is the sample Java method resolveConflict. It calls a Java method that uses the JDBC connection provided by MobiLink to resolve the conflict.

package ExamplePackage;
import java.sql.*;
public class ExampleClass
    DBConnectionContext _cc;
    public ExampleClass( DBConnectionContext cc ) 
	_cc = cc;

    public void resolveConflict( String user,
				 String table )
	throws java.sql.SQLException 
	if( table == "Order" ) {
	    // Insert error information in a table,
	    Connection	conn   = _cc.getConnection();
	    String conflictTable = "New" + table;
	    PreparedStatement stmt = conn.prepareStatement( 
		"SELECT order_id, new_status, new_notes " +
		"FROM " + conflictTable +
		"WHERE rid = " + _cc.getRemoteID() );
	    ResultSet rs = stmt.executeQuery();
	    PreparedStatement updt = conn.prepareStatement(
		"UPDATE ULOrder SET status = ?, notes = ? WHERE order_id = ?" );

	    while( ) {
		if( rs.getString( 2 ) == "Approved" ) {
		    updt.setString( 1, rs.getString( 2 ) );
		    updt.setString( 2, rs.getString( 3 ) );
		    updt.setInt( 3, rs.getInt( 1 ) );
.NET example

The following call to a MobiLink system procedure registers a .NET method called ResolveConflict as the script for the resolve_conflict table event when synchronizing the script version ver1.

CALL ml_add_dnet_table_script(
   'TestScripts.Test.ResolveConflict' )

The following is the sample .NET method ResolveConflict. It calls a .NET method that resolves the conflict.

using System;
using Sap.MobiLink.Script;
namespace TestScripts
    public class Test
	DBConnectionContext _cc;

	public Test( DBConnectionContext cc )
	    _cc = cc;
	public void ResolveConflict( string user,
				     string table )
	    if( table == "Order" ) {
		// Insert error information in a table,
		DBConnection	conn   = _cc.GetConnection();
		String conflictTable = "New" + table;
		DBCommand cmd = conn.CreateCommand();
		cmd.CommandText = 
			"SELECT order_id, new_status, new_notes " +
			"FROM " + conflictTable +
			"WHERE rid = " + _cc.GetRemoteID();
		DBRowReader dr = cmd.ExecuteReader();
		DBCommand updt = conn.CreateCommand();
		updt.CommandText =
			"UPDATE ULOrder SET status = ?, notes = ? WHERE order_id = ?";
		object[] row;
		while( (row = dr.NextRow() ) != null ) {
		    if( row.[1].Equals( "Approved" ) ) {
			updt.Parameters[0] = row[1];
			updt.Parameters[1] = row[2];
			updt.Parameters[2] = row[0];