Delete (4)
The Delete operation (B_DELETE) removes an existing record from a file. The space that the deleted record occupied is then available for inserting new records.
Parameters
Op Code
Pos Block
Data Buf
Data Buf Len
Key Buffer
Key Number
Sent
Returned
Prerequisites
•
The file must be open.
•
You have established physical or logical currency in the file. Operations that satisfy this requirement are Get (except extended Gets or Get Key), Step (except extended Steps), Insert, and Update.
Procedure
1
Set the operation code to 4.
2
Pass the position block of the file that contains the record to be deleted.
Details
The Delete operation is not a valid operation if performed immediately after an extended Get or extended Step operation.
After you perform a Delete operation, a later Get Next or Get Previous operation must use the same key number as the last operation that established logical position. If you use another value, the MicroKernel Engine returns Status Code 7.
The MicroKernel Engine does not allow Delete operations after a Get Key operation (+50). Before the MicroKernel Engine performs a Delete operation, 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 Engine 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 Delete. The Delete fails because the MicroKernel Engine cannot perform its passive concurrency conflict checking without the compare. When the Delete fails, the MicroKernel Engine returns Status Code 8.
Result
If the Delete operation is successful, the MicroKernel Engine removes the record from the file, releases the record lock (if one existed for the deleted record), and adjusts all key indexes to reflect the deletion.
If the Delete operation is unsuccessful, the MicroKernel Engine returns one of the following status codes:
8
The current positioning is invalid.
80
The MicroKernel Engine encountered a record-level conflict.
84
The record or page is locked.
85
The file is locked.
Delete operations never reduce file size. Empty Space created by deletion of records is reused when records are added in the future. Recovering disk space can only be done by recreating the file and inserting all the records into it.
Positioning
The Delete operation destroys the complete physical location information and the logical current record position but does not change the physical and logical positions of either the next record or the previous record.