mco_db_xml_export

Save a database image to an external file.

Prototype

 
    MCO_RET	mco_db_xml_export(	/*IN*/ mco_trans_h t,
                   /*IN*/ void * stream_handle,
                   /*IN*/ mco_stream_write output_stream_writer );
 

Arguments

t

The mco_trans_h transaction handle returned by mco_trans_start().

stream_handle Handle to the output stream.

output_stream_writer

Handler function called by the runtime to format output.

Description

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; they will be rebuilt when the database is reloaded. See the control structure stream writer for further details.

Return Codes

MCO_S_OK The database was closed successfully.
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;
        mco_device_t       dev;
        mco_db_params_t    db_params;
        mco_trans_h t;
        FILE * f;
         
        if( (rc = mco_runtime_start()) != MCO_S_OK)
            exit(-1);
             
        rc = mco_db_open_dev( dbname, simple_get_dictionary(), &dev, 1, &db_params );
        if ( MCO_S_OK != rc )
        {
            rc = mco_db_connect(dbname, &db);
            ...
             
            /* Export database */
            f = fopen( "db.xml", "wb" );
            if ( f == 0 ) 
            {
                printf( "\n\t Can't open output file for streaming\n");
            }
            else 
            { 
                rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t);
                if ( MCO_S_OK == rc ) 
                {
                    rc = mco_db_xml_export( t, f, file_writer );
        
                    mco_trans_rollback( t );
                    fclose( f );
                    ...
                }
            }
            ...
        }
    }
 

Files

Header file:
mcoxml.h
Source file:
mcoxser.c
Library:
libmcolib.a