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

SQL Anywhere 12.0.1 » MobiLink - 服务器管理 » MobiLink 服务器技术 » 同步技术 » 冲突处理 » 冲突解决

 

通过 upload_update 脚本解决冲突

解决冲突时,您可以调用 upload_update 脚本中的存储过程而不是使用 resolve_conflict 脚本。使用此技术时,必须以编程方式检测并解决冲突。

存储过程必须接受所有列,包括新(后映像)值和旧(前映像)值。

upload_update 脚本可能如下所示:

{CALL UpdateProduct(
   {ml o.id}, {ml o.name}, {ml o.desc}, {ml r.name}, {ml r.desc}
)
}

UpdateProduct 存储过程可能是:



CREATE PROCEDURE UpdateProduct( 
  @id INTEGER,
  @preName VARCHAR(20), 
  @preDesc VARCHAR(200),
  @postName VARCHAR(20), 
  @postDesc VARCHAR(200) ) 
BEGIN
    UPDATE product
     SET name = @postName, description = @postDesc
     WHERE id = @id
       AND name = @preName
       AND description = @preDesc
    IF @@rowcount=0 THEN
        // A conflict occurred: handle resolution here.
    END IF
END

与使用 resolve_conflict 脚本解决冲突相比,此方法更易于维护,因为只有一个脚本需要维护,所有逻辑都包含在一个存储过程中。但是,如果表列可以为空,或其中包含 BLOB 或 CLOB,存储过程的代码可能会非常复杂。此外,对于一些受 MobiLink 统一数据库支持的 RDBMS,它们可以传递到存储过程的值有大小限制。

 另请参见
 示例