在 MobiLink 服务器处理完上载的插入、更新和删除操作的流之后立即处理与特定表有关的语句。
在下表中,说明部分提供 SQL 数据类型。如果您使用 Java 或 .NET 编写脚本,则应该使用相应的数据类型。请参见SQL-Java 数据类型和SQL-.NET 数据类型。
在 SQL 脚本中,可以使用名称或问号指定事件参数,但不能在一个脚本中混合使用名称和问号。如果使用问号,则参数必须按照如下所示的顺序并且仅当没有指定任何后继参数时才是可选的(例如,如果您想使用参数 2,则必须使用参数 1)。如果使用命名参数,则可以按照任何顺序指定任意参数子集。
参数 |
说明 |
顺序 |
---|---|---|
s.remote_id | VARCHAR(128)。MobiLink 远程 ID。只有在使用命名参数时才能引用远程 ID。 | 不适用 |
s.username |
VARCHAR(128)。MobiLink 用户名。 |
1 |
s.table |
VARCHAR(128)。表名。 |
2 |
无。
MobiLink 服务器执行此脚本是对上载的信息进行处理的最后一步。上载信息在单独的事务中进行处理。此脚本的执行是此事务中最后一步表特定的操作。
您可以为远程数据库的每个表编写一个 end_upload 脚本。
以下对 MobiLink 系统过程的调用将 end_upload 事件指派给名为 ULCustomerIDPool_maintain 的存储过程。
CALL ml_add_table_script( 'custdb', 'ULCustomerIDPool', 'end_upload', 'CALL ULCustomerIDPool_maintain( username );' ); |
以下 SQL 语句创建 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; |
以下对 MobiLink 系统过程的调用在同步脚本版本 ver1 时将名为 endUploadTable 的 Java 方法注册为 end_upload 表事件的脚本。
CALL ml_add_java_table_script( 'ver1', 'table1', 'end_upload', 'ExamplePackage.ExampleClass.endUploadTable' ) |
以下是 Java 方法 endUploadTable 示例。它为表生成一个删除操作,该表的名称与传入的表名相关。此语法用于 SQL Anywhere 统一数据库。
public String endUploadTable( String user, String table ) { return( "DELETE from '" + table + "_temp'" ); } |
以下对 MobiLink 系统过程的调用在同步脚本版本 ver1 和表 table1 时将名为 EndUpload 的 .NET 方法注册为 end_upload 表事件的脚本。
CALL ml_add_dnet_table_script( 'ver1', 'table1', 'end_upload', 'TestScripts.Test.EndUpload' ) |
以下 .NET 示例将插入临时表的行移动到传入脚本的表中。
public string 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(); return ( null ); } |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |