xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

COPY STRUCTURE EXTENDED

Copies field information to a new database file.

Syntax

COPY STRUCTURE EXTENDED TO <cDatabaseExt>

Arguments

TO <cDatabaseExt>
This is name of the database file to create. It can include path and file extension. When no path is given, the file is created in the current directory. The default file extension is DBF. <cDatabaseExt> can be specified as a literal file name or as a character expression enclosed in parentheses.

Description

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
PositionField nameTypeLengthDecimals
1FIELD_NAMECharacter100
2FIELD_TYPECharacter10
3FIELD_LENNumeric30
4FIELD_DECNumeric40

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe