mco_trans_start

Start a database transaction.

Prototype

    MCO_RET	mco_trans_start(
            /*IN*/ mco_db_h db,
            /*IN*/ MCO_TRANS_TYPE trans_type,
            /*IN*/ MCO_TRANS_PRIORITY priority,
            /*OUT*/ mco_trans_h * t
    );

Arguments

db
The database handle for a database connection
trans_type
A one-byte unsigned value, taken from the enum MCO_TRANS_TYPE
priority
A two-byte unsigned value, taken from the enum MCO_TRANS_PRIORITY
t
The address of a mco_trans_h to receive the transaction handle

Description

This function initiates a transaction for the database referenced by db. All database access must occur within the scope of a transaction. This function is called with the MCO_READ_ONLY transaction type for database navigation. If the intent is to find a database object for modification (Update of Delete) the MCO_UPDATE transaction type should be specified. To update a database object a MCO_READ_WRITE transaction must be started, or the current transaction must be upgraded by calling function mco_trans_upgrade().

Return Codes

MCO_S_OK
The database was created successfully
MCO_ERR_TRN
A database transaction error occurred

Example

    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_WRITE, MCO_TRANS_FOREGROUND, &t);

            if ( MCO_S_OK == rc )
            {
                ...
                rc = mco_trans_commit( t );
                ...
            }
        }
        ...
    }

Files

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