Difference between revisions of "Dbcreat()"

From Recital Documentation Wiki
Jump to: navigation, search
Line 11: Line 11:
  
 
<input parameters>
 
<input parameters>
char *dbname; /* Address of the character string containing the
+
char *dbname; /* Address of the character string containing the name of the .DBF file to be created */
name of the .DBF file to be created */
+
 
int nfields; /* Number of fields per record */
 
int nfields; /* Number of fields per record */
 
dBFIELD fields[]; /* Address of an array of fields definitions */
 
dBFIELD fields[]; /* Address of an array of fields definitions */

Revision as of 11:08, 2 April 2009

PURPOSE

create a database file


SYNOPSIS

#include "dbl.h"
 
	int	dbcreat(dbname, nfields, fields)
 
	<input parameters>
	char	*dbname;	/* Address of the character string containing the name of the .DBF file to be created	*/
	int	nfields;		/* Number of fields per record		*/
	dBFIELD fields[];	/* Address of an array of fields definitions	*/
 
	<output parameters>
	none


RETURN VALUE

The dbcreat() 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 creates a .DBF file. The structure dBFIELD is defined in the header file <dbl.h> as follows:-


typedef stuct {
	char 	fieldnm[11]];		/* Field name			*/
	char	type;			/* Type of data in the field:
					'C'	= character
					'N'	= numeric
					'L'	= logical
					'D'	= date
					'M'	= memo		*/
	int	width;			/* Field width */
	int	dec;			/* Number of decimal places
					(for numeric fields only)	*/
} dBFIELD;


An array of dBFIELD structure defines the organization of each record in the database. The array must be initialized and a pointer to it must be passed to dbcreat. All the structure's numbers must be set to appropriate values. If the name file already exists, this function will reinitialize the file.

NOTE: When using dbcreat(), remember the record specifications of a .DBF file:-

Maximum File Name = 80 bytes Maximum Field Size = 254 Maximum Record Size = 4000 Maximum Numeric Size = 25 Maximum Decimal Places = 14 Maximum Number of Fields = 128


EXAMPLE

The following example creates a .DBF file with the name 'TEST.DBF' whose records consist of 6 fields defined in "dBFIELD fields[6]".

#include "dbl.h"
	dBFIELD fields[6] = {
		"NAME",		'C',	20,	0,
		"SSN",			'N',	9,	0,
		"AMOUNT",		'N',	8,	2,
		"RESIDENCY",	'L',	1,	0,
		"BIRTHDATE",	'D',	8,	0,
		"COMMENT",	'C',	40,	0
	}
	int	rc;	/* Return code		*/
	rc = dbcreat("test.dbf", 6, fields);
	if (re = = SUCCESS) printf('database created n");
	else {
		printf("error number %d n, rc);
		exit (1)
	}


SEE ALSO

dbatofld(), dbcreat(), dbcreatx(), dbfldtoa(), dbgetf(), dbgetr(), dbgetfx(), dbicreat(), dbmcreat()