mco_disk_save DEPRECATED

Save persistent classes to an external file. This function has been deprecated in version 7.1. See mco_db_save().

Prototype

    MCO_RET mco_disk_save(/*IN*/ void *stream_handle,
                 /*IN*/ mco_stream_write output_stream_writer,
                 /*IN*/ mco_db_h db);

Arguments

stream_handle
Handle to the output stream.
output_stream_writer
Handler function called by the runtime to format output.
db
The database handle.

Description

While mco_db_save() copies all database objects (both persistent and transient), this function writes the content of only the persistent classes to a stream. The calling application must provide a stream pointer (a pointer to a file, socket, pipe, etc.) and the address of a function that will perform the actual writes of the stream of bytes representing the database image.

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 saved successfully.
MCO_E_NOINSTANCE
The specified database is not opened.
MCO_E_WRITE_STREAM
Error writing to output stream.

Example

    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 database */
            fbak = fopen("diskdb.bak", "wb");
            if (fbak == 0)
            {
                printf("\n\t Can't open output file for streaming\n");
            }
            else
            {
                rc = mco_disk_save((void *)fbak, file_writer, db);

                fclose(fbak);
                sample_rc_check("\t Save database", rc);
            }
            ...
        }
    }

Files

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