mco_db_load

Load a database image from an external file.

Prototype

 
    MCO_RET	mco_db_load(	/*IN*/ void *stream_handle,
                /*IN*/ mco_stream_read input_stream_reader,
                /*IN*/ const char * dbname,
                /*IN*/ mco_dictionary_h dict,
                /*IN*/ mco_device_t *devices,
                /*IN*/ uint2 n_devices,
                /*IN*/ mco_db_params_t * db_params );
 

Arguments

stream_handle Handle to the input stream
input_stream_reader Handler function called by the runtime to read the input
dbname Database name passed to mco_db_open_dev()

dict

Database dictionary handle passed to mco_db_open_dev().

devices

Device structure array passed to mco_db_open_dev()

n_devices

The number of device structures passed to mco_db_open_dev()

db_params

The database parameters passed to mco_db_open_dev()

Description

This function loads a previously saved image of a database and opens it by internally calling mco_db_open_dev() with the passed parameters. It is the application’s responsibility to open the input stream, in the proper mode to read binary data, and to ensure that there is adequate memory to hold the database. See the control structure stream_reader for further details. (Also see mco_db_save()).

With release 7.1, eXtremeDB has simplified the mco_db_save() and mco_db_load() APIs and the former variants mco_inmem_save(), mco_inmem_load(), mco_disk_save(), mco_disk_load() and mco_disk_load_file() have been deprecated.

The simplified version of mco_db_save() and mco_db_load() allow the application to stream database contents to and from a persistent media file, socket, or pipe, with CRC checking, “binary schema evolution” (BSE) support and buffering to allow interruption and restart of the streaming process. Also, if the database snapshot files were encrypted by function mco_db_save(), they will be decrypted by mco_db_load()if field mco_db_params_t::cipher_key is specified. (Note that the exact same cipher key must be specified for saving and loading an encrypted snapshot.)

Return Codes

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

Example

 
    Application snippet:

     
    const char * db_name = "backupdb";
     
    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;
        …
        rc = mco_db_load( (void *)fbak, file_reader, dbname, backupdb_get_dictionary(), dbmem.dev, dbmem.n_dev, &db_params );

        fclose( fbak );
        sample_rc_check( "\t Load database", 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:
mcoseri.c
Library:
libmcoseri.a