Processes statements related to a specific table just after the MobiLink server concludes processing of uploaded inserts, updates, and deletions.
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 | 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. |
1 |
s.table |
VARCHAR(128). The table name. |
2 |
None.
The MobiLink server executes this script as the last step in the processing of uploaded information. Upload information is processed in a separate transaction. The execution of this script is the last table-specific action in this transaction.
You can have one end_upload script for each table in the remote database.
The following call to a MobiLink system procedure assigns the end_upload event to a stored procedure called ULCustomerIDPool_maintain.
CALL ml_add_table_script( 'custdb', 'ULCustomerIDPool', 'end_upload', '{ CALL ULCustomerIDPool_maintain( {ml s.username} ) }' ) |
The following SQL statements create the ULCustomerIDPool_maintain stored procedure. This procedure inserts new primary keys, to replace the keys used by the rows just uploaded, into a primary key pool that gets downloaded to the remote database later in the same synchronization.
CREATE PROCEDURE ULCustomerIDPool_maintain ( IN syncuser_id INTEGER ) BEGIN DECLARE pool_count INTEGER; -- Determine how many ids to add to the pool SELECT COUNT(*) INTO pool_count FROM ULCustomerIDPool WHERE pool_emp_id = syncuser_id; -- Top up the pool with new ids WHILE pool_count < 20 LOOP INSERT INTO ULCustomerIDPool ( pool_emp_id ) VALUES ( syncuser_id ); SET pool_count = pool_count + 1; END LOOP; END |
The following call to a MobiLink system procedure registers a Java method called endUploadTable as the script for the end_upload table event when synchronizing the script version ver1.
CALL ml_add_java_table_script( 'ver1', 'table1', 'end_upload', 'ExamplePackage.ExampleClass.endUploadTable' ) |
The following is the sample Java method endUploadTable. It generates a delete for a table with a name related to the passed-in table name. This syntax is for SQL Anywhere consolidated databases.
package ExamplePackage; public class ExampleClass { String _curUser = null; public String endUploadTable( String user, String table ) { return( "DELETE from '" + table + "_temp'" ); }} |
The following call to a MobiLink system procedure registers a .NET method called EndUpload as the script for the end_upload table event when synchronizing the script version ver1 and the table table1.
CALL ml_add_dnet_table_script( 'ver1', 'table1', 'end_upload', 'TestScripts.Test.EndUpload' ) |
The following .NET example moves rows inserted into a temporary table into the table passed into the script.
using iAnywhere.MobiLink.Script; namespace TestScripts { public class Test { DBConnection _curConn = null; public Test( DBConnectionContext cc ) { _curConn = cc.GetConnection(); } public void EndUpload( string user, string table ) { DBCommand stmt = _curConn.CreateCommand(); // Move the uploaded rows to the destination table. stmt.CommandText = "INSERT INTO " + table + " SELECT * FROM dnet_ul_temp"; stmt.ExecuteNonQuery(); stmt.Close(); } } } |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |