# mco_metadict_register_conn
RT

> Register a database dictionary in the meta-dictionary.

### Prototype

        MCO_RET mco_metadict_register_conn(	/*IN*/ mco_metadict_header_t * metadict,
                       /*IN*/ const mco_db_h db,
                       /*IN*/ const void * user_data);

### Arguments

metadict | The address of a mco_metadict_header_t structure
db | The database handle
user_data | The address of optional application-specific data

### Description

The API registers the database dictionaries for the current connection in the meta-dictionary. Unlike function `mco_metadict_register()` this function does not require a pointer to a dictionary structure generated by `mcocomp`. So it is ideal for applications where the database dictionary is not initially known, for example when an application opens a database already created by another application in shared memory.

Another use case of function `mco_metadict_register_conn()` is an application that uses SQL dynamic DDL operations like `create table`, `alter table` etc. Since the database table is created or modified by SQL DDL operations it is impossible to use any statically defined data access functions; i.e. the functions generated by `mcocomp`. Of course it is necessary to register a dictionary again each time that it is modified. The return code `MCO_E_SCHEMA_CHANGED` is returned by function`mco_trans_start()` whenever an SQL operation has changed a database schema. In this case the current connection should be closed and then re-connected again; the newly obtained connection should then be used to register its dictionary in the meta-dictionary.

### Return Codes

MCO_S_OK | The metadictionary was successfully registered
MCO_E_UDA_TOOMANY_ENTRIES | The metadictionary is full
MCO_E_UDA_NAME_TOO_LONG | The dictionary name is too long
MCO_E_UDA_DUPLICATE | The name is already registered

### Example

        Application snippet:

        const char * dbname = "SimpleDb";

        int main(int argc, char* argv[])
        {
            MCO_RET rc;
            mco_db_h           db;
            mco_device_t       dev;
            mco_db_params_t    db_params;
            unsigned int size;
            mco_metadict_header_t *header;
            uint4 custom_data = 999; // any type of application specific data

            rc = mco_db_open_dev( dbname, simpledb_get_dictionary(), &dev, 1, &db_params );
            if ( MCO_S_OK != rc ) exit();

            rc = mco_db_connect(  dbname, &db );
            ...
            mco_metadict_size(1, &size);
             header = (mco_metadict_header_t *) malloc(size);
             mco_metadict_init(header, size);
             ...
             // Perform SQL DDL operation on database “simpledb”
             ...
             // Register the modified database dictionary for “simpledb”
             mco_metadict_register_conn(header, db, &custom_data);

             ...
        }

### Files

Header file:
mcouda.h
Source file:
mcouda.c
Library:
libmcouda.a