Load an entire class from an external file.
MCO_RET mco_class_load(/*IN*/ uint2 class_code,
/*IN*/ void *stream_handle,
/*IN*/ mco_stream_read input_stream_reader,
/*IN*/ mco_db_h db);
class_code
stream_handle
input_stream_reader
db
This function loads a previously saved image of a database class (see
mco_class_save()). 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().The
class_codeparameter can be obtained from the mcocomp-generated files or set to 0. In the latter case theclass_codevalue is determined automatically from the image file. If this is impossible, the valueMCO_E_ILLEGAL_PARAMis returned.
MCO_S_OK
MCO_E_NOINSTANCE
Application snippet:
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;
uint2 my_class_code = 1;
...
rc = mco_class_load(my_class_code, (void *)fbak, file_reader, db);
fclose(fbak);
sample_rc_check("\t Load class", rc);
if (MCO_S_OK == rc)
{
/* Connect to database */
rc = mco_db_connect(dbname, &db);
sample_rc_check("\t Connect to database", rc);
}
}