Connect to a database specifying a context.
MCO_RET mco_db_connect_ctx(/*IN*/ const char *dbname,
/*IN*/ void const* context,
/*OUT*/ mco_db_h *db);
dbname
context
mco_db_connection_context()
which returns the address of the context associated with a connection to an existing database.db
This function connects to a database specifying connection context values that can later be accessed for application-specific purposes.
MCO_S_OK
MCO_E_NOINSTANCE
MCO_ERR_TRN
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)
{
...
}
}
...
}