Writing an application to capture data changes

Use the Change Data Capture functions to control the data capture process. Process CDC records to extract the data. Query syscdc tables to retrieve the symbolic names and descriptions of CDC records and errors.

Before you begin

Complete the prerequisite tasks to prepare for using the Change Data Capture API.
Your application should contain the following structures and functions:
  • A structure to store table schema information. You use the table schema to parse the column data.
  • A function to interpret the table schema information and populate the table schema structure. You can obtain the table schema information from the CDC_REC_TABSCHEMA record.
  • A function to retrieve and parse the column values from the data buffer.
  • A function to handle errors. You can query the syscdcerrcodes table to determine the symbolic name and description of the error code.

About this task

Include the following tasks in your application to capture data changes:

Procedure

  1. As user informix, connect to the syscdcv1 database on the database server to which the client is currently connected.
  2. Open a capture session by running the cdc_opensess() function.
    The cdc_opensess() function returns a session ID.
  3. Enable full-row logging for each table from which you want to capture data by running the cdc_set_fullrowlogging() function.
  4. Specify which data to capture by running the cdc_startcapture() function.
    Run this function for each table from which you want to capture data.
  5. Start the capture process by running the cdc_activatesess() function.
    CDC records, including those that contain captured data, are returned to the application.
  6. Read the CDC records containing captured data with a smart large object read function such as mi_lo_read() by passing the session ID as the large object file descriptor.
    Use the same smart large object read function for all read calls.
  7. Parse the data by column values.
    If you are writing your application in Java™, you can use the IfxToJavaType class to convert a byte stream of the HCL OneDB™ representation of a data type to the appropriate Java data type and value.
  8. Stop capturing data by running the cdc_endcapture() function for each table.
  9. Disable full-row logging by running the cdc_set_fullrowlogging() function for each table.
    Make sure that no other applications or processes are dependent on full-row logging before your disable it.
  10. Close the capture session by running the cdc_closesess() function.