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

Purpose:    add a new record to a database

Prototype:  int iaddrec(Db_Obj *db,Index_Obj *index,char *fields[]);

Header:     isam.h

Inputs:     db      - database handle
            index   - index handle or NULL
            fields  - array of pointers to field values

Description:
        iaddrec adds a new record to the database referenced by the
        database handle db.  All indexes to the database are automatically
        updated to know about the new record.

        If index is NULL, the current record pointer is not changed.  If
        an index handle is specified, the current record pointer of the
        specified index ONLY is set to the record just added.  The current
        record pointer of other indexes is not changed.

        The fields array is the record to be added.  Each element of the
        array is a pointer to the field value for the corresponding field.
        Each field value is a string of arbitrary bytes (usually text)
        terminated by a binary zero byte.  The list of field pointers need
        not be terminated by a NULL pointer, but it won't hurt.

        Duplicate keys are allowed, but iaddrec does not detect duplicate
        records.

Returns:    OK or ERROR

Example:
/* Assumes existing database named "phonbook"; see EXAMPLE for icreate_db */
#include    "isam.h"

char    *a_record [] = {
        "Michael",
        "(214) 555-1234",
        "Dallas",
        NULL
};


int main ()
{
    Db_Obj  *phone_db;

    phone_db = iopen_db ("phonbook");
    if (phone_db != NULL) {
        /* add a record, don't change the currenct record */

        if (iaddrec(phone_db, NULL, a_record) == OK)
            printf("Added one record\n");
        else
            iprterr();

        iclose_db (phone_db);
    }
}

See Also: icreate_db iopen_db iprterr

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