# mco_set_trans_callback
RT

> 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 for a database connection
callback
A pointer to a callback function
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`
> - `MCO_TRANS_POSTCOMMIT`
> - `MCO_TRANS_ROLLBACK`
> 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