Table events

Many of the connection events that occur between the begin_synchronization and end_synchronization events, such as begin_download and end_upload, also have table equivalents. These and other overall table events might be used for tasks such as creating an intermediate table to hold changes or printing information to a log file.

You can also script table events that apply to each row in the table. For row-level events, the order of the columns in your scripts must match the order in which they appear in the CREATE TABLE statement in the remote database, and the column names in the scripts must refer to the column names in the consolidated database.

Generating default scripts

Although there are several row-level events, most tables need scripts for three upload events (for INSERT, UPDATE, and DELETE) and one download event. To speed up the task of creating these four scripts for every table, you can generate scripts for them automatically by running the “create a synchronization model” task from the MobiLink 10 plug-in in Sybase Central.

For information on the MobiLink plug-in, see the online MobiLink Getting Started book.

The MobiLink plug-in allows you to add more functionality to default scripts than default scripts generated in earlier versions of MobiLink. However, if you are using a remote Adaptive Server Anywhere 9 database (instead of a remote SQL Anywhere 10 database), you can still generate default synchronization scripts by starting the MobiLink synchronization server with the -za switch and setting the SendColumnNames extended option for dbmlsync. For applications using a remote UltraLite 9.x database, you (or an application user) can select a send Column Names check box.

NoteRead-only remote databases If the remote Adaptive Server Anywhere 9 database is read-only—that is, you never want to upload any data—you should not implement the upload scripts. You can use the -ze switch to generate sample scripts, and use the download samples as templates for your download scripts.

StepsTo generate synchronization scripts automatically in PocketBuilder:

  1. Select the Automatic Script Generation check box in the MobiLink Synchronize Server Options dialog box and click OK to start the server.

    You open this dialog box from the Utilities folder in the Database painter or the Database Profiles dialog box.

  2. In an application using a remote Adaptive Server Anywhere database, enter SendColumnNames=ON in the Extended text box on the Settings page of the w_appname_sync_options window.

    or

    In an application using a remote UltraLite database, select the Send Column Names check box on the Settings page of the w_appname_ulsync_options window.

    You must have at least one publication and user defined in the remote database. For a remote Adaptive Server Anywhere database, you must also have at least one subscription defined in the database. If you have more than one publication or user, you must use the -n and/or -u switches to specify which subscription you want to work with.

    If there are existing scripts in the consolidated database, MobiLink does nothing. If there are no existing scripts, MobiLink generates them for all tables specified in the publication. The scripts control the upload and download of data to and from your client and consolidated databases.

    If the column names on the remote and consolidated database differ, the generated scripts must be modified to match the names on the consolidated database.

You can also generate synchronization scripts from a command prompt. Start the server using the -za switch, then run dbmlsync and set the SendColumnNames extended option to on. For example:

dbmlsrv9 -c "dsn=masterdb" -za
dbmlsync -c "dsn=remotedb" -e SendColumnNames=ON

Generated scripts

Table 17-2 shows the scripts that are generated for a table named emp with the columns emp_id, emp_name, and dept_id. The primary key is emp_id.

Table 17-2: Sample default scripts generated by dbmlsrv9 -za

Script name

Script

upload_insert

INSERT INTO emp (emp_id, emp_name, dept_id) VALUES (?,?,?)

upload_update

UPDATE emp SET emp_name = ?, dept_id = ? WHERE emp_id=?

upload_delete

DELETE FROM emp WHERE emp_id=?

download_cursor

SELECT emp_id, emp_name, dept_id FROM emp

The scripts generated for downloading data perform “snapshot” synchronization. A complete image of the table is downloaded to the remote database. Typically you need to edit these scripts to limit the data transferred. For more information, see “Limiting data downloads”.

Before modifying any scripts, you should test the synchronization process to make sure that the generated scripts behave as expected. Performing a test after each modification will help you narrow down errors.