Save the database internal data layout definition to an external file.
MCO_RET mco_db_save_metadata(/*IN*/ void *stream_handle,
/*IN*/ mco_stream_write output_stream_writer,
/*IN*/ mco_db_h db,
/*IN*/ mco_bool save_defaults);
stream_handle
output_stream_writer
db
save_defaults
MCO_YES, 0=false= MCO_NO.This function is used to stream the eXtremeDB database metadata in xSQL config file format (JSON) to permanent storage. This file can later be loaded into xSQL in order to connect to the database as a client application.
Note that this function should be used only for applications using a static database schema. When a dynamic schema is used,
MCO_S_OK
MCO_E_NOINSTANCE
MCO_E_WRITE_STREAM
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 metadata */
fbak = fopen( "metadata.cfg", "wb" );
if ( fbak == 0 )
{
printf( "\n\t Can't open output file for streaming\n");
}
else
{
rc = mco_db_save_metadata( (void *)fbak, file_writer, db, MCO_YES);
fclose( fbak );
sample_rc_check( "\t Save database metadata", rc );
}
...
}
}