在本课中,您将在统一数据库中添加脚本,以实现 SQL 行处理和直接行处理。
上下文和注释
SQL 行处理可用于将远程数据与 MobiLink 统一数据库中的表同步。基于 SQL 的脚本可定义:
如何将从 MobiLink 客户端上载的数据应用到统一数据库。
应从统一数据库下载哪些数据。
在本课中,您将为以下基于 SQL 的上载和下载事件编写同步脚本:
upload_insert 此事件对插入客户端数据库的新订单如何应用到统一数据库进行定义。
download_cursor 此事件对应下载到远程客户端的订单进行定义。
download_delete_cursor 在使用非仅上载的同步脚本时,需要使用此事件。对于本教程,需将 MobiLink 服务器设置为忽略此事件。
使用直接行处理将特殊处理添加到基于 SQL 的同步系统中。在本课中,您将注册与 handle_UploadData、download_cursor 和 download_delete_cursor 事件对应的方法名。 在第 5 课:创建 Java 类进行 MobiLink 直接行处理中创建您自己的 Java 类。
如果您尚未建立连接,则在 Interactive SQL 中连接到统一数据库。
运行以下命令:
dbisql -c "DSN=mlxml_db" |
使用 ml_add_table_script 存储过程为 upload_insert、download_cursor 和 download_delete_cursor 事件添加基于 SQL 的表脚本。
在 Interactive SQL 中执行以下 SQL 语句。upload_insert 脚本将上载的 order_id、product_id、quantity 和 order_status 插入到 MobiLink 统一数据库。download_cursor 脚本使用基于时间戳的过滤将更新的行下载到远程客户端。
CALL ml_add_table_script( 'default', 'RemoteOrders', 'upload_insert', 'INSERT INTO RemoteOrders( order_id, product_id, quantity, order_status) VALUES( {ml r.order_id}, {ml r.product_id}, {ml r.quantity}, {ml r.order_status} )' ); CALL ml_add_table_script( 'default', 'RemoteOrders', 'download_cursor', 'SELECT order_id, product_id, quantity, order_status FROM RemoteOrders WHERE last_modified >= {ml s.last_table_download}'); CALL ml_add_table_script( 'default', 'RemoteOrders', 'download_delete_cursor', '--{ml_ignore}'); COMMIT; |
为 handle_UploadData 事件注册 Java 方法。
在 Interactive SQL 中执行以下 SQL 语句:
CALL ml_add_java_connection_script( 'default', 'handle_UploadData', 'MobiLinkOrders.GetUpload' ); |
Interactive SQL 将对 handle_UploadData 事件注册 GetUpload 方法。在后续课程中,将创建 GetUpload 方法,它可从 MobiLink 客户端数据库中的 OrderComments 表中检索插入的数据。
注册 download_cursor 和 download_delete_cursor 事件。
在 Interactive SQL 中执行以下 SQL 语句:
CALL ml_add_table_script( 'default', 'OrderComments', 'download_cursor', '--{ml_ignore}'); CALL ml_add_table_script( 'default', 'OrderComments', 'download_delete_cursor', '--{ml_ignore}'); |
使用脚本时,download_cursor 和 download_delete_cursor 事件必须进行注册才能用于 OrderComments 表,因为同步是双向同步,而不是仅上载同步。 请参见必需的脚本。
提交所做的更改。
在 Interactive SQL 中执行以下 SQL 语句:
COMMIT; |
关闭 Interactive SQL。
![]() |
使用DocCommentXchange讨论此页。
|
版权 © 2013, SAP 股份公司或其关联公司. - SAP Sybase SQL Anywhere 16.0 |