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 服务器技术 » 同步技术 » 在远程数据库之间对行进行分区

 

有交集分区

统一数据库中的一些表中可能包含属于多个远程数据库的行。每个远程数据库都拥有一个统一数据库中的行的子集,并且该子集与其它远程数据库之间存在交集。客户表便是这种情况。这时,该表与远程数据库之间存在多对多的关系,而且通常具有一个描述这种关系的表格。download_cursor 和 download_delete_cursor 事件的脚本需要将正在下载的表连接到关系表。

示例

CustDB 示例应用程序在 ULOrder 表中使用此技术。ULEmpCust 表保存 ULCustomer 和 ULEmployee 之间的多对多关系的信息。

每个远程数据库只从 ULOrder 表中接收那些其 emp_id 列与 MobiLink 用户名相匹配的行。

在 CustDB 应用程序中,用于 ULOrder 的 download_cursor 脚本的 SQL Anywhere 版本如下:

SELECT o.order_id, o.cust_id, o.prod_id,
   o.emp_id, o.disc, o.quant, o.notes, o.status
FROM ULOrder o , ULEmpCust ec
WHERE o.cust_id = ec.cust_id
 AND ec.emp_id = {ml s.username}
 AND ( o.last_modified >= {ml s.last_table_download}
  OR ec.last_modified >= {ml s.last_table_download})
 AND  ( o.status IS NULL
  OR o.status != 'Approved' )
 AND ( ec.action IS NULL )

此脚本相当复杂。它说明在远程数据库中定义了一个表的查询中可以包含统一数据库中的多个表。脚本将下载 ULOrder 中满足以下条件的所有行:

  • ULOrder 表中的 cust_id 列与 ULEmpCust 表中的 cust_id 列相匹配

  • ULEmpCust 表中的 emp_id 列与同步用户名相匹配

  • 订单或员工-客户关系的上次修改时间晚于此用户的最近同步的时间

  • 状态不是 Approved

ULEmpCust 上的操作列用于标记要删除的列。其目的与当前主题并不相关。

下面是 download_delete_cursor 脚本。

SELECT o.order_id
FROM ULOrder o, ULEmpCust ec
WHERE o.cust_id = ec.cust_id
  AND ec.emp_id = {ml s.username}
  AND ( o.last_modified >= {ml s.last_table_download} OR
        c.last_modified >= {ml s.last_table_download} )
  AND ( o.status IS NULL OR
        o.status != 'Approved' )
  AND ( ec.action IS NULL )

此脚本从远程数据库中删除所有已核准的行。