COPY STRUCTURE

 

COPY STRUCTURE

Create a new database based on current database structure

Syntax

      COPY STRUCTURE TO <xcFileName> [FIELDS <field,...>]

Arguments

TO <xcFileName> is the name of the new database file to create. (.dbf) is the default extension if none is given. It can be specified as a literal file name or as a character expression enclosed in parentheses.

FIELDS <field, …> is an optional list of field names to copy from the currently open database in the specified order, the default is all fields. Names could be specified as uppercase or lowercase.

Description

COPY STRUCTURE create a new empty database file with a structure that is based on the currently open database in this work-area.

COPY STRUCTURE can be use to create a sub-set of the currently open database, based on a given field list.

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

Examples

      // Create a new file that contains the same structure
       USE TEST
       COPY STRUCTURE TO MyCopy

       // Create a new file that contains part of the original structure
       USE TEST
       COPY STRUCTURE TO SomePart FIELDS name, address

Compliance

Clipper

Platforms

All

Seealso

COPY STRUCTURE EXTENDED, DBCREATE(), DBSTRUCT(), __dbCopyStruct(), __dbCopyXStruct(), __dbCreate(), __dbStructFilter()

__FLedit()

Template

Function

Name

__FLedit()*

Category

API

Subcategory

Database

Oneliner

Filter a database structure array

Syntax

      __FLedit( <aStruct>,  [<aFieldList>] ) --> aStructFiltered

Arguments

<aStruct> is a multidimensional array with database fields structure, which is usually the output from dbStruct(), where each array element has the following structure:

       Position   Description    dbstruct.ch
       --------   -----------    -----------
       1          cFieldName     DBS_NAME
       2          cFieldType     DBS_TYPE
       3          nFieldLength   DBS_LEN
       4          nDecimals      DBS_DEC

<aFieldList> is an array where each element is a field name. Names could be specified as uppercase or lowercase.

Returns

__FLedit() return a new multidimensional array where each element is in the same structure as the original <aStruct>, but the array is built according to the list of fields in <aFieldList>. If <aFieldList> is empty, __FLedit() return reference to the original <aStruct> array.

Description

__FLedit() can be use to create a sub-set of a database structure, based on a given field list.

Note that field names in <aStruct> MUST be specified in uppercase or else no match would found.

SET EXACT has no effect on the return value.

__FLedit() is a compatibility function and it is synonym for __dbStructFilter() which does exactly the same.

Examples

      LOCAL aStruct,  aList,  aRet
      aStruct := { { "CODE",   "N",   4,  0 },  ;
                   { "NAME",   "C",  10,  0 },  ;
                   { "PHONE",  "C",  13,  0 },  ;
                   { "IQ",     "N",   3,  0 } }
      aList := { "IQ",  "NAME" }
      aRet := __FLedit( aStruct,  aList )
                        // { { "IQ",  "N",  3,  0 },  { "NAME",  "C",  10,  0 } }

      aRet := __FLedit( aStruct,  {} )
      ? aRet == aStruct // .T.

      aList := { "iq",  "NOTEXIST" }
      aRet := __FLedit( aStruct,  aList )
                        // { { "IQ",  "N",  3,  0 } }

      aList := { "NOTEXIST" }
      aRet := __FLedit( aStruct,  aList )   // {}

      // Create a new file that contain part of the original structure
      LOCAL aStruct,  aList,  aRet
      USE TEST
      aStruct := dbStruct()
      aList := { "NAME" }
      dbCreate( "onlyname.dbf",  __FLedit( aStruct,  aList ) )

Compliance

CA-Cl*pper has internal undocumented function named __FLedit(), in Harbour we name it __dbStructFilter(). The new name gives a better description of what this function does. In Harbour __FLedit() simply calls __dbStructFilter() and therefor the latter is the recommended function to use.

This function is only visible if src/rdd/dbstrux.prg was compiled with the HB_CLP_UNDOC flag.

Platforms

All

Files

Header file is dbstruct.ch
Library is rdd

Seealso

dbCreate(), dbStruct(), __dbCopyStruct(), __dbStructFilter()

__dbCopyStruct()

Template

Procedure

Name

__dbCopyStruct()

Category

API

Subcategory

Database

Oneliner

Create a new database based on current database structure

Syntax

      __dbCopyStruct( <cFileName>,  [<aFieldList>] )

Arguments

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

<aFieldList> is an array where each element is a field name. Names could be specified as uppercase or lowercase.

Description

__dbCopyStruct() create a new empty database file with a structure that is based on the currently open database in this work-area. If <aFieldList> is empty, the newly created file would have the same structure as the currently open database. Else, the new file would contain only fields that exactly match <aFieldList>.

__dbCopyStruct() can be use to create a sub-set of the currently open database, based on a given field list.

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

Examples

      // Create a new file that contain the same structure
      USE TEST
      __dbCopyStruct( "mycopy.dbf" )

      // Create a new file that contain part of the original structure
      LOCAL aList
      USE TEST
      aList := { "NAME" }
      __dbCopyStruct( "onlyname.dbf",  aList )

Compliance

Clipper

Platforms

All

Files

Library is rdd

Seealso

COPY STRUCTURE, COPY STRUCTURE EXTENDED, dbCreate(), dbStruct(), __dbCopyXStruct(), __dbCreate(), __dbStructFilter()