Use this stored procedure to control when synchronization takes place.
Name | Value | Description |
---|---|---|
delay duration (in|out) |
number of seconds |
If the procedure sets the delay duration value to zero, then dbmlsync synchronization proceeds immediately. A non-zero delay duration value specifies the number of seconds before the delay hook is called again. |
maximum accumulated delay (in|out) |
number of seconds |
The maximum accumulated delay specifies the maximum number of seconds delay before each synchronization. Dbmlsync keeps track of the total delay created by all calls to the delay hook since the last synchronization. If no synchronization has occurred since dbmlsync started running, the total delay is calculated from the time dbmlsync started up. When the total delay exceeds the value of maximum accumulated delay, synchronization begins without any further calls to the delay hook. |
publication_n (in) |
publication |
Deprecated. Use subscription_n instead. The publications being synchronized, where n is an integer. There is one publication_n entry for each publication being synchronized. The numbering of n starts at zero. |
MobiLink user ( in ) |
MobiLink user name |
The MobiLink user for which you are synchronizing. |
script version (in) |
script version name |
The MobiLink script version to be used for the synchronization. |
subscription_n (in) | subscription name(s) | The names of subscriptions being synchronized where n is an integer. This is one subscription_n entry for each subscription being synchronized. The numbering of n starts at zero. |
If a procedure of this name exists, it is called before sp_hook_dbmlsync_begin at the beginning of the synchronization process.
This hook is not called when synchronization is initiated using the Dbmlsync API or the SQL SYNCHRONIZE statement.
Actions of this procedure are committed immediately after execution.
Assume you have the following table to log orders on the remote database.
CREATE TABLE OrdersTable( "id" INTEGER PRIMARY KEY DEFAULT AUTOINCREMENT, "priority" VARCHAR(128) ); |
The following example delays synchronization for a maximum accumulated delay of one hour. Every ten seconds the hook is called again and checks for a high priority row in the OrdersTable. If a high priority row exists, the delay duration is set to zero to start the synchronization process.
CREATE PROCEDURE sp_hook_dbmlsync_delay() BEGIN -- Set the maximum delay between synchronizations -- or before the first synchronization starts to 1 hour UPDATE #hook_dict SET value = '3600' // 3600 seconds WHERE name = 'maximum accumulated delay'; -- check if a high priority order exists in OrdersTable IF EXISTS (SELECT * FROM OrdersTable where priority='high') THEN -- start the synchronization to process the high priority row UPDATE #hook_dict SET value = '0' WHERE name='delay duration'; ELSE -- set the delay duration to call this procedure again -- following a 10 second delay UPDATE #hook_dict SET value = '10' WHERE name='delay duration'; END IF; END; |
In the sp_hook_dbmlsync_end hook you can mark the high priority row as processed:
CREATE PROCEDURE sp_hook_dbmlsync_upload_end() BEGIN IF EXISTS( SELECT value FROM #hook_dict WHERE name = 'Upload status' AND value = 'committed' ) THEN UPDATE OrderTable SET priority = 'high-processed' WHERE priority = 'high'; END IF; END; |
This example assumes that you have used LockTables extended option to ensure that the tables are locked during synchronization. If the tables are not locked, it is possible for a high priority row to be inserted after the upload is built but before the sp_hook_dbmlsync_end hook is executed. If that happened the row's priority would be changed to "high-processed" even though it was never uploaded.
See sp_hook_dbmlsync_end.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |