Lesson 2: Specify class methods for events

CustdbScripts.dll, created in the previous lesson, encapsulates the methods UploadInsert() and DownloadCursor(). These methods contain implementation for the ULCustomer upload_insert and download_cursor events, respectively.

In this section, you specify class methods for table-level events using two approaches:

  1. Creating a MobiLink project through Sybase Central.

    You connect to the CustDB database using Sybase Central, replace the upload_insert SQL script with a .NET script, and then specify MLExample.CustdbScripts.UploadInsert to handle the event.

  2. Using the ml_add_dnet_table_script stored procedure.

    You connect to the CustDB database with Interactive SQL and run ml_add_dnet_table_script, specifying MLExample.CustdbScripts.DownloadCursor for the download_cursor event.

 To create a new MobiLink project
  1. Choose Start » Programs » SQL Anywhere 12 » Administration Tools » Sybase Central.

  2. From the Tools menu, choose MobiLink 12 » New Project.

  3. In the Name field, type mldnet_project.

  4. In the Location field, type C:\mldnet, and then click Next.

  5. Check the Add A Consolidated Database To The Project option.

  6. In the Database Display Name field, type mldnet_db.

  7. Click Edit. The Connect To A Generic ODBC Database window appears.

  8. In the ODBC Data Source name field, click Browse and select SQL Anywhere 12 CustDB.

  9. Click OK, then click Save.

  10. Click Finish.

  11. Click OK.

In the next procedure, you use Sybase Central to specify a .NET method as the script for the ULCustomer upload_insert event.

 To subscribe CustdbScripts.uploadInsert() to the upload_insert event for the ULCustomer table
  1. From the View menu, choose Folders.

  2. In the left pane of Sybase Central under MobiLink 12, expand mldnet_project, Consolidated Databases, mldnet_db, Synchronized Tables and then ULCustomer.

  3. In the right pane, select the custdb 12.0 upload_insert table script. From the Edit menu, choose Delete.

  4. Create a new upload_insert table script.

    1. From the File menu, choose New » Table Script.

    2. In the For Which Version Do You Want To Create The Table Script list, click custdb 12.0.

    3. In the Which Event Should Cause The Table Script To Be Executed list, click upload_insert, and then click Next.

    4. Select Create a new script definition and then select .NET.

    5. Click Finish.

  5. Enter the .NET method name to load for the custdb 12.0 upload_insert table script.

    In the right pane of Sybase Central, use the following .NET script for the upload_insert event:

    MLExample.CustdbScripts.UploadInsert
  6. From the File menu, choose Save to save the script.

  7. Close Sybase Central.

Alternatively, you can use the ml_add_dnet_connection_script and ml_add_dnet_table_script stored procedures. Using these stored procedures is more efficient, especially if you have a large number of .NET methods to handle synchronization events.

See ml_add_dnet_connection_script system procedure and ml_add_dnet_table_script system procedure.

In the next procedure, you connect to CustDB with Interactive SQL and execute ml_add_dnet_table_script, assigning MLExample.CustdbScripts.DownloadCursor to the download_cursor event.

 To specify MLExample.CustdbScripts.DownloadCursor for the ULCustomer download_cursor event
  1. Connect to the sample database with Interactive SQL.

    1. Choose Start » Programs » SQL Anywhere 12 » Administration Tools » Interactive SQL, or run the following command:

      dbisql
    2. Click ODBC Data Source Name and type SQL Anywhere 12 CustDB.

    3. Click Connect.

  2. Run the following SQL script in Interactive SQL:

    CALL ml_add_dnet_table_script(
        'custdb 12.0',
        'ULCustomer',
        'download_cursor',
        'MLExample.CustdbScripts.DownloadCursor');
    COMMIT;

    The following is a description of each parameter:

    Parameter Description
    custdb 12.0 The script version.
    ULCustomer The synchronized table.
    download_cursor The event name.
    MLExample.CustdbScripts.DownloadCursor The fully qualified .NET method.
    Note

    Your updated download_cursor script might not appear in Sybase Central. To view the most recent changes to the MobiLink project in Sybase Central, click the View menu and choose Refresh All.

  3. Close Interactive SQL.

In this lesson, you specified .NET methods to handle ULCustomer table-level events. The next lesson ensures that the MobiLink server loads the appropriate class files and the MobiLink server API.

 Further reading