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 versions 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 the mco_db_save() function, they will be decrypted by mco_db_load() if the mco_db_params_t::cipher_key field 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 loaded successfully.
MCO_E_NOINSTANCE
The specified database is not opened.
MCO_E_VERS_MISMATCH
The metainformation (bit depth, endianness, etc.) of the loaded and new databases does not match.
MCO_E_LOAD_DATA
Invalid file format.
MCO_E_ILLEGAL_PARAM
The parameters of the new and loaded database do not match.
Other codes
Other return codes may be returned due to implementation-specific errors.

For a more detailed explanation of the error's root cause, run the application with ERROR-level tracing enabled.

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, db_name, backupdb_get_dictionary(), dbmem.dev, dbmem.n_dev, &db_params);

        fclose(fbak);
        sample_rc_check("\tLoad database", rc);
        if (MCO_S_OK == rc)
        {
            /* Connect to database */
            rc = mco_db_connect(db_name, &db);
            sample_rc_check("\tConnect to database", rc);
        }
    }
        

Files

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