Save an entire class to an external file.
MCO_RET mco_class_save(/*IN*/ uint2 class_code,
/*IN*/ void *stream_handle,
/*IN*/ mco_stream_write output_stream_writer,
/*IN*/ mco_db_h db);
class_code
stream_handle
output_stream_writer
db
This function is used to stream the entire contents of a database class to permanent storage. Used together with
mco class load(), an application can save and optionally load class data. 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 withmco db save()/mco db load(). That means that the application can save the entire database image withmco db save()and later load (or reload) the content of a particular class from the full image. Or it is possible to save the content of only one class withmco_class_save()and then use this image to create a database withmco db load().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;
uint2 my_class_code = 1;
...
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("myclass.bak", "wb");
if (fbak == 0)
{
printf("\n\t Can't open output file for streaming\n");
}
else
{
rc = mco_class_save(my_class_code, (void *)fbak, file_writer, db);
fclose(fbak);
sample_rc_check("\t Save class", rc);
}
...
}
}