...MENU

AFields()

This function puts information about table structure into an array. Read it as "Array from fields." In Visual FoxPro, this function returns a lot more information than in previous FoxPro versions.

Usage

nFieldCount = AFIELDS( ArrayName [, cAlias | nWorkarea ] )

Parameter

Value

Meaning

ArrayName

Array Name

The array to hold table structure information.

cAlias

Character

The alias of the table whose structure information is placed in ArrayName.

Omitted

If nWorkarea is also omitted, use current work area.

nWorkarea

Numeric

The number of the work area containing the table whose structure information is placed in ArrayName.

Omitted

If cAlias is also omitted, use current work area.

nFieldCount

Positive number

The number of rows in the array, which is the number of fields in the specified table.


In VFP 5 and later, the resulting array has 16 columns. In VFP 3, the array has only the first 11 of these columns.

Column

Type

Meaning

1

Character

Field name.

2

Single Character

Field type (see TYPE() for a list of field types).

3

Numeric

Field size.

4

Numeric

Decimal places.

5

Logical

Nulls allowed?

6

Logical

Code page translation NOT allowed?

7

Character

Field Validation rule (from DBC).

8

Character

Field Validation text (from DBC).

9

Character

Field Default value (from DBC).

10

Character

Table Validation rule (from DBC).

11

Character

Table Validation text (from DBC).

12

Character

Long table name (from DBC).

13

Character

Insert Trigger expression (from DBC).

14

Character

Update Trigger expression (from DBC).

15

Character

Delete Trigger expression (from DBC).

16

Character

Table Comment (from DBC).


The sixth column indicates whether code page translation is allowed, but it uses a sort of double negative. In other words, this column is .T. if the field has the NOCPTRANS attribute, which happens if you define it as Character (binary) or Memo (binary). TYPE() doesn't supply this information, so you need to use either AFIELDS(), COPY STRUCTURE EXTENDED or SET("NOCPTRANS") to find out which fields have this attribute. All the columns from 10 to the end contain table-level information and are filled in only for the first field of the table (the first array row). We're not really sure why this information is returned by AFIELDS() at all. DBGETPROP() returns the information, so it's already available, though not in array form. We guess it's to make it possible to use AFIELDS(), followed by CREATE TABLE with the FROM ARRAY clause.

As discussed in "DBF, FPT, CDX, DBC—Hike!," tables that contain nullable fields also have a hidden system field called _NullFlags. Note that this field is not returned by AFIELDS() (it wouldn't be very well hidden if it was, now, would it?) and therefore routines that think they can add the values returned from AFIELDS() to calculate the size of a DBF will break. Check out RECSIZE() instead.

The same array is created for a free table as for a table contained in a database, but the columns marked "(from DBC)" in the table above are empty, in that case.

Example

SELECT Customer = AFIELDS(aCustFlds)  && structure array for Customer USE MyTable IN 0 = AFIELDS(aMyStruc, "MyTable")  && structure array for MyTable

See Also

ADatabases(), ADBObjects(), ADir(), Array Manipulation, Copy Structure Extended, Create Table, DBGetProp(), FCount(), FSize(), RecSize(), Set NoCPTrans, Type()


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net