DBF GATHER()

From Recital Documentation Wiki
Revision as of 10:38, 30 March 2009 by Yvonnemilne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PURPOSE

Gather an array into a record


SYNONYM

api_dbf_gather()


SYNOPSIS

#include "dbapi.h"
 
char	*DBF_GATHER(fldbuf)
 
<input parameters>
char	fldbuf[ ];	/* Pointer to an array containing values to update from	*/
 
<output parameters>
none


DESCRIPTION

The DBF_GATHER() function will update the current record with the contents of the specified array. The number of array elements must match the number of fields in the database to be updated.

Recital converts the character array elements automatically to the data type of each field in the record. Memo and Blob fields are not updated with the DBF_GATHER() function, however an array element must still be defined for these fields.


EXAMPLE

The following example updates the second record in the "example.dbf" database from the specified array. See Appendix A for the data structure of "example.dbf".

#include "dbapi.h"
 
dbapi_dbf_gather()
{
    int	rc;
    int	element_no;
    char	*fldbuf[12];
    char	blob[5];
    char	byte[3];
    char	character[21];
    char	date[9];
    char	dfloat[11];
    char	integer[5];
    char	logical[2];
    char	number[11];
    char	memo[5];
    char	real[11];
    char	word[11];
    char	zoned[11];
 
    strcpy(blob,"blob");
    strcpy(byte,"2");
    strcpy(character, "Record number 2");
    strcpy(date, "19990112");
    strcpy(dfloat, "2.22");
    strcpy(integer, "2");
    strcpy(logical, "T");
    strcpy(number, "2.22");
    strcpy(memo, "memo");
    strcpy(real, "2.22");
    strcpy(word, "2.22");
    strcpy(zoned, "2.22");
 
    fldbuf[0] = blob;
    fldbuf[1] = byte;
    fldbuf[2] = character;
    fldbuf[3] = date;
    fldbuf[4] = dfloat;
    fldbuf[5] = integer;
    fldbuf[6] = logical;
    fldbuf[7] = number;
    fldbuf[8] = memo;
    fldbuf[9] = real;
    fldbuf[10] = word;
    fldbuf[11] = zoned;
 
    rc = COMMAND("use example");
    if (rc == 0) {
       DBF_GOTO(2);
 
       if (!DBF_ISEXCLUSIVE()) DBF_LOCKR(DBF_RECNO());
 
       rc = DBF_GATHER(fldbuf);
       rc = DBF_UPDATE();
 
       if (!DBF_ISEXCLUSIVE()) DBF_UNLOCKR(DBF_RECNO());
 
       COMMAND("use");
    }
 
    _retni(rc);
}


SEE ALSO

BLOB_UPDATE(), BLOB_WRITE(), DBF_APPEND(), DBF_READ(), DBF_RECBUFFER(), DBF_SCATTER(), DBF_SELECT(), DBF_UPDATE(), FIELD_UPDATE(), MEMO_UPDATE(), MEMO_WRITE()