mco_get_last_error

Return the last return code from an eXtremeDB function that caused a transaction to enter an error state.

Prototype

    MCO_RET	mco_get_last_error(	/*IN*/ mco_trans_h t );

Arguments

t
The mco_trans_h transaction handle returned by mco_trans_start().

Description

This function returns the value of the last return code from an eXtremeDB function that caused a transaction to enter an error state. After a transaction enters an error state, subsequent operations within that transaction will return MCO_E_TRANSACT so that a call to mco_get_last_error() will return the error code of the operation that initially caused the error condition.

In eXtremeDB/rt returns the current transaction error code. Applications can use the function to verify the deadline status while carrying out non-database activity within the database transaction. Specifically the mco_get_last_error() function internally verifies the deadline at its cancellation point.

Return Codes

MCO_RET value
The error that caused the transaction to enter an error state. If no error occurred, MCO_S_OK.

Example

    /* eXtremeDB */
    const char * dbname = "SimpleDb";
    int main(int argc, char* argv[])
    {
        mco_db_h db;
        MCO_RET rc;
        mco_device_t       dev;
        mco_db_params_t    db_params;
        mco_trans_h t;
        ...
        rc = mco_db_open_dev( dbname, simple_get_dictionary(), &dev, 1, &db_params );
        if ( MCO_S_OK != rc )
        {
            rc = mco_db_connect(  dbname, &db );
            ...
            rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
            if ( MCO_S_OK == rc )
            {
                ...
                // Perform database operations within the transaction
                ...
                rc = mco_get_last_error( t );

                if ( MCO_S_OK != rc )
                {
                    mco_trans_rollback(t);
                }
                ...
            }
        }
        ...
    }
    /* eXtremeDB/rt */
    mco_trans_h t;
    mco_trans_rt_start(..., &t);
    ...
    while (condition) {
        /* ... non-DB activity ... */
        if (mco_get_last_error(t) != MCO_S_OK) {
            /* E_INTERRUPTED is detected */
            break;
        }
    }
    ...
    mco_trans_commit(t);

Files

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