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>igetrec</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Name:       igetrec

Purpose:    get a copy of the current record

Prototype:  int igetrec (Db_Obj    *db,
                         Index_Obj *index,
                         char      *fields[],
                         char      *buffer,
                         Rec_Len  buffer_size);

Header:     isam.h

Inputs:     db          - database handle
            index       - index handle
            fields      - (to be) array of pointers to each field
            buffer      - storage for record
            buffer_size - maximum size for your buffer.

Description:
        igetrec copies the current record of the index from the
        database db into the area pointer to by buffer.  Not more than
        buffer_size bytes are copied, so it returns an incomplete record
        if the record will not fit into the buffer.  It is not an error to
        return an incomplete record.  Even an incomplete record is terminated
        by a nul (binary zero).  You can call igetreclen to determine the
        length of the record before you call igetrec.  The buffer may
        contain one or two orphan bytes at the end.

        igetrec fills in the fields array with a pointer to the
        beginning of each field.  If an incomplete record is returned, the
        fields array is filled in as much as possible, and the other
        elements are set to NULL.  In this case, note that the last element of
        fields may point to an incomplete field, but that field is still
        nul-terminated.

        The behavior is undefined (and certainly undesirable) if the
        fields array is not large enough.  Use igetfldcount to
        determine the needed size if you are not sure.  The fields array
        is terminated by a NULL pointer, so be sure the array is large enough
        for all the fields plus the NULL pointer at the end.

        The buffer and the fields array are not filled in if the file
        cursor is at BOI (beginning of index) or EOI (end of index), or if
        there is some error (like it can't read the disk).

        The file cursor (current record pointer) is not changed.

Returns:
        Ok, BOI, EOI, or ERROR

EXAMPLE:
/* assumes existing database named "phonbook"; see EXAMPLE for icreate_db */

#include    "isam.h"

int main()
{
    Db_Obj      *phone_db;
    Index_Obj   *name_index;
    char        buffer[100];
    char        *fields[5];
    Rec_Len     record_length;
    int         i;

    phone_db = iopen_db("phonbook");
    if (phone_db == NULL) {
        iprterr();
        exit(1);
    }
    name_index = ihandle(phone_db, "name");

    /* get first record if less than 100 bytes */

    if (ifindhead(phone_db, name_index) != OK) {
        iprterr();
        exit(1);
    }
    if (igetreclen(phone_db, name_index, &record_length) == OK) {
        if (record_length < 100) {
            if (igetrec(phone_db, name_index, fields, buffer,
                        record_length) == OK) {

                printf("Field values of first record:\n");
                for (i=0;  fields[i] != NULL;  ++i)
                    printf("%s\n", fields[i]);
            }
            else
                iprterr();
        }
    }
    iclose_db(phone_db);
}

See Also: igetreclen igetfldcount icreate_db

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