Save transient (in-memory) classes to an external file. This function has been deprecated in version 7.1. See mco_db_save().
MCO_RET mco_inmem_save(/*IN*/ void *stream_handle,
/*IN*/ mco_stream_write output_stream_writer,
/*IN*/ mco_db_h db);
stream_handle
output_stream_writer
db
While
mco_db_save()copies all database objects (both persistent and transient), this function writes the content of only the transient classes to a stream. The calling application must provide a stream pointer (a pointer to a file, socket, pipe, etc.) and the address of a function that will perform the actual writes of the stream of bytes representing the database image.It is the application's responsibility to open the output stream in the proper mode to stream binary data, and to ensure that there is adequate space at the destination to hold the database. Indexes are not streamed; they will be rebuilt when the database is reloaded. See the control structure stream writer for further details.
MCO_S_OK
MCO_E_NOINSTANCE
MCO_E_WRITE_STREAM
Application snippet:
const char *dbname = "SimpleDb";
/* Stream writer with prototype mco_stream_write */
mco_size_sig_t file_writer(void *stream_handle /* FILE * */, const void *from, mco_size_t nbytes)
{
FILE *f = (FILE *)stream_handle;
mco_size_sig_t nbs;
nbs = fwrite(from, 1, nbytes, f);
return nbs;
}
int main(int argc, char* argv[])
{
mco_db_h db;
MCO_RET rc;
FILE *fbak;
mco_device_t dev;
mco_db_params_t db_params;
...
if ((rc = mco_runtime_start()) != MCO_S_OK)
exit(-1);
rc = mco_db_open_dev(dbname, simpledb_get_dictionary(), &dev, 1, &db_params);
if (MCO_S_OK != rc)
{
rc = mco_db_connect(dbname, &db);
...
/* Backup database */
fbak = fopen("inmemdb.bak", "wb");
if (fbak == 0)
{
printf("\n\t Can't open output file for streaming\n");
}
else
{
rc = mco_inmem_save((void *)fbak, file_writer, db);
fclose(fbak);
sample_rc_check("\t Save database", rc);
}
...
}
}