The Btrieve product stores information in Btrieve data files. Inside each data file is a collection of records (described in detail in Records).
A record contains bytes of data. That data might represent an employees's name, ID, address, phone number, rate of pay, and so on.
For example, when an application retrieves the record for Cliff Jones, the information in the record might be displayed as follows:
Jones Cliff D 340873 2341 Baxter Austin TX 512-555-2345 2146.00
NOTE: The application, not Btrieve, is responsible for the actual appearance of the data in a record---that is, the format of the data on screen or in a report.
Btrieve sees this record (or any record) only as a collection of bytes; it does not recognize logically discrete pieces of information within a record. To Btrieve, no last name, first name, employee ID, and so on exist inside a record. The record is simply a collection of bytes.
For example, an application that inserts information into or retrieves information about Cliff Jones from the Btrieve file might specify that the fields in the record use a data structure based on the format shown in Table 8.
Table 8. Example Data Structure for a Sample Record
| Information in Record | Length in Bytes | Data Type |
|---|---|---|
Last name |
25 |
Null-terminated string |
First name |
25 |
Null-terminated string |
Middle initial |
1 |
Char (byte) |
Employee ID |
4 |
Long (4-byte integer) |
Street address |
30 |
Null-terminated string |
City |
25 |
Null-terminated string |
State |
11 |
Null-terminated string |
Phone number |
12 |
Null-terminated string |
Pay rate per month |
4 |
Long (4-byte integer) |
Inside the Btrieve file, however, this information comprising Cliff Jones' record would be stored as a collection of bytes.
The only discrete portions of information that Btrieve can recognize in a Btrieve file are keys (described in detail in Keys). An application (or user) can designate any collection of bytes in a record as a key.
Using Btrieve sorts records on the basis of the values in any specified key. Btrieve can also find a particular record based on a specified key value.
In the example shown in Table 8, the 25 bytes that contain the last name in each record might be designated as a key in the Btrieve file. The sample application could use the last name key to obtain a listing of all the employees named Smith, or it could obtain a listing of all employees and then display that listing, sorted by last name.
Keys also allow Btrieve to access information quickly. For each key defined in a Btrieve data file, Btrieve builds an index (described in detail in Indexes.) The index is stored inside the Btrieve data file itself and contains a collection of pointers (addresses or offsets) into the actual data within that file. A key value is associated with each pointer.
In the example shown in Table 8, the key "last name" has an index. Inside that index is a collection of last names: one last name for every employee. For every last name in the index, a pointer indicates where the information about that employee is located in the Btrieve data file.
Normally, when accessing or sorting information for an application, Btrieve does not search through all the data in its data file. Instead, it goes to the index, performs the search, and then manipulates only those records that meet the application's request.