upload_new_row_insert table event

Conflict resolution scripts for statement-based uploads commonly require access to the old and new values of rows uploaded from the remote database. This event allows you to handle the new, updated values of rows uploaded from 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.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. This parameter is optional.

Optional

r.pk-column-1

A column value from the old (pre-image) row, where the named parameter is specified as a column name prefaced by r.

1 (2 if username is referenced)

... ...

r.pk-column-N

A column value from the old (pre-image) row, where the named parameter is specified as a column name prefaced by r.

N (N+1 if username is referenced)

r.column-1

A column value from the old (pre-image) row, where the named parameter is specified as a column name prefaced by r.

N + 1 (N+2 if username is referenced)
... ... ...
r.column-M

A column value from the old (pre-image) row, where the named parameter is specified as a column name prefaced by r.

N + M (N+M+1 if username is referenced)
Default action

None.

Remarks

When a MobiLink client sends an updated row to the MobiLink server, it includes not only the new values (the post-image), but also a copy of the old row values (the pre-image). When the pre-image does not match the current values in the consolidated database, a conflict is detected.

This event allows you to save post-image values to a table. You can use this event to assist in developing conflict resolution procedures for statement-based updates. The parameters for this event hold new row values from the remote database before the update is performed on the corresponding consolidated database table. This event is also used to insert rows in statement-based, forced-conflict mode.

The script for this event is usually an insert statement that inserts the new row into a temporary table for use by a resolve_conflict script.

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

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

See also
SQL example

This example handles updates made on the product table in the remote database. The script inserts the new value of the row into a global temporary table named product_conflict. The final column of the table identifies the row as a new row.

CALL ml_add_table_script(
 'ver1',
 'table1',
 'upload_new_row_insert',
 'INSERT INTO DBA.product_conflict(
   id, 
   name, 
   size, 
   quantity, 
   unit_price, 
   row_type )
  VALUES( 
   {ml r.id}, 
   {ml r.name}, 
   {ml r.size}, 
   {ml r.quantity}, 
   {ml r.unit_price}, 
   ''New'' )' )
Java example

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

CALL ml_add_java_table_script(
  'ver1',
  'table1',
  'upload_new_row_insert',
  'ExamplePackage.ExampleClass.uploadNewRowInsertTable'
)

Following is the sample Java method uploadNewRowInsertTable. It dynamically generates an INSERT statement. This syntax is for SQL Anywhere consolidated databases.

public String uploadNewRowInsertTable() {
  return("insert into" + _curTable + "_new" +
    getCols(_curTable) + "values" + getNamedParams(_curTable)); 
}
.NET example

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

CALL ml_add_dnet_table_script(
  'ver1',
  'table1',
  'upload_new_row_insert',
  'TestScripts.Test.UploadNewRowInsertTable'
)

Following is the sample .NET method UploadNewRowInsertTable. It dynamically generates an INSERT statement. This syntax is for SQL Anywhere consolidated databases.

public string UploadNewRowInsertTable() {
  return("insert into" + _curTable + "_new" +
    GetCols(_curTable) + "values" + GetNamedParams(_curTable)); 
}