Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 服务器管理 » MobiLink 事件 » 编写同步脚本 » 脚本参数

 

用户定义的命名参数

您也可以定义自己的参数。这些参数对于不允许使用用户定义变量的 RDBMS 特别有用。

用户定义的参数在首次引用时定义(并设置为空)。它们必须以 ui 和一个句点 (ui.) 开头。用户定义的参数的持续时间与一个同步的时间相同—每个同步启动时该参数都会设置为空。用户定义的参数是输入/输出参数。

对用户定义参数的典型应用是,在不必将状态信息存储到表中的情况下访问状态信息(可能需要复杂连接)。

示例

例如,假定您创建一个名为 MyCustomProc 的存储过程,该过程将名为 var1 的变量设置为 custom_value:

CREATE PROCEDURE MyCustomProc(
  IN username VARCHAR (128), INOUT var1 VARCHAR (128)
)
begin
 SET var1 = 'custom_value';
end

以下 begin_connection 脚本定义用户定义的参数 var1,并将其值设为 custom_value:

CALL ml_add_connection_script ( 
  'version1', 
  'begin_synchronization', 
  '{call MyCustomProc( {ml s.username}, {ml ui.var1} )}' );

以下 begin_upload 脚本引用 var1,其值为 custom_value:

CALL ml_add_connection_script ( 
  'version1', 
  'begin_upload', 
  'update SomeTable set some_column = 123 where some_other_column = {ml ui.var1}' );

假定您另有一个名为 MyPFDProc 的存储过程,该过程将其第一个参数定义为输入/输出参数。以下 prepare_for_download 脚本将 var1 的值更改为 pfd_value:

CALL ml_add_connection_script ( 
  'version1', 
  'prepare_for_download', 
  '{call MyPFDProc( {ml ui.var1} )}' );

以下 begin_download 脚本引用 var1,其值现在是 pfd_value:

CALL ml_add_connection_script ( 
  'version1', 
  'begin_download', 
  'insert into SomeTable values( {ml s.username}, {ml ui.var1} )' );