Binding external schema to text tables

<< Click to Display Table of Contents >>

Navigation:  Application development > Database driver characteristics > Text driver >

Binding external schema to text tables

Previous pageReturn to chapter overviewNext page

Although you can set the field descriptors on text tables for use with export/import utilities, the BDE text driver can bind an external schema information to text tables. You bind schema information to a text table by storing the schema information of that text table in another text file.

The extension of the text file containing the schema information will be "sch". Thus, the name of the text file containing the schema information of the text table zzz.txt will be zzz.sch. If the text table has an extension other than "txt", extension of the schema file would still be "sch".

Schema File

All information in the schema file is case-insensitive.

Here is a sample schema file:

 

[CUSTOMER]                          // File name with no extension.

FILETYPE = VARYING                 // Format: VARYING or FIXED

CHARSET = ascii                        // Language driver name.

DELIMITER = "                        // Delimiter for char fields.

SEPARATOR = ,                        // Separator character 

Field1 = Name,CHAR,12,0,0        // Field information

Field2 = Salary,FLOAT,8,2,12                 

 

The schema file has a format similar to Windows INI files. The file begins with the name of the table in brackets. The second line specifies the file format following the keyword FILETYPE: FIXED or VARYING.

FIXED format file
Each field always takes up a fixed number of characters in the file, and the data is padded with blanks as needed.

VARYING format file
Each field takes a variable number of characters, each character field is enclosed by DELIMITER characters, and the fields are separated by a SEPARATOR character. The DELIMITER and SEPARATOR must be specified for a VARYING format file, but not for a FIXED format file.

The CHARSET attribute specifies the name of the language driver to use. This is the base filename of the .LD file used for localization purposes.

The DELIMITED character surrounds the text field types (alphanumeric or character) in the text file. Delimited fields must be of character type.

The field SEPARATOR character separates the text file field values.

The remaining lines specify the attributes of the table's fields (columns). Each line must begin with "Fieldx = ", where x is the field number (that is. Field1, Field2, and so on).

Next appears a comma-delimited list specifying:

Field name. Same restrictions as Paradox field names.

Data type. The field data type. See below.

Number of characters or units. Must be <= 20 for numeric data types. Total maximum number of characters for date/time data types (including / and : separators).

Number of digits after the decimal (FLOAT only).

Offset. Number of characters from the beginning of the line that the field begins. Used for FIXED and DELIMITED formats.

 

The following data types are supported:

CHAR      - Character

FLOAT     - 64-bit floating point

NUMBER    - 16-bit integer

BOOL      - Boolean (T or F)

LONGINT   - 32-bit long integer

DBIDATE   - Date field. Format specified in Registry

TIME      - Time field. Format specified in Registry

TIMESTAMP - Date/Time field. Format specified in Registry

Note: You specify date and time formats by using the BDE Administrator.

Example 1:  VARYING format file

CUSTOMER.SCH:

 

[CUSTOMER]

Filetype=VARYING

Delimiter="

Separator=,

CharSet=ascii

Field1=Customer No,Float,20,04,00

Field2=Name,Char,30,00,20

Field3=Phone,Char,15,00,145

Field4=First Contact,Date,11,00,160

 

CUSTOMER.TXT:

1221.0000,"Kauai Dive Shoppe","808-555-0269",04/03/1994

1231.0000,"Unisco","809-555-3915",02/28/1994

1351.0000,"Sight Diver","357-6-876708",04/12/1994

1354.0000,"Cayman Divers World Unlimited","809-555-8576",04/17/1994

1356.0000,"Tom Sawyer Diving Centre","809-555-7281",04/20/1994

All the BDE API functions work with the text driver. To support external schema binding, the text driver includes the database property dbUSESCHEMAFILE applicable only to the text driver.

If the dbUSESCHEMAFILE property is set to true at the time of an export to a text table, the schema information of that text table is stored in a schema file. The DbiBatchMove function is used in exporting data to a text file. DbiBatchMove automatically stores the schema information while copying the data to a text table.

If the dbUSESCHEMAFILE flag is set to TRUE at the time of an import and a schema file exists for the text table, the text driver gets the field descriptors from the schema text file and sets them as the default fields for that text table. If the dbUSESCHEMAFILE flag is not set, you should define the field descriptions of the text table by using the function DbiSetFieldMap.