Code examples

This section provides examples of a simple application using the CDC procedures. The examples are provided separately for each of the supported language libraries.

Cursor management and server side filtering

The change identifiers returned from the CDC procedures are valid until the server rotates the transaction log.

Usually the change cursor stays valid, since each call to db.cdc.query updates the cursor. However, very strict selectors may cause db.cdc.query to not return any changes. This can in extreme cases lead to the cursor not being updated in time before the transaction log is rotated. To avoid this, the code examples update the cursor to db.cdc.current if db.cdc.query returns empty. Note that db.cdc.current needs to be called and stored before calling db.cdc.query for this to work.

Another way to avoid this issue is to use broader selectors and perform client side filtering instead.