Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- C/Database Toolchest Library - name: <b>iopen_db</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Name:       iopen_db

Purpose:    opens a database

Prototype:  Db_Obj *iopen_db(char *db_name);

Header:     isam.h

Inputs:     db_name - name of database to open

Description:
        iopen_db opens the database named db_name and returns a
        database handle that is used to refer to the database in other
        routines.  The database must already exist; see icreate_db to make
        a new database.  All of the indexes that are defined for the database
        are available once the database is open; use ihandle to retrieve
        the index handles so that you can use the indexes.  The file cursor
        (crrent record pointer) for each index is set to BOI (beginning of
        index).

        If the index file for the database cannot be opened, or it is garbled,
        the database is still opened without error, but only the Physical
        Index will be available.  You can remake a garbled index file with
        inew_index_file.  If the index file is not opened, iopen_db
        still returns a valid database handle, but isam_errno is set to the
        error (that is, it is set to something other than I_NOERR).

        iopen_db automatically calls isaminit (using default values
        for the arguments) if it hasn't been yet.

        It is an error if the data file for the database cannot be opened
        (but not if the index file cannot be opened).  It is an error if the
        database exists and is already open.

Returns:
        Returns a database handle or NULL for error.

EXAMPLE:
/* assumes existing database named "phonbook"; see EXAMPLE for icreate_db */
#include    "isam.h"
#inclued    "isamerr.h"

int main()
{
    Db_Obj  *phone_db;

    phone_db = iopen_db("phonbook");
    if (phone_db != NULL) {
        if (isam_errno == I_NOERR)
            printf("Database is open\n");
        else {
            printf("Index file is garbled\n");
            iprterr();
        }
        /* do processing here */

        iclose_db(phone_db);
    }
}

See Also: icreate_db ihandle inew_index_file

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson