Advertisements
CREATE FROM Create a new .dbf file from a structure extended file ------------------------------------------------------------------------------ Syntax CREATE <xcDatabase> FROM <xcExtendedDatabase> [NEW] [ALIAS <xcAlias>] [VIA <cDriver>] Arguments <xcDatabase> is the name of the new database file to create from the structure extended file. <xcExtendedDatabase> is the name of a structure extended file to use as the structure definition for the new database file. Both of these arguments can be specified either as literal database file names or as character expressions enclosed in parentheses. If an extension is not specified, the default is .dbf. NEW opens <xcDatabase> in the next available work area making it the current work area. If this clause is not specified, <xcDatabase> is opened in the current work area. ALIAS <xcAlias> is the name to associate with the work area when <xcDatabase> is opened. You may specify the alias name as a literal name or as a character expression enclosed in parentheses. A valid <xcAlias> may be any legal identifier (i.e., it must begin with an alphabetic character and may contain numeric or alphabetic characters and the underscore). Within a single application, Clipper will not accept duplicate aliases. If this clause is not specified, the alias defaults to the database file name. VIA <cDriver> specifies the replaceable database driver (RDD) to use to process the current work area. <cDriver> is the name of the RDD specified as a character expression. If you specify <cDriver> as a literal value, you must enclose it in quotes. Description CREATE FROM produces a new database file with the field definitions taken from the contents of a structure extended file. To qualify as a structure extended file, a database file must contain the following four fields: Structure of an Extended File ------------------------------------------------------------------------ Field Name Type Length Decimals ------------------------------------------------------------------------ 1 Field_name Character 10 2 Field_type Character 1 3 Field_len Numeric 3 0 4 Field_dec Numeric 4 0 ------------------------------------------------------------------------ <xcDatabase> is automatically opened in the current work area after it is created. Notes . Data dictionaries: For data dictionary applications, you can have any number of other fields within the structure extended file to describe the extended field attributes. You may, for example, want to have fields to describe such field attributes as a description, key flag, label, color, picture, and a validation expression for the VALID clause. When you CREATE FROM, Clipper creates the new database file from the required fields only, ignoring all other fields in the extended structure. Moreover, Clipper is not sensitive to the order of the required fields. . Character field lengths greater than 255: There is one method for creating a character field with a length greater than 255 digits: - Specify the field length using both the Field_len and Field_dec fields according to the following formulation: FIELD->Field_len := <nFieldLength> % 256 FIELD->Field_dec := INT(<nFieldLength> / 256) Examples . This example is a procedure that simulates an interactive CREATE utility: CreateDatabase("NewFile") RETURN FUNCTION CreateDatabase( cNewDbf ) CREATE TmpExt // Create empty structure extended USE TmpExt lMore := .T. DO WHILE lMore // Input new field definitions APPEND BLANK CLEAR @ 5, 0 SAY "Name.....: " GET Field_name @ 6, 0 SAY "Type.....: " GET Field_type @ 7, 0 SAY "Length...: " GET Field_len @ 8, 0 SAY "Decimals.: " GET Field_dec READ lMore := (!EMPTY(Field_name)) ENDDO // Remove all blank records DELETE ALL FOR EMPTY(Field_name) PACK CLOSE // Create new database file CREATE (cNewDbf) FROM TmpExt ERASE TmpExt.dbf RETURN NIL . This example creates a new definition in a structure extended file for a character field with a length of 4000 characters: APPEND BLANK REPLACE Field_name WITH "Notes",; Field_type WITH "C",; Field_len WITH 4000 % 256,; Field_dec WITH INT(4000 / 256) Files Library is CLIPPER.LIB.
See Also: COPY STRUCTURE COPY STRU EXTE CREATE
Advertisements