在 MobiLink 同步服务器处理完上载的插入、更新和删除操作的流之后立即处理与特定表有关的语句。
在下表中,[说明] 部分提供 SQL 数据类型。如果您使用 Java 或 .NET 编写脚本,则应该使用相应的数据类型。请参见 SQL-Java 数据类型和 SQL-.NET 数据类型。
只有当未指定任何后续参数时,事件参数才是可选的。如果要使用参数 2,您必须使用参数 1。
| 项 | 参数 | 说明 |
|---|---|---|
| 1 | ml_username | VARCHAR(128) |
| 2 | table | VARCHAR(128) |
无。
MobiLink 同步服务器执行该脚本是对上载的信息进行处理的最后一步。上载信息是在单独的一个事务中进行处理的。该脚本的执行是该事务中最后一步表特定的操作。
您可以为远程数据库的每个表编写一个 end_upload 脚本。
下面的语句定义一个存储过程和一个 end_upload 脚本。代码中的第一部分将调用 ml_add_table_script,第二部分创建 ULCustomerIDPool_maintain 过程。
ml_add_table_script( 'custdb', 'ULCustomerIDPool', 'end_upload', ULCustomerIDPool_maintain( ? );) CREATE OR REPLACE PROCEDURE ULCustomerIDPool_maintain( SyncUserID IN integer ) AS pool_count INTEGER; pool_max INTEGER; BEGIN -- Determine how many ids to add to the pool
SELECT COUNT(*)
INTO pool_count
FROM ULCustomerIDPool
WHERE pool_emp_id = SyncUserID;
-- Determine the current Customer id max
SELECT MAX(pool_cust_id)
INTO pool_max
FROM ULCustomerIDPool;
-- Top up the pool with new ids
WHILE pool_count < 20 LOOP
pool_max := pool_max + 1;
INSERT INTO ULCustomerIDPool(
pool_cust_id, pool_emp_id )
VALUES ( pool_max, SyncUserID );
pool_count := pool_count + 1;
END LOOP;
END;下面的存储过程调用在同步脚本版本 ver1 时将名为 endUploadTable 的 Java 方法注册为 end_upload 表事件的脚本。
call ml_add_java_table_script( 'ver1', 'table1' 'end_upload', 'ExamplePackage.ExampleClass.endUploadTable' )
下面是示例 Java 方法 endUploadTable。它为表生成一个删除操作,该表的名称与传入的表名相关。此语法用于 Adaptive Server Anywhere 统一数据库。
public String endUploadTable( String user,
String table)
{ return( "DELETE from '" + table + "_temp'" ); }下面的存储过程调用在同步脚本版本 ver1 和表 table1 时将名为 EndTableUpload 的 .NET 方法注册为 end_upload 表事件的脚本。
call ml_add_dnet_table_script( 'ver1', 'table1', 'end_upload', 'TestScripts.Test.EndTableUpload' )
下面是调用 EndTableUpload 的 C# 签名。
public void EndTableUpload( string user, string table )
下面的 C# 示例将插入临时表的行移动到传入脚本的表中。
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();
}SQL Anywhere Studio 9.0.2
版权所有 © 1989–2005 Sybase, Inc. 部分版权所有 © 2001–2005 iAnywhere Solutions, Inc. 保留所有权利。