#hook_dict table

Immediately before a hook is called, dbmlsync creates the #hook_dict table in the remote database, using the following CREATE statement. The # before the table name means that the table is temporary.

CREATE TABLE #hook_dict(
name VARCHAR(128) NOT NULL UNIQUE,
value VARCHAR(10240) NOT NULL)

The dbmlsync utility uses the #hook_dict table to pass values to hook functions, and hook functions use the #hook_dict table to pass values back to dbmlsync.

Each hook receives parameter values. In some cases, you can modify the value to return a new value; others are read-only. Each row in the table contains the value for one parameter.

For example, for the following dbmlsync command line, when the sp_hook_dbmlsync_abort hook is called, the #hook_dict table contains the following rows:

dbmlsync -c 'dsn=MyDsn' -n pub1,pub2 -u MyUser

#hook_dict row

Value

publication_0

pub1

publication_1

pub2

MobiLink user

MyUser

Abort synchronization

false

Your abort hook can retrieve values from the #hook_dict table and use them to customize behavior. For example, to retrieve the MobiLink user you would use a SELECT statement like this:

SELECT value
FROM #hook_dict
WHERE name = 'MobiLink user'

In/out parameters can be updated by your hook to modify the behavior of dbmlsync. For example, your hook could instruct dbmlsync to abort synchronization by updating the abort synchronization row of the table using a statement like this:

UPDATE #hook_dict
SET value='true'
WHERE name='abort synchronization'

The description of each hook lists the rows in the #hook_dict table.

Examples

The following sample sp_hook_dbmlsync_delay procedure illustrates the use of the #hook_dict table to pass arguments. The procedure allows synchronization only outside a scheduled down time of the MobiLink system between 18:00 and 19:00.

CREATE PROCEDURE sp_hook_dbmlsync_delay()
BEGIN
   DECLARE delay_val integer;
 SET delay_val=DATEDIFF(
   second, CURRENT TIME, '19:00');
 IF (delay_val>0 AND
     delay_val<3600)
 THEN
 UPDATE #hook_dict SET value=delay_val
   WHERE name='delay duration';
 END IF;
END

The following procedure is executed in the remote database at the beginning of synchronization. It retrieves the current MobiLink user name (one of the parameters available for the sp_hook_dbmlsync_begin event), and displays it on the SQL Anywhere messages window.

CREATE PROCEDURE sp_hook_dbmlsync_begin()
BEGIN
   DECLARE syncdef VARCHAR(150);
   SELECT '>>>syncdef = ' || value INTO syncdef
      FROM #hook_dict
      WHERE name ='MobiLink user name';
   MESSAGE syncdef TYPE INFO TO CONSOLE;
END