mco_trans_rt_start

Start a real-time database transaction.

Prototype

    MCO_RET mco_trans_rt_start(
        /*IN*/  mco_db_h con,
        /*IN*/  MCO_TRANS_TYPE type,
        /*IN*/  MCO_TRANS_PRIORITY pri,
        /*IN*/  const mco_trans_rt_params_t *params,
        /*OUT*/ mco_trans_h *p_trans
    );

    #define mco_trans_start(db, type, pri, p_trans) \
            mco_trans_rt_start(db, type, pri, NULL, p_trans)

Arguments

con
Database connection handle.
type
Transaction type: one of the values from the MCO_TRANS_TYPE enum (e.g., MCO_READ_ONLY, MCO_READ_WRITE, MCO_UPDATE).
pri
Transaction priority: one of the values from the MCO_TRANS_PRIORITY enum (e.g., MCO_TRANS_FOREGROUND, MCO_TRANS_BACKGROUND).
params
Pointer to a mco_trans_rt_params_t structure containing real-time parameters (e.g., deadline). May be NULL for non-real-time behavior.
p_trans
Address of a variable to receive the new transaction handle.

Description

This function starts a new real-time transaction on the specified database connection. All database operations must be performed within an active transaction.

Use MCO_READ_ONLY for navigation and queries. Use MCO_UPDATE when you intend to modify or delete existing objects. Use MCO_READ_WRITE to create new objects or perform general modifications.

In eXtremeDB/rt, the standard macro mco_trans_start() is defined as an alias to mco_trans_rt_start() with the params argument set to NULL. This allows seamless integration of real-time and non-real-time code paths.

If real-time guarantees are required (e.g., deadline enforcement), provide a valid params structure. Otherwise, pass NULL to start a conventional transaction.

Return Codes

MCO_S_OK
Transaction started successfully.
MCO_ERR_TRN
A database transaction error occurred (e.g., invalid type, priority, or concurrent transaction limit exceeded).

Example

    const char *dbname = "SimpleDb";

    int main(int argc, char* argv[])
    {
        mco_db_h db;
        mco_trans_h t;
        MCO_RET rc;
        mco_device_t dev;
        mco_db_params_t db_params;

        /* Open or connect to database */
        rc = mco_db_open_dev(dbname, simple_get_dictionary(), &dev, 1, &db_params);
        if (rc != MCO_S_OK) {
            rc = mco_db_connect(dbname, &db);
        }
        if (rc != MCO_S_OK) {
            /* handle error */
            return -1;
        }
        ...
        /* Start a real-time read-write transaction */
        rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
        if (rc == MCO_S_OK) {
            /* Perform database operations */
            ...

            /* Commit the transaction */
            rc = mco_trans_commit(t);
        }
        ...
        return 0;
    }

Files

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