# mco_class_load
RT

> Load an entire class from an external file.

### Prototype

        MCO_RET	mco_class_load(	/*IN*/ uint2 class_code,
                      /*IN*/ void *stream_handle,
                      /*IN*/ mco_stream_read input_stream_reader,
                      /*IN*/ mco_db_h db );

### Arguments

class_code | Integer class code or 0 (see description below)
stream_handle | Handle to the input stream
input_stream_reader | Handler function called by the runtime to read the input
db | The database handle

### Description

> This function loads a previously saved image of a database class. (See `mco_class_save()`). Note that a transaction is opened implicitly for this operation – no transaction handle is required.

> The `mco_class_save()` / `mco_class_load()` combination is compatible with `mco_db_save()` /`mco_db_load()`. That means that the application can save the entire database image with `mco_db_save()` and later load (or reload) the content of a particular class from the full image. Or it's possible to save the content of only one class with `mco_class_save()` and then use this image to create a database with the`mco_db_load()`.

> The `class_code` parameter can be obtained from the mcocomp-generated files or set to 0. In the latter case the `class_code` value is determined automatically from the image file. If this is impossible, the value `MCO_E_ILLEGAL_PARAM` is returned.

### Return Codes

MCO_S_OK | The database was closed successfully
MCO_E_NOINSTANCE | The specified database is not opened

### Example

        Application snippet:

        mco_size_sig_t file_reader( void *stream_handle /* FILE *  */,  /* OUT */void *to, mco_size_t max_nbytes )
        {
            FILE *f = (FILE *)stream_handle;
            mco_size_sig_t nbs;
            nbs = fread( to, 1, max_nbytes, f );
            return nbs;
        }

        int  main(int argc, char** argv)
        {
            MCO_RET             rc;
            sample_memory_t     dbmem;
            mco_db_h            db;
            mco_db_params_t     db_params;
            …
            FILE * fbak;
            uint2 my_class_code = 1;
            …
            rc = mco_class_load( my_class_code, (void *)fbak, file_reader, db );

            fclose( fbak );
            sample_rc_check( "\t Load class", rc );
            if ( MCO_S_OK == rc )
            {
                /* Connect to database */
                rc = mco_db_connect( dbname, &db );
                sample_rc_check( "\t Connect to database", rc );
            }
        }

### Files

Header file:
mco.h
Source file:
mcosericmn.c
Library:
libmcoseri.a