mco_db_connect_ctx

Connect to a database specifying a context.

Prototype

    MCO_RET mco_db_connect_ctx(/*IN*/ const char *dbname,
                     /*IN*/ void const* context,
                     /*OUT*/ mco_db_h *db);

Arguments

dbname
The name of the database to connect to.
context
The address of database context data or a call to mco_db_connection_context() which returns the address of the context associated with a connection to an existing database.
db
The address of a database handle for this database connection.

Description

This function connects to a database specifying connection context values that can later be accessed for application-specific purposes.

Return Codes

MCO_S_OK
The database was connected successfully.
MCO_E_NOINSTANCE
The specified database is not opened.
MCO_ERR_TRN
A database transaction error occurred. (e.g. The database is already opened by some other thread that has an open transaction.)

Example

    Application snippet:

    const char *dbname = "SimpleDb";

    int get_pid()
    {
        #ifdef _WIN32
            return GetCurrentProcessId();
        #else
            return getpid();
        #endif
    }

    int main(int argc, char* argv[])
    {
        mco_db_h db;
        MCO_RET rc;
        mco_device_t dev;
        mco_db_params_t db_params;
        int pid = get_pid();
        ...
        rc = mco_db_open_dev(dbname, simpledb_get_dictionary(), &dev, 1, &db_params);

        /* Allow duplicate instances because all processes connect to the same db */
        if (MCO_S_OK == rc || MCO_E_INSTANCE_DUPLICATE == rc)
        {
            /* connect using mco_db_connect_ctx() and pass &pid as parameter */
            rc = mco_db_connect_ctx(dbname, &pid, &db);

            if (MCO_S_OK == rc)
            {
                ...
            }
        }
        ...
    }

Files

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