Difference between revisions of "Dbcreat()"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
(5 intermediate revisions by 2 users not shown) | |||
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 */ |
− | + | 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 32: | Line 31: | ||
+ | <code lang="c"> | ||
typedef stuct { | typedef stuct { | ||
− | char fieldnm[11]]; | + | char fieldnm[11]]; /* Field name */ |
char type; /* Type of data in the field: | char type; /* Type of data in the field: | ||
− | + | 'C' = character | |
− | + | 'N' = numeric | |
− | + | 'L' = logical | |
− | + | 'D' = date | |
− | + | 'M' = memo */ | |
− | int width; | + | int width; /* Field width */ |
int dec; /* Number of decimal places | int dec; /* Number of decimal places | ||
− | (for numeric fields only) */ | + | (for numeric fields only) */ |
} dBFIELD; | } dBFIELD; | ||
+ | </code> | ||
+ | |||
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. | 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:- | + | 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 | + | Maximum Record Size = 4000 |
Maximum Numeric Size = 25 | Maximum Numeric Size = 25 | ||
Maximum Decimal Places = 14 | Maximum Decimal Places = 14 | ||
− | Maximum Number of Fields = | + | Maximum Number of Fields = 256 |
− | + | </pre> | |
==EXAMPLE== | ==EXAMPLE== | ||
Line 65: | Line 68: | ||
dBFIELD fields[6] = { | dBFIELD fields[6] = { | ||
"NAME", 'C', 20, 0, | "NAME", 'C', 20, 0, | ||
− | "SSN", | + | "SSN", 'N', 9, 0, |
"AMOUNT", 'N', 8, 2, | "AMOUNT", 'N', 8, 2, | ||
"RESIDENCY", 'L', 1, 0, | "RESIDENCY", 'L', 1, 0, | ||
Line 71: | Line 74: | ||
"COMMENT", 'C', 40, 0 | "COMMENT", 'C', 40, 0 | ||
} | } | ||
− | int rc; /* Return code | + | int rc; /* Return code */ |
rc = dbcreat("test.dbf", 6, fields); | rc = dbcreat("test.dbf", 6, fields); | ||
− | if ( | + | if (rc == SUCCESS) printf("database created \n"); |
else { | else { | ||
− | printf("error number %d n, rc); | + | printf("error number %d \n, rc); |
exit (1) | exit (1) | ||
} | } | ||
</code> | </code> | ||
− | |||
==SEE ALSO== | ==SEE ALSO== | ||
− | [[dbatofld | + | [[dbatofld()]], [[dbcreatx()]], [[dbfldtoa()]], [[dbgetf()]], [[dbgetr()]], [[dbgetfx()]], [[dbicreat()]], [[dbmcreat()]] |
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:Library]] | [[Category:Library]] |
Latest revision as of 11:34, 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 = 256
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()