# sample_load_database

Load an eXtremeDB database.

### For an overview see page Samples Helper Functions in C

### Prototype

        MCO_RET sample_load_database( /*IN*/ void* stream_handle,
                        /*IN*/ mco_stream_read input_stream_reader,
                        /*IN*/ const char * db_name,
                        /*IN*/ mco_dictionary_h dict,
                        /*IN*/ mco_size_t db_sz,
                        /*IN*/ mco_size_t cache_sz,
                        /*IN*/ uint2 mem_pg_sz,
                        /*IN*/ uint2 pstorage_pg_sz,
                        /*IN*/ uint2 max_conn_no,
                        /*IN*/ sample_memory_t * pdev)

### Arguments

stream_handle | An optional database input stream handle
input_stream_reader | An optional database input stream reader
db_name | The name of the database
dict | A pointer to compiled database dictionary (typically the generated function database_name`_get_dictionary()`)
db_sz | The size of the memory segment for the in-memory part of the database
cache_sz | The size of the cache segment for persistent storage
mem_pg_sz | The size of memory pages
pstorage_pg_sz | The size of persistent storage pages
max_conn_no | The maximum number of connections
pdev | The pointer to the `sample_memory_t` struct to be initialized:
      typedef struct tag_sample_memory
      {
        unsigned int       n_dev;
        mco_device_t       dev[4];

      } sample_memory_t;

### Description

This function does the work of creating an in-memory or persistent database by creating the memory devices, allocating dynamic memory and setting the database parameters according to the specified arguments. If the `stream_handle` and `input_stream_reader` arguments are non-zero, function `mco_db_load()` is called to load a previously saved image of a database. Otherwise function `mco_db_open_dev()` is called to open the database with the initialized `sample_memory_t` struct.

(Typically this function is called indirectly by sample applications which instead call `sample_open_database()`.)

### Return Codes

MCO_S_OK | The database was successfully created
MCO_E_ILLEGAL_PARAM | The specified arguments are inconsistent or invalid

### Example

        #include <common.h>
        #include <simpledb.h>
        const char * db_name = "simpledb";
        ...

        int main(int argc, char* argv[])
        {
            MCO_RET rc;
            sample_memory_t dbmem;

            mco_runtime_start();

            rc = sample_load_database( 0, 0, db_name, simpledb_get_dictionary(), DATABASE_SIZE, CACHE_SIZE,
                            MEMORY_PAGE_SIZE, PSTORAGE_PAGE_SIZE, 1, &dbmem );

            ...
        }