Modify the MobiLink user name.
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. This is an INOUT parameter. |
1 |
None.
This script is invoked at the end of the authentication transaction.
The MobiLink server provides the user name as a parameter when it calls scripts; the user name is sent by the MobiLink client. Sometimes 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.
A more flexible approach to mapping the MobiLink user name is to use user-defined named parameters. See User-defined named parameters.
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 |
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 ); } |
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 + "' " ); } |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |