__dbCopyXStruct()

Template

Function

Name

__dbCopyXStruct()

Category

API

Subcategory

Database

Oneliner

Copy current database structure into a definition file

Syntax

      __dbCopyXStruct( <cFileName> ) --> lSuccess

Arguments

<cFileName> is the name of target definition file to create. (.dbf) is the default extension if none is given.

Returns

__dbCopyXStruct() returns .F. if no database is USED in the current work-area, .T. on success, or a run-time error if the file create operation had failed.

Description

__dbCopyXStruct() create a new database named <cFileName> with a pre-defined structure (also called “structure extended file”):

       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

Each record in the new file contains information about one field in the original file. CREATE FROM could be used to create a database from the structure extended file.

For prehistoric compatibility reasons, Character fields which are longer than 255 characters are treated in a special way by writing part of the length in the FIELD_DEC according to the following formula (this is done internally):

      FIELD->FIELD_DEC := Int( nLength / 256 )
      FIELD->FIELD_LEN := ( nLength % 256 )

Later if you want to calculate the length of a field you can use the following formula:

      nLength := iif( FIELD->FIELD_TYPE == "C",  ;
                      FIELD->FIELD_DEC * 256 + FIELD->FIELD_LEN,  ;
                      FIELD->FIELD_LEN )

COPY STRUCTURE EXTENDED command is preprocessed into __dbCopyXStruct() function during compile time.

Examples

      // Open a database,  then copy its structure to a new file, 
      // Open the new file and list all its records
      USE Test
      __dbCopyXStruct( "TestStru" )
      USE TestStru
      LIST

Compliance

Clipper

Platforms

All

Files

Library is rdd

Seealso

COPY STRUCTURE, COPY STRUCTURE EXTENDED, CREATE, CREATE FROM, dbCreate(), dbStruct(), __dbCopyStruct(), __dbCreate()

3 responses to “__dbCopyXStruct()

  1. Pingback: Harbour Internal Functions | Viva Clipper !

  2. Pingback: Harbour Database Functions | Viva Clipper !

  3. Pingback: Harbour RG Summary | Viva Clipper !

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.