modify_user connection event

Provide the MobiLink user name.

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.

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 is an INOUT parameter.

1

Default action

None.

Remarks

The MobiLink server provides the user name as a parameter when it calls scripts; the user name is sent by the MobiLink client. In some cases, you may want to have an alternate user name. This script allows you to modify the user name used in calling MobiLink scripts.

The username parameter must be long enough to hold the user name.

SQL scripts for the modify_user event must be implemented as stored procedures.

See also
SQL example

The following example maps a remote database user name to the ID of the user using the device, by using a mapping table called user_device. This technique can be used when the same person has multiple remotes (such as a PDA and a laptop) requiring the same synchronization logic (based on the user's name or id).

The following call to a MobiLink system procedure assigns the ModifyUser stored procedure to the modify_user event. This syntax is for a SQL Anywhere consolidated database.

CALL ml_add_connection_script(
 'ver1',
 'modify_user',
 'call ModifyUser( {ml s.username} )' )

The following SQL statement creates the ModifyUser stored procedure.

CREATE PROCEDURE ModifyUser( INOUT u_name varchar(128) )
BEGIN
 SELECT user_name
    INTO u_name
    FROM user_device
    WHERE device_name = u_name;
END
Java example

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

CALL ml_add_java_connection_script(
   'ver1',
   'modify_user',
   'ExamplePackage.ExampleClass.modifyUser' )

The following is the sample Java method modifyUser. It gets the user ID from the database and then uses it to set the user name.

public String modifyUser( 
  InOutString ioUserName )
  throws SQLException {
  Statement uidSelect = curConn.createStatement();
  ResultSet uidResult = uidSelect.executeQuery(
   "SELECT rep_id FROM SalesRep WHERE name = '" +
   ioUserName.getValue() + "' " );
  uidResult.next();
  ioUserName.setValue(
   java.lang.Integer.toString(uidResult.getInt( 1 ));
   uidResult.close();
   uidSelect.close();
  return ( null );
}
.NET example

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

CALL ml_add_dnet_connection_script(
  'ver1',
  'modify_user',
  'TestScripts.Test.ModUser'
)

The following is the sample .NET method ModUser.

public string ModUser( 
  string user ) {
  return ( "SELECT rep_id FROM SalesRep WHERE name = '" + user + "' " );
}