Start a real-time database transaction.
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)
con
type
MCO_TRANS_TYPE enum (e.g., MCO_READ_ONLY, MCO_READ_WRITE, MCO_UPDATE).pri
MCO_TRANS_PRIORITY enum (e.g., MCO_TRANS_FOREGROUND, MCO_TRANS_BACKGROUND).params
mco_trans_rt_params_t structure containing real-time parameters (e.g., deadline). May be NULL for non-real-time behavior.p_trans
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_ONLYfor navigation and queries. UseMCO_UPDATEwhen you intend to modify or delete existing objects. UseMCO_READ_WRITEto create new objects or perform general modifications.In eXtremeDB/rt, the standard macro
mco_trans_start()is defined as an alias tomco_trans_rt_start()with theparamsargument set toNULL. 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
paramsstructure. Otherwise, passNULLto start a conventional transaction.
MCO_S_OK
MCO_ERR_TRN
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;
}