Difference between revisions of "Dbcreat()"

From Recital Documentation Wiki
Jump to: navigation, search
(EXAMPLE)
Line 13: Line 13:
 
char *dbname; /* Address of the character string containing the name of the .DBF file to be created */
 
char *dbname; /* Address of the character string containing the 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 */
  
 
<output parameters>
 
<output parameters>
Line 51: Line 51:
 
NOTE:  When using dbcreat(), remember the record specifications of a .DBF file:-
 
NOTE:  When using dbcreat(), remember the record specifications of a .DBF file:-
  
 +
<pre>
 
Maximum File Name = 80 bytes
 
Maximum File Name = 80 bytes
 
Maximum Field Size = 254
 
Maximum Field Size = 254
Maximum Record Size = 4000
+
Maximum Record Size = 4000
 
Maximum Numeric Size = 25
 
Maximum Numeric Size = 25
 
Maximum Decimal Places = 14
 
Maximum Decimal Places = 14
 
Maximum Number of Fields = 128
 
Maximum Number of Fields = 128
 
+
</pre>
  
 
==EXAMPLE==
 
==EXAMPLE==
Line 75: Line 76:
 
int rc; /* Return code */
 
int rc; /* Return code */
 
rc = dbcreat("test.dbf", 6, fields);
 
rc = dbcreat("test.dbf", 6, fields);
if (rc == SUCCESS) printf('database created \n");
+
if (rc == SUCCESS) printf("database created \n");
 
else {
 
else {
 
printf("error number %d \n, rc);
 
printf("error number %d \n, rc);

Revision as of 11:33, 1 May 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 (rc == SUCCESS) printf("database created \n");
	else {
		printf("error number %d \n, rc);
		exit (1)
	}

SEE ALSO

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