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 服务器技术 » 同步技术

 

基于时间戳的下载

时间戳方法是进行高效同步的最实用的通用技术。此方法将跟踪每个用户上次同步的时间并仅下载在该时刻后更改的行。

MobiLink 维持一个时间戳值,用来指示每个 MobiLink 用户上次下载数据的时间。此值被称为上次下载时间

请参见在脚本中使用上次下载时间

♦  实现表的基于时间戳的同步
  1. 在统一数据库中,添加一列以保存行的最近修改时间。通常可以按照如下方式声明该列:

    DBMS 最近修改的列
    Adaptive Server Enterprise datetime
    IBM DB2 LUW timestamp
    IBM DB2 主机 timestamp
    Microsoft SQL Server datetime
    MySQL timestamp
    Oracle date
    SQL Anywhere timestamp DEFAULT timestamp
  2. 在 download_cursor 和 download_delete_cursor 事件的脚本中,将第一个参数与时间戳列中的值进行比较。

示例

如下表声明及脚本将实现 Contact 示例中 Customer 表的基于时间戳的同步:

  • 表定义:

    CREATE TABLE "DBA"."Customer"(
       "cust_id"  integer NOT NULL DEFAULT GLOBAL AUTOINCREMENT,
       "name"  char(40) NOT NULL,
       "rep_id"  integer NOT NULL,
       "last_modified" timestamp NULL DEFAULT timestamp,
       "active"  bit NOT NULL,
       PRIMARY KEY ("cust_id") )
  • download_delete_cursor 脚本:

    SELECT cust_id
    FROM Customer JOIN SalesRep
    ON Customer.rep_id = SalesRep.rep_id
    WHERE Customer.last_modified >= {ml s.last_table_download}
        AND ( SalesRep.ml_username != {ml s.username}
              OR Customer.active = 0 )
  • download_cursor 脚本:

    SELECT cust_id, Customer.name, Customer.rep_id
    FROM Customer KEY JOIN SalesRep
    WHERE Customer.last_modified >= {ml s.last_table_download}
        AND SalesRep.ml_username = {ml s.username}
        AND Customer.active = 1

请参见同步逻辑源代码同步 Contact 示例中的联系人


在脚本中使用上次下载时间
处理 daylight savings time