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 |
Integer class code or 0 (see description below) |
stream_handle | Handle to the input stream |
input_stream_reader | Handler function called by the runtime to read the input |
db |
The database handle |
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's possible to save the content of only one class withmco_class_save()
and then use this image to create a database with themco_db_load()
.The
class_code
parameter can be obtained from the mcocomp-generated files or set to 0. In the latter case theclass_code
value is determined automatically from the image file. If this is impossible, the valueMCO_E_ILLEGAL_PARAM
is returned.
MCO_S_OK | The database was closed successfully |
MCO_E_NOINSTANCE | The specified database is not opened |
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 ); } }