|
<< Click to Display Table of Contents >> Text driver |
![]() ![]()
|
The text driver allows BDE clients to access text files. The text driver allows BDE clients to access text data directly without first importing into a table format. By using this driver, the application developer can build a more efficient import/export utility. Filters can be set on the cursors that are opened on the text files to import/export only those records that satisfy the filter's criteria.
When you open a text table, you can provide the field descriptor information by calling the function DbiSetFieldMap to set a field map or you can bind external schema to text tables:
Creating a text file with DbiCreateTable
A text file can be created by using DbiCreateTable. The developer supplies only table name and driver type values in the CRTblDesc descriptor; the rest of the field values are ignored. DbiCreateTable creates a file with the given name; no field descriptions are necessary.
Opening, importing and exporting text files
DbiOpenTable can be used to open a text file for import/export. The file can be opened as a delimited text file or as a fixed length text file.
Example 1: Opening a delimited text file
In this example, the text file dBASE.txt is opened as a delimited text file. The quotation mark (") is the delimiter character and comma is the field separator character.
DbiOpenTable (hDb, "DBASE.TXT", "ASCIIDRV-\"-,", NULL, NULL, 0,
dbiREADWRITE, dbiOPENEXCL, xltNONE, FALSE, NULL, &hCursor);
The pszDriverType argument of DbiOpenTable is used to indicate the field separator and the delimiter characters. The field separator and delimiter characters are passed through the pszDriverType argument as shown below:
"ASCIIDRV-<Delimiterchar>-<FieldSeparator>"
The field separator character separates the text file field values. The delimited character surrounds the text field types (alphanumeric or character) in the text file.
Example 2: Opening a fixed length text file
In this example, the text file dBASE.txt is opened as a fixed length text file:
DbiOpenTable (hDb, "DBASE.TXT", "ASCIIDRV", NULL, NULL, 0,
dbiREADWRITE, dbiOPENEXCL, xltNONE, FALSE, NULL, &hCursor);
When opening a fixed-length text file, no delimiter and separator characters are passed along with the pszDriverType argument.