DBListFields -- Retrieve the field definitions from a database |
DBListFields() |
Managing Database Files |
You may occasionally wish to examine the fields in a database--their names, the types of data they contain, and their sizes, etc. FileFlex provides a function that allows you to retrieve such information about the currently active database file, if you wish. You can obtain a list of all of the fields in the current database file with the FileFlex DBListFields function. Since it operates on the current database, you must first call the DBSelect function to make the desired database current if it is not already. The field list is returned in the variable or container you specify. The format for the field list devotes one line to each field, except for the first line, which contains a number indicating the number of fields in the file. Each line of the variable, or container, describes a field as follows: field name, field type, field width, decimal places The field type can be any of the values shown below: ABBREVIATION FIELD TYPE N numeric C character M memo L logical D date The DBListFields function's result should be placed into a variable or field so that you can later use it to relate field names and content types to field numbers. In the following example, the first line makes the database whose name you supply as a parameter the current database, and the next one puts a list of its fields into a card field called "DBFields". put DBSelect(databaseID) into dbResult put DBListFields() into field "DBFields" The first line of "DBFields" will contain the number of fields in the file. All subsequent lines will contain each field's name, type, width, decimal places as a comma-delimited list. From the above example, the field named "DBFields" would contain the following information, assuming this is the structure of the file being examined: Name,C,20,0 Salary,N,10,2 Single,L,1,0 Note,M,10,0
|
Even non-numeric fields contain exactly four items in their field descriptions, including the number of decimal places (which will always be zero for non-numeric fields). Be forewarned that this is NOT the same structure as required by DBCreate. |
29
|