Load a database image from an external file.
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 );
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 seemco_db_save()
).With release 7.1, eXtremeDB has simplified the
mco_db_save()
andmco_db_load()
APIs and the former variantsmco_inmem_save()
,mco_inmem_load()
,mco_disk_save()
,mco_disk_load()
andmco_disk_load_file()
have been deprecated.The simplified version of
mco_db_save()
andmco_db_load()
allow the application to stream database contents to and from a persistent media file, socket, or pipe, withCRC
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 functionmco_db_save()
, they will be decrypted bymco_db_load()
if fieldmco_db_params_t::cipher_key
is specified. (Note that the exact same cipher key must be specified for saving and loading an encrypted snapshot.)
MCO_S_OK | The database was closed successfully |
MCO_E_NOINSTANCE | The specified database is not opened |
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 ); } }