mco_db_save_metadata

Save the database internal data layout definition to an external file.

Prototype

 
    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);
 

Arguments

stream_handle Handle to the output stream

output_stream_writer

Handler function called by the runtime to format output

db

The database handle

save_defaults

Save default values in addition to explicitly set values: 1=true= MCO_YES, 0=false= MCO_NO

Description

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,

Return Codes

MCO_S_OK The database was closed successfully
MCO_E_NOINSTANCE The specified database is not opened
MCO_E_WRITE_STREAM Error writing to output stream

Example

 
    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;
        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 );
            }
            ...
        }
    }
 

Files

Header file:
mco.h
Source file:
mcodbcfg.c
Library:
libmcolib.a