__dbCreate()
Create structure extended file or use one to create new file
- Syntax
-
- __dbCreate( <cFileName>, [<cFileFrom>], [<cRDDName>], [<lNew>],
- [<cAlias>] ) --> lUsed
- Arguments
-
- <cFileName> is the target file name to create and then open. (.dbf) is the default extension if none is given.
- <cFileFrom> is an optional structure extended file name from which the target file <cFileName> is going to be built. If omitted, a new empty structure extended file with the name <cFileName> is created and opened in the current work-area.
- <cRDDName> is RDD name to create target with. If omitted, the default RDD is used.
- <lNew> is an optional logical expression, (.T.) opens the target file name <cFileName> in the next available unused work-area and makes it the current work-area. (.F.) opens the target file in the current work-area. Default value is (.F.). The value of <lNew> is ignored if <cFileFrom> is not specified.
- <cAlias> is an optional alias to USE the target file with. If not specified, alias is based on the root name of <cFileName>.
- Returns
-
- __dbCreate() returns (.T.) if there is database USED in the current work-area (this might be the newly selected work-area), or (.F.) if there is no database USED. Note that on success a (.T.) would be returned, but on failure you probably end up with a run-time error and not a (.F.) value.
- Description
-
- __dbCreate() works in two modes depending on the value of <cFileFrom>:
- 1) If <cFileFrom> is empty or not specified a new empty structure extended file with the name <cFileName> is created and then opened in the current work-area (<lNew> is ignored). The new file has the following structure:
Field name | Type | Length | Decimals |
|
FIELD_NAME | C | 10 | 0 |
FIELD_TYPE | C | 1 | 0 |
FIELD_LEN | N | 3 | 0 |
FIELD_DEC | N | 3 | 0 |
- The CREATE command is preprocessed into the __dbCopyStruct() function during compile time and uses this mode.
- 2) If <cFileFrom> is specified, it is opened and assumed to be a structure extended file where each record contains at least the following fields (in no particular order): FIELD_NAME, FIELD_TYPE, FIELD_LEN and FIELD_DEC. Any other field is ignored. From this information the file <cFileName> is then created and opened in the current or new work-area (according to <lNew>), if this is a new work-area it becomes the current.
- For prehistoric compatibility reasons, structure extended file Character fields which are longer than 255 characters should be treated in a special way by writing part of the length in the FIELD_DEC according to the following formula:
FIELD->FIELD_DEC := int( nLength / 256 )
FIELD->FIELD_LEN := ( nLength % 256 )
- CREATE FROM command is preprocessed into __dbCopyStruct() function during compile time and use this mode.
Examples
// CREATE a new structure extended file, append some records and
// then CREATE FROM this file a new database file
__dbCreate( "template" )
DBAPPEND()
FIELD->FIELD_NAME := "CHANNEL"
FIELD->FIELD_TYPE := "N"
FIELD->FIELD_LEN := 2
FIELD->FIELD_DEC := 0
DBAPPEND()
FIELD->FIELD_NAME := "PROGRAM"
FIELD->FIELD_TYPE := "C"
FIELD->FIELD_LEN := 20
FIELD->FIELD_DEC := 0
DBAPPEND()
FIELD->FIELD_NAME := "REVIEW"
FIELD->FIELD_TYPE := "C" // this field is 1000 char long
FIELD->FIELD_LEN := 232 // 1000 % 256 = 232
FIELD->FIELD_DEC := 3 // 1000 / 256 = 3
DBCLOSEAREA()
__dbCreate( "TV_Guide", "template" )
- Status
- Ready
- Compliance
-
- __dbCreate() works exactly as in CA-Clipper
- Platforms
-
- All
- Files
-
- Library is rdd
- See Also