Navigation: Language Reference > 13 - Built-in Functions >====== DELETE (delete a record) ====== | |
DELETE( entity )
DELETE | Removes a record from a FILE, VIEW, or QUEUE structure. |
entity | The label of a FILE, VIEW, or QUEUE structure. |
The DELETE statement removes a record.
FILE Usage
DELETE(file) removes the last record successfully accessed by NEXT, PREVIOUS, GET, REGET, ADD, or PUT. The key entries for that record are also removed from the KEYs. DELETE does not clear the record buffer. Therefore, data values from the record just deleted still exist and are available for use until the record buffer is overwritten. If no record was previously accessed, or the record is held by another workstation, DELETE posts the “Record Not Available” error and no record is deleted.
VIEW Usage
DELETE(view) removes the last VIEW primary file record that was successfully accessed by a NEXTor PREVIOUS statement. The key entries for that record are also removed from the KEYs. DELETE does not remove records from any secondary JOIN files in the VIEW. If no record was previously accessed, or the record is held by another workstation, DELETE posts the “Record Not Available” error and no record is deleted. The specific disk action DELETE performs in the file is file driver dependent.
DELETE only deletes the primary file record in the VIEW because the VIEW structure performs both relational Project and Join operations at the same time. Therefore, it is possible to create a VIEW structure that, if all its component files were updated, would violate the Referential Integrity rules set for the database. The common solution to this problem in SQL-based database products is to delete only the Primary file record. Therefore, Clarion has adopted this same industry standard solution.
QUEUE Usage
DELETE(queue) removes the QUEUE entry at the position of the last successful GET or ADD and de-allocates its memory. If no previous GET or ADD was executed, the “Entry Not Found” error is posted. DELETE does not affect the current POINTER procedure return value, however, once the entry is deleted, the POINTER value for all subsequent entries in the QUEUE decrement by one (1).
If the QUEUE contains any reference variables or fields with the ANY data type, you must reference assign a NULL to each reference variable and ANY field in the queue structure before the DELETE statement. This will avoid memory leaks by freeing up the memory used by the ANY or reference variables before the DELETE statement.
If for any reason you plan to use DISPOSE on an object in a queue that was created with NEW, you must issue the DISPOSE before the DELETE statement is executed.
Errors Posted:
05 | Access Denied |
08 | Insufficient Memory |
30 | Entry Not Found |
33 | Record Not Available |
Example:
Customer FILE,DRIVER('Clarion'),PRE(Cus) !Declare customer file layout
AcctKey KEY(Cus:AcctNumber)
Record RECORD
AcctNumber LONG
Name STRING(20)
Addr STRING(20)
City STRING(20)
State STRING(20)
Zip STRING(20)
END
END
CustView VIEW(Customer) !Declare VIEW structure
PROJECT(Cus:AcctNumber,Cus:Name)
END
NameQue QUEUE,PRE(Que)
Name STRING(20),NAME('FirstField')
Zip DECIMAL(5,0),NAME('SecondField')
END
CODE
DO BuildQue !Call routine to build the queue
LOOP X# = RECORDS(NameQue) TO 1 BY -1 !Loop backwards thriough queue
GET(NameQue,X#) !geting each entry
ASSERT(NOT ERRORCODE())
IF NameQue.Name[1] = 'J' !Evaluate a condition
DELETE(NameQue) !and delete only specific entries
ASSERT(NOT ERRORCODE())
END
END
OPEN(Customer)
Cus:AcctNumber = 12345 !Initialize key field
SET(Cus:AcctKey,Cus:AcctKey)
OPEN(CustView)
NEXT(CustView) !Get that record
IF ERRORCODE()
STOP(ERROR())
END
DELETE(CustView) !Delete the customer record
CLOSE(CustView) !Close the VIEW
Cus:AcctNumber = 12345 !Initialize key field
GET(Customer,Cus:AcctKey) !Get that record
IF ERRORCODE() THEN STOP(ERROR()).
DELETE(Customer) !Delete the customer record
See Also: