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 | The name of the database to connect to |
context |
The address of database context data or a call to |
db |
The address of a database handle for this database connection |
This function connects to a database specifying connection context values that can later be accessed for application specific purposes.
MCO_S_OK | The database was created successfully |
MCO_E_NOINSTANCE | The specified database is not opened |
MCO_ERR_TRN | A database transaction error occurred. (eg. The database is already opened by some other thread that has an open transaction.) |
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 ) { ... } } ... }