18 The Text Driver : Defining Table Structure on Windows

Defining Table Structure on Windows
Because text files do not all have the same structure, the driver provides the option of defining the structure of an existing file. Although defining the structure is not mandatory (the driver can attempt to guess the names and types of the columns), this feature is extremely useful.
To define the structure of a file:
1
Display the ODBC Text Driver Setup dialog box through the ODBC Administrator. Click the Advanced tab; then, click Define to display the Define File dialog box.
The ODBC Text Driver Define File dialog box
2
Select the correct file and click Open to display the Define Table dialog box.
The ODBC Text Driver Define File dialog box
Database Name: This field displays the name of the database directory that you selected in the Define File dialog box.
File: This field displays the name of the file that you selected in the Define File dialog box.
Table: Type a table name in the Table field. This name specifies the table name associated with the text file you selected earlier. The name can be a maximum of 32 characters and must be unique. This name is returned by SQLTables. By default, it is the file name without its extension (for example, Trc_read).
Column Names in First Line: Select this check box if the first line of the file contains column names; otherwise, do not select this box.
Table Type: Select the type of text file, either comma, tab, fixed, character, or stream.
Delimiter Character: If the table type is Character, type the delimiter used in character-separated files. The value can be any printable character except single and double quotes.
Decimal Symbol: Type the decimal separator used when data is stored. Valid values are a comma or a period. The international decimal symbol (.) must be used in DML statements and parameter buffers.
3
If you specified a comma-separated, tab-separated, or character-separated type in the Table Type field, the Guess/Parse button displays Guess. Click Guess to have the driver guess at the column names and display them in the list box of the Column Information pane.
If you specified a fixed-length or stream type in the Table Type field, the Guess/Parse button displays Parse. Click Parse to have the driver display the Parse Table dialog box and define the table columns.
The ODBC Text Driver Parse Table dialog box
This dialog box displays the first line of the file. You must mark where each field begins and ends by enclosing it in square brackets [ ]. These brackets indicate the position and length of each field value in the record. Click OK to close the Parse Table dialog box. The driver will suggest column names in the list box of the Column Information pane.
4
If you do not want the driver to guess or parse, enter values in the following fields to define each column. Click Add to add the column name to the Column Information box.
Name: Type the name of the column.
Type: Select the data type of the column. If the field type is Date, the Mask field is enabled and you must select a date mask or type one in. See “Date Masks” for more information.
Mask: Select a date mask. If you selected Date for the Type field, you must select a date mask for the field or type one in. See “Date Masks” for more information.
Precision: Type the precision of the column. The precision of numeric data types is defined as the maximum number of digits used by the data type of the column. For character types, this is the length in characters of the data. Note that the precision and scale values determine how numeric data is to be returned.
Scale: Type the scale of the column. The scale of numeric data types is defined as the maximum number of digits to the right of the decimal point. Note that the precision and scale values determine how numeric data is to be returned.
Length: If you specified a fixed-length table type, type the length, which is the number of bytes the data takes up in storage.
Offset: If you specified a fixed-length table type, type the offset, which is the number of bytes from the start of the table to the start of the field.
5
To modify an existing column definition, select the column name in the Column Information box. Modify the values for that column name; then, click Modify.
6
7
Click OK to define the table.