大多数同步脚本可以接收来自 MobiLink 服务器的参数。有关可在每个脚本中使用的参数的详细信息,请参见同步事件。
可以采用以下两种方式之一在您的 SQL 脚本中指定参数:
命名的脚本参数
问号(在 SQL 脚本中不建议使用)
命名参数相对于问号(不建议使用)具有以下优点:
命名参数允许您以任意顺序指定可用参数的任何子集。
除了输入/输出参数以外,您可以在一个脚本内多次指定相同的命名参数。
如果使用命名参数,则可以在脚本中指定远程 ID。这是在脚本中指定远程 ID 的唯一方法。
您可以创建自己的命名参数。请参见用户定义的命名参数。
在一个脚本中不能混合使用命名参数和问号。
MobiLink 命名参数的类型共有四种。要指定命名参数,必须将其类型作为前缀,如下所示:
命名参数的类型 | 前缀 | 示例 |
---|---|---|
系统参数。 | s. | {ml s.remote_id} |
行参数。(列名。如果列包含空格,则用双引号或方括号将其括起来。) | r. |
{ml r.cust_id} {ml r."Column name"} |
旧的行参数。(仅用于 upload_update 脚本之中,以指定前映像列值。如果列名包含空格,则用双引号或方括号将其括起来。) | o. |
{ml o.cust_name} {ml o."Column name"} |
验证参数。请参见验证参数。 | a. | {ml a.1} |
用户定义的参数。请参见用户定义的命名参数。 | u. 或 ui. |
|
要按名称引用脚本参数,应将该参数括在大括号内,并在前面加上 ml 前缀,如 {ml parameter }。例如,{ml s.action_code}。大括号表示是一种 ODBC 约定。
为方便起见,可以在大括号中包含更长的代码,只要这部分代码不包含与 MobiLink 脚本参数名称相同的任何模式名称即可。例如,以下每个 upload_insert 脚本均有效且等效:
INSERT INTO t ( id, c0 ) VALUES( {ml r.id}, {ml r.c0} ) |
和
INSERT INTO t ( is, c0 ) VALUES({ml r.id, r.c0}) |
和
{ml INSERT INTO t ( id, c0 ) VALUES( r.id, r.c0 ) } |
要使用命名行参数,您可能需要使用 ml_add_column 系统过程在统一数据库中存储列信息,尽管大多数使用版本 12 的同步客户端的部署不需要此项。请参见ml_add_column 系统过程。
用问号表示参数是一种 ODBC 约定。要在您的 MobiLink SQL 脚本中使用问号,请在脚本中为每个参数放置一个问号。MobiLink 服务器将用一个参数的值替换每个问号。它将按照参数在脚本定义中出现的顺序来替换这些值。
参数必须为同步事件中指定的顺序。有些参数是可选的。只有在未指定任何后续参数时,参数才是可选的。例如,如果要使用参数 2,则必须使用参数 1。
支持以下几种格式的注释:
双连字符前缀 (--)
双正斜线前缀 (//)
块注释 (/* */)
前两种格式可使系统忽略行末之前的脚本文本。第三种格式可使 /* 前缀和 */ 后缀之间的所有脚本文本都被忽略。块注释不能嵌套。
任何其它类型的服务商特定注释都无法识别,因此不应将其用于注释对命名参数的引用。
系统参数 | 事件类型 | 事件参数在以下各项中可用 |
---|---|---|
action_code |
connection |
action_code 参数在以下事件中可用:
|
authentication_status |
connection |
authentication_status 参数在以下事件中可用:
|
bytes |
connection 和 table |
bytes 参数在以下事件中可用:
|
conflicted_deletes |
connection 和 table |
conflicted_deletes 参数在以下事件中可用:
|
conflicted_inserts |
connection 和 table |
conflicted_inserts 参数在以下事件中可用:
|
conflicted_updates |
connection 和 table |
conflicted_updates 参数在以下事件中可用:
|
connection_retries |
connection |
conflicted_retries 参数在以下事件中可用:
|
deadlocks |
connection 和 table |
deadlocks 参数在以下事件中可用:
|
deleted_rows |
connection 和 table |
deleted_rows 参数在以下事件中可用:
|
error_code |
connection |
error_code 参数在以下事件中可用:
|
error_message |
connection |
error_message 参数在以下事件中可用:
|
errors |
connection 和 table |
errors 参数在以下事件中可用:
|
event_name |
connection 和 table |
event_name 参数在以下事件中可用:
|
fetched_rows |
connection 和 table |
fetched_rows 参数在以下事件中可用:
|
file_authentication_code |
connection |
file_authentication_code 参数在以下事件中可用:
|
filename |
connection |
filename 参数在以下事件中可用:
|
file_size |
connection |
file_size 参数在以下事件中可用:
|
filtered_rows |
connection 和 table |
filtered_rows 参数在以下事件中可用:
|
generation_number |
connection |
filtered_rows 参数在以下事件中可用:
|
hashed_new_password |
connection |
hashed_new_password 参数在以下事件中可用:
|
hashed_password |
connection |
hashed_password 参数在以下事件中可用:
|
ignored_deletes |
connection 和 table |
ignored_deletes 参数在以下事件中可用:
|
ignored_inserts |
connection 和 table |
ignored_inserts 参数在以下事件中可用:
|
ignored_updates |
connection 和 table |
ignored_updates 参数在以下事件中可用:
|
inserted_rows |
connection 和 table |
inserted_rows 参数在以下事件中可用:
|
last_download |
connection |
last_download 参数在以下事件中可用:
|
last_publication_download |
connection |
last_publication_download 参数在以下事件中可用:
|
last_publication_upload |
connection |
last_publication_upload 参数在以下事件中可用:
|
last_table_download |
table |
last_table_download 参数在以下事件中可用:
|
maximum_time |
connection 和 table |
maximum_time 参数在以下事件中可用:
|
minimum_time |
connection 和 table |
minimum_time 参数在以下事件中可用:
|
new_password |
connection |
new_password 参数在以下事件中可用:
|
next_last_download |
connection |
next_last_download 参数在以下事件中可用:
|
number_of_calls |
connection 和 table |
number_of_calls 参数在以下事件中可用:
|
odbc_state |
connection |
odbc_state 参数在以下事件中可用:
|
password |
connection |
password 参数在以下事件中可用:
|
publication_name |
connection |
publication_name 参数在以下事件中可用:
|
remote_id |
connection 和 table |
remote_id 参数在以下事件中可用:
|
remote_key |
connection |
remote_key 参数在以下事件中可用:
|
subdir |
connection |
subdir 参数在以下事件中可用:
|
subscription_id |
connection |
subscription_id 参数在以下事件中可用:
|
synchronization_ok |
connection 和 table |
synchronization_ok 参数在以下事件中可用:
|
synchronized_tables |
connection |
synchronized_tables 参数在以下事件中可用:
|
table |
connection 和 table |
table 参数在以下事件中可用:
|
total_time |
connection 和 table |
total_time 参数在以下事件中可用:
|
updated_rows |
connection 和 table |
updated_rows 参数在以下事件中可用:
|
username |
connection 和 table |
username 参数在以下事件中可用:
|
warnings |
connection 和 table |
warnings 参数在以下事件中可用:
|
![]() |
使用DocCommentXchange 讨论此页。
|
版权 © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |