Firebird Documentation IndexFirebird ODBC/JDBC Driver ManualFirebird Events → Priming the Driver to Listen for Events
Firebird Home Firebird Home Prev: Firebird EventsFirebird Documentation IndexUp: Firebird EventsNext: The Services Interface

Priming the Driver to Listen for Events

The first piece of setting up the driver to listen for events is to connect to an ODBC interface file that describes Firebird events processing:

#include "OdbcUserEvents.h"
      

Next, in the table eventInfo, we specify the events that we are interested in. For our example, the event 'new_order' is the only one we are interested in at this stage. The event 'change_order' is in the picture only to demonstrate the driver's ability to manage multiple events.

ODBC_EVENT_INFO eventInfo[] =
{
 INIT_ODBC_EVENT("new_order"),
 INIT_ODBC_EVENT("change_order")
};
      

Now, we need to create a structure—which we will name MyUniqueData—to store the data tasks involved in our operation. In our example, a field event_flag will signal an event delivered from the server. Our job starts from there.

struct MyUniqueData
{
 int event_flag;
 //... other define for use into astRoutine
};
      

We need to create a callback function, astRoutine, which will be activated when events defined in the eventInfo table are flagged:

void astRoutine( void *userEventsInterfase, short length, char * updated )
{
    PODBC_USER_EVENTS_INTERFASE userInterfase = (PODBC_USER_EVENTS_INTERFASE)userEventsInterfase;
    SQLSetConnectAttr( userInterfase->hdbc, SQL_FB_UPDATECOUNT_EVENTS, (SQLPOINTER)updated, SQL_LEN_BINARY_ATTR( length ) );
    MyUniqueData &myData = *(MyUniqueData*)userInterfase->userData;
    myData.event_flag++;
    printf( "ast routine was called\n" );
}
      

The function needs to have a call:

  SQLSetConnectAttr( userInterfase->hdbc,
                       SQL_FB_UPDATECOUNT_EVENTS,
                       (SQLPOINTER)updated,
                       SQL_LEN_BINARY_ATTR( length ) );
      

This call is needed for updating the state of events in our structure eventInfo. That structure has a field countEvents that maintains a total of event operations and a Boolean field changed that is set True when the 'before' and 'after' values of countEvents are different.

When we want to flag an event that we are interested in, we issue the command:

    myData.event_flag++;
      

It provides a fairly primitive mechanism for synchronizing workflow, but it is sufficient for our needs. Its setup is as follows:

Prev: Firebird EventsFirebird Documentation IndexUp: Firebird EventsNext: The Services Interface
Firebird Documentation IndexFirebird ODBC/JDBC Driver ManualFirebird Events → Priming the Driver to Listen for Events