PreviousBtrieve API Guide (9.1 revision 1) Next

Get Key (+50)

Show this topic in Library frames

The Get Key bias allows you to perform a Get operation without actually retrieving a data record. You can use Get Key to detect the presence of a value in a file. A Get Key operation is generally faster than its corresponding Get operation. You can use the Get Key operation with any of the following Get operations:

Parameters

The parameters are the same as those for the corresponding Get operation, except that the MicroKernel ignores the Data Buffer Length and does not return a record in the Data Buffer.

Prerequisites

The prerequisites for a Get Key operation are the same as those for the corresponding Get operation.

Procedure
  1. Set the parameters as you would for the corresponding Get operation. You do not need to initialize the Data Buffer Length.
  2. Set the Operation Code to the Get operation you want to perform, plus 50. For example, to perform a Get Key (+50) with the Get Equal operation (5), set the Operation code to 55.

The MicroKernel does not allow Delete or Update operations after a Get Key operation (+50). Before the MicroKernel performs Update or Delete operations, it compares the current usage count of the data page it intends to modify with the usage count of the data page when the record was read. To obtain the usage count, the MicroKernel must read the data page.

Because the Get Key operation does not read the data page, no usage count is available for comparison on the Update or Delete. The Update or Delete fails because the MicroKernel cannot perform its passive concurrency conflict checking without the compare. When the Update or Delete fails, the MicroKernel returns Status Code 8.

Result

If the MicroKernel finds the requested key, it returns the key value in the Key Buffer and Status Code 0. Otherwise, the MicroKernel returns a status code indicating why it cannot find the key value.

Positioning

The Get Key operation establishes the current positioning in a similar manner to the corresponding Get operation. However, when a Get Key operation involves a key that allows duplicates, the MicroKernel ignores the duplicate instances of the current retrieved key value. After a Get Key operation, the logical previous position points to the record containing the previous lesser key value. The logical next position points to the record with the next greater key value.

For example, assume you perform a Get Key/Get Equal operation (55) on a last name key that contains eight occurrences of Smith and a single Smythe. The logical next position does not point to the next Smith, but to Smythe.

Because a Get Key operation does not positively identify any one record, the MicroKernel does not allow an Update or Delete operation to follow a Get Key operation.


Chapter contents
Publication contents

Prev topic: Get Greater Than or Equal (9)
Next topic: Get Last (13)