| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Creates an empty database from a structure definition array.
DbCreate( <cDatabase> , ;
<aStructure>, ;
[<cDriver>] , ;
[<lNewArea>] , ;
[<cAlias>] ) --> NIL
The following #define constants exist in file DBSTRUCT.CH to address each column of <aStructure>.
#define constants for the structure definition array
| Constant | Value | Meaning |
|---|---|---|
| DBS_NAME | 1 | Field name |
| DBS_TYPE | 2 | Field type |
| DBS_LEN | 3 | Field length |
| DBS_DEC | 4 | Field decimals |
Note: only the first four columns of <aStructure> are used. If the array has more columns, they are ignored.
Open modes for new database files
| Value | Description |
|---|---|
| NIL (*) | the database is not opened. |
| .F. | the database is opened in the current work area. |
| .T. | the database is opened in a new, unused work area. |
| (*) default | |
The return value is always NIL.
This function creates the database file specified as <cDatabase> from the two-dimensional array <aStructure>. If no file extension is included with <cDatabase> the .DBF extension is assumed. The array specified with <aStructure> must contan at least four columns as outlined above.
The DbCreate( ) function does not use the decimal field to calculate the length of a character field that can store than 256 characters. Values of up to the maximum length of a character field, which is 65,519 bytes, can be assigned directly to the DBS_LEN column of <aStructure>.
The <cDriver> parameter specifies the name of the Replaceable Database Driver to use for database creation. If not specified, the return value of RddSetDefault() is used.
The <lOpenNew> parameter specifies if the already created database is to be opened, and where. If NIL, the file is not opened. If .T. (true), it is opened in a new work area, and if .F. (false) it is opened in the current work area, closing any file already occupying that area.
The <cAlias> parameter specifies the alias name for the newly opened database.
| See also: | AFields(), COPY STRUCTURE EXTENDED, CREATE, CREATE FROM, DbStruct() |
| Category: | Database functions |
| Header: | Dbstruct.ch |
| Source: | rdd\dbcmd.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example shows how to create a new database from a
// structure definition array using the DBFCDX driver.
REQUEST DBFCDX
PROCEDURE Main()
LOCAL aStruct := { ;
{ "CHARACTER", "C", 25, 0 }, ;
{ "NUMERIC" , "N", 8, 0 }, ;
{ "DOUBLE" , "N", 8, 2 }, ;
{ "DATE" , "D", 8, 0 }, ;
{ "LOGICAL" , "L", 1, 0 }, ;
{ "MEMO1" , "M", 10, 0 }, ;
{ "MEMO2" , "M", 10, 0 } ;
}
DbCreate( "testdbf", aStruct, "DBFCDX", .T., "MYALIAS" )
Browse()
RETURN
http://www.xHarbour.com