Get Previous (7)
The Get Previous operation (B_GET_PREVIOUS) retrieves the record in the logical previous position based on a specified key. You can use the Get Previous operation to retrieve a record within a group of records that have duplicate key values. You can use the
Get Key (+50)
bias to detect the presence of a value in a file. A Get Key operation is generally faster.
Parameters
Op Code
Pos Block
Data Buf
Data Buf Len
Key Buffer
Key Number
Sent
Returned
Prerequisites
•
The file must be open.
•
The file cannot be a data-only file.
•
Your application must have established a logical previous position based on the specified key.
Procedure
1
Set the Operation Code to 7. Optionally, you can include a lock bias:
•
+100—Single wait record lock.
•
+200—Single no-wait record lock.
•
+300—Multiple wait record lock.
•
+400—Multiple no-wait record lock.
For more information about locking, refer to the
Pervasive PSQL Programmer's Guide
.
2
Pass the Position Block for the file.
3
Set the Data Buffer Length to a value greater than or equal to the length of the record you want to retrieve.
4
Specify the key value from the previous operation in the Key Buffer. Pass the Key Buffer exactly as the transactional interface returned it on the previous call. The transactional interface may need the information previously stored in the Key Buffer to determine its current position in the file.
5
Set the Key Number parameter to the key path used on the previous call. You cannot change key paths using a Get Previous operation.
Result
If the Get Previous operation is successful, the transactional interface updates the Key Buffer with the key value for the previous record, returns the previous record in the Data Buffer, and returns the length of the record in the Data Buffer Length parameter.
If the Get Previous operation is unsuccessful, the transactional interface returns one of the following status codes:
3
The file is not open
6
The key number parameter is invalid
7
The key number has changed
8
The current positioning is invalid
9
The operation encountered the end-of-file
22
The data buffer parameter is too short
82
The transactional interface lost positioning
This operation returns Status Code 9 if the logical previous position points beyond the beginning of the file.
Positioning
The Get Previous operation establishes the complete logical and physical currencies and makes the retrieved record the current one.