DBF SCATTER()

From Recital Documentation Wiki
Jump to: navigation, search

PURPOSE

Copy record buffer to an array


SYNONYM

api_dbf_scatter()


SYNOPSIS

#include "dbapi.h"
 
int	DBF_SCATTER(fldbuf)
 
<input parameters>
none
 
<output parameters>
char	*fldbuf[];	/* A pointer to an array to hold the value of each field 	*/


DESCRIPTION

The DBF_SCATTER() function will scatter the contents of the current record into the specified array pointer.

The array elements to store the field values must be defined as characters strings as Recital will convert all the field data types to character strings. The contents of MEMO and BLOB fields are not copied into the array elements, instead the word "MEMO" is returned.


EXAMPLE

The following example scatters the contents of the first record in the "example" database to the array pointer "fldbuf". The array value specified by the first parameter passed to the "dbapi_dbf_scatter()" function is returned. See Appendix A for the data structure of the "example.dbf" database.

#include "dbapi.h"
 
dbapi_dbf_scatter()
{
    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[6];
    char	logical[2];
    char	number[11];
    char	memo[5];
    char	real[11];
    char	word[11];
    char	zoned[11];
 
    if (_parinfo(1) != API_NTYPE) _retc("");
 
    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;
 
    element_no = _parni(1)-1;
 
    rc = COMMAND("use example");
    if ( rc == 0) {
       if ((element_no+1) > FIELD_COUNT() || element_no < 0) {
       COMMAND("use");
       _retc("Array value out of bounds.");
       }
 
       rc = DBF_SCATTER(fldbuf);
       COMMAND("use");
    } else {
       strcpy(fldbuf[element_no], "");
    }
 
    _retc(fldbuf[ element_no]);
}


SEE ALSO

BLOB_READ(), DBF_APPEND(), DBF_GATHER(), DBF_READ(), DBF_RECBUFFER(), DBF_SELECT(), DBF_UPDATE(), FIELD_COUNT(), FIELD_UPDATE(), MEMO_MLINE(), MEMO_READ()