This function exports the entire database contents, or individual objects, in JSON format.
MCO_RET mco_db_json_export(/*IN*/ mco_trans_h t,
/*IN*/ void *stream_handle,
/*IN*/ mco_stream_write output_stream_writer);
t
mco_trans_h transaction handle returned by mco_trans_start().stream_handle
output_stream_writer
This function exports database data to an output stream. The runtime calls the application-defined handler to manage the output stream.
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. (See the control structure mco stream write for further details.)
MCO_S_OK
MCO_E_WRITE_STREAM
MCO_E_JSER_NOINDEX
/* Stream writer function matching the mco_stream_write prototype */
mco_size_sig_t file_writer(void *stream_handle /* FILE * */, const void *from, mco_size_t nbytes)
{
return fwrite(from, 1, nbytes, (FILE *)stream_handle);
}
/* Function to export the entire database contents */
void export_all()
{
mco_trans_h t;
FILE *f = fopen("db.json", "wb");
/* Export the database */
mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
mco_db_json_export(t, f, file_writer);
mco_trans_rollback(t);
fclose(f);
}