|
<< Click to Display Table of Contents >> Field maps |
![]() ![]()
|
Because no description of the fields is available when a text file is created, it is a good practice to set a field map on the cursor that is opened on that text file. The text driver uses this field map to interpret the data types of the fields in that text file.
When you open a text table, you can provide the field descriptor information by using the DbiSetFieldMap call. dBASE, FoxPro, Access, and Paradox go through the following steps in setting the field description information for a text table.
| 1. | Obtains the field descriptors of the source/target table by using the function call DbiGetFieldDescs. |
| 2. | Obtains equivalent physical field descriptors of the text driver by using the call DbiTranslateRecordStructure. |
| 3. | Sets the field descriptor information on the text table by using the call DbiSetFieldMap. |
If no field maps are set, the following behavior is expected:
The text file exists and has records:
Fixed-length Text |
Delimited Text |
iFlds = 1 |
iFlds = Calculated using the first record |
fldType = CHAR |
fldType = CHAR |
fldLen = Calculated using first record |
fldLen= (4k/iFlds) && less than 255. |
The text file does not exist and has no records:
Fixed -length Text |
Delimited Text |
iFlds = 1 |
iFlds = 1 |
fldType = CHAR |
fldType = CHAR |
fldLen = 255 |
fldLen = 255 |
When a field map is set on a cursor that is opened as a text table, the source field descriptors (or destination field descriptors when importing) must be converted into text driver type descriptors. This step is necessary because some data types (for example, DBIDATE) have different field lengths in different driver types (for example, in Paradox, a DATE field is of four bytes long, while in dBASE a DATE field is eight bytes long).
The DbiTranslateRecordStructure call can be used to convert the logical or physical fields of a given driver type (that is, Paradox, dBASE, FoxPro, or Access) to the physical fields of the text driver. Then those physical text fields should be used in the DbiSetFieldMap call. When a field map is set on a text table, the iFldType, iFldNum, iUnits1, iUnits2 and iLen elements should be set correctly in all the field descriptors.
| Note: | The Text driver supports files with field names in the first record because many applications export ASCII files with field names in the first line. |
After a field map is set on the Text driver, DbiBatchMove can be used to import and export data to and from the text files.
Alternatively, you can bind schema information to a text table by storing the schema information of that text table in another text file. See Binding External Schema to Text Tables