xHarbour Reference Documentation > Command Reference |
Copies field information to a new database file.
COPY STRUCTURE EXTENDED TO <cDatabaseExt>
The COPY STRUCTURE EXTENDED command copies field information of the current work area into a new database file. Field information is stored in the records of the new file and can be retrieved using the following pre-defined field names and database structure:
Fields in a structure extended file
Position | Field name | Type | Length | Decimals |
---|---|---|---|---|
1 | FIELD_NAME | Character | 10 | 0 |
2 | FIELD_TYPE | Character | 1 | 0 |
3 | FIELD_LEN | Numeric | 3 | 0 |
4 | FIELD_DEC | Numeric | 4 | 0 |
A database of this structure is called "structure extended" since it stores structural information of a database in its records. The CREATE FROM database command can then be used to create a database file of this structure programmatically.
Note: The length of a field of type Character is calculated as the sum of FIELD_LEN plus 256 * FIELD_DEC. The maximum length, however, is limited to 64k. Use a MEMO field to store longer Character strings.
See also: | COPY STRUCTURE, CREATE, CREATE FROM, DbCopyExtStruct(), DbCreate(), DbStruct(), FieldName(), Type() |
Category: | Database commands |
Source: | rtl\dbstrux.prg |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The examples demonstrates a technique for changing the structure of // an existing database file at runtime. PROCEDURE Main LOCAL cOldFile := "Address.dbf" LOCAL cBackup := StrTran( cOldFile, ".dbf", ".bak" ) USE (cOldFile) COPY STRUCTURE EXTENDED TO Tmp USE Tmp EXCLUSIVE APPEND BLANK REPLACE FIELD->FIELD_NAME WITH "Newfield" REPLACE FIELD->FIELD_TYPE WITH "C" REPLACE FIELD->FIELD_LEN WITH 20 REPLACE FIELD->FIELD_DEC WITH 0 CLOSE Tmp RENAME (cOldFile) TO (cBackup) CREATE (cOldFile) FROM Tmp APPEND FROM (cBackup) CLOSE (cOldFile) ERASE Tmp.dbf RETURN
http://www.xHarbour.com