A DDO delete is performed by send Request_Delete to a DDO. In some cases, you will use objects such as data-entry object (DEOs) to handle the entire delete for you. In other cases, you will need to write custom code to perform the delete. In all cases, the delete process itself is the same.
The Request_Delete message is responsible for deleting a record in the DDO for the main table, updating all parent DDOs (and tables) and possibly deleting all child records.
Two modes of deleting are supported:
A delete will delete all related descendant records.
A deletes will not be allowed when child records exist.
The property Cascade_Delete_State controls this message.
If Cascade_Delete_State is true, Request_Delete will attempt to delete the DDO’s record and all descendant records as follows:
Verify that the DDO structure is valid for the cascade delete operation.
Begin Transaction – From this point on tables are locked (if the database uses table locking) or records are locked as they are found (if the database uses record locking).
Re-Find all required records.
Get Validate_Delete of the main DDO.
if validation fails, cancel operation
Delete all related descendant records. For each child record:
Send Deleting to the child DDO.
Send Backout to all parent DDOs.
Attach and Save all parent tables (Attach_Main_File, Save_Main_File)
Delete the child record (Delete_Main_File)
Delete the record of the main DDO
Send Deleting to the main DDO.
Send Backout to all parent DDOs.
Attach and Save all parent tables (Attach_Main_File, Save_Main_File)
Delete the main record (Delete_Main_File)
End Transaction – either commit changes or roll back changes. Unlock tables.
If delete was successful, send Refresh all participating DEOs.
If Cascade_Delete_State is false, Request_Delete will not allow users to delete a record when a child-file record(s) exists as follows:
Deletes when Cascade_Delete_State is false:
Verify that the DDO structure is valid for the no-cascade delete operation.
Begin Transaction – From this point on tables are locked (if the database uses table locking) or records are locked as they are found (if the database uses record locking).
Re-Find all required records.
Get Validate_Delete of the main DDO.
if validation fails, cancel operation
Check for any child records or closed tables (get Validate_Delete_No_Cascade)
if validation fails, cancel operation
Send Deleting to the main DDO.
Send Backout to all parent DDOs.
Attach and Save all parent tables (Attach_Main_File, Save_Main_File)
Delete the main record (Delete_Main_File)
End Transaction – either commit changes or roll back changes. Unlock tables.
If delete was successful, send Refresh all participating DEOs.
If an error occurs anywhere within a delete, the transaction is rolled back, the database is unlocked and the error is reported.
Most often the error will occur within the Validate_Delete event and will be a “controlled” error (i.e., an error purposefully created by the programmer). This must be a real DataFlex error generated using the UserError message or the Error command. The generation of an error is what triggers a transaction rollback. The reporting of the error will be properly deferred until the transaction is rolled back and your database is unlocked.
Although Validate_Delete is the event specifically created to allow you to perform one last validation, you may stop a transaction within any of the delete events (Deleting, Backout, Delete_Main_File, Attach_Main_File, Save_Main_File). If you generate an error, the transaction will be rolled back.