mco_set_trans_callback

Assign a callback function to be invoked when a transaction is committed or rolled back.

Prototype

    void mco_set_trans_callback(
        /*IN*/ mco_db_h db,
        /*IN*/ mco_trans_callback_t callback,
        /*IN*/ void* arg);

Arguments

db
The database handle that was established by mco_db_connect().
callback
A pointer to the mco_trans_callback() function that is called when a transaction is committed or rolled back.
arg
A pointer to an argument to be passed to the callback function.

Description

This function assigns a callback to be invoked when a transaction is committed or rolled back. The callback function is called with the transaction handle, the transaction state, and a user-supplied argument.

Callback Prototype

    ...
    static MCO_RET mco_trans_callback(
        mco_trans_h trans,
        mco_trans_state state,
        void* arg
    )
    {
        if (state == MCO_TRANS_POSTCOMMIT) {
            ((McoAsyncCommitSession*)arg)->commit();
        }
        return MCO_S_OK;
    }
    ...

Callback Parameters

trans
Handle of the transaction being processed.
state
Indicates the current transaction state. One of the following values:
  • MCO_TRANS_PRECOMMIT — the transaction is about to be committed.
  • MCO_TRANS_POSTCOMMIT — the transaction has been committed.
  • MCO_TRANS_ROLLBACK — the transaction has been rolled back.
arg
User-defined pointer passed to the callback.

Callback Return Value

The callback function should return MCO_S_OK on success.

Return Codes

None
This function does not report errors.

Example

    ...
    void McoAsyncCommitSession::listen(McoSqlSession* session)
    {
        mco_db_h dbh = session->getHandle();
        mco_set_trans_callback(dbh, mco_trans_callback, this);
    }

    ...

Files

Header file:
mco.h
Source file:
mcoabst.c
Library:
libmcolib.a