Dbputr()

From Recital Documentation Wiki
Jump to: navigation, search

PURPOSE

put data record into a .DBF file


SYNOPSIS

#include "dbl.h"
 
	int	dbputr(dbf, recno, record)
 
	<input parameters>
	char	*dbf;		/* .DBF file descriptor */
	long	recno;	/* Record number */
	char	*record;	/* Address of a buffer where the record contents are stored */
 
	<output parameters>
	none


RETURN VALUE

The dbputr() function returns 0 for success, or < 0 if an error occurs. See the section on return code values for a detailed list of return codes.


DESCRIPTION

This function writes the contents of the record supplied in a user defined buffer to a .DBF file. The position of the record within the file is determined by the record number. All the records existing in the file starting from this position (if any) will be shifted down to create a space for the new record. For example, if the record to be written has the number 5, and 8 records have been previously written to the file, the 5th, 6th, 7th and 8th records will become 6th, 7th, 8th and 9th respectively. The new record becomes the 5th record.


EXAMPLE

The first example adds the 56th record whose contents are in the "char record[100]" to the .DBF file whose file descriptor is in "char *dbf".

#include "dbl.h"
 
	char	*dbf;			/* .DBF file descriptor */
	char	record[100];	/* Record buffer */
	int	rc;			/* Return code */
 
	rc = dbputr(dbf, (long) 56, record);
	if (rc == SUCCESS) printf("Record added \n");
	else {
		printf("error number %d \n", rc);
		exit (1);
	}


The second example adds a record to the end of the .DBF file. The function dbsize() is used to get the size of the .DBF file (the number of the last record).

#include "dbl.h"
 
	char	*dbf;			/* .DBF file descriptor */
	char	record[100];	/* Rrecord buffer */
	long	recno;		/* Record number */
	int	rc;			/* Return code */
 
	dbsize(dbf, &recno);
	rc = dbputr(dbf, recno + 1, record);
	if (rc == SUCCESS) printf("record added \n");
	else {
		printf("error number %d\n", rc);
		exit (1);
	}


SEE ALSO

dbappend(), dbfield(), dbflush(), dbgetr(), dbputm(), dbputrk(), dbrecin(), dbsize(), dbupdr()