# sample_open_database

Open an eXtremeDB database.

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

### Prototype

        MCO_RET sample_open_database( /*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

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 provides a simple method for creating an in-memory or persistent database by simply specifying the argument values. Internally the function calls `sample_load_database()` to do the work.

### 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_open_database( db_name, simpledb_get_dictionary(), DATABASE_SIZE, CACHE_SIZE,
                            MEMORY_PAGE_SIZE, PSTORAGE_PAGE_SIZE, 1, &dbmem );

            ...
        }