dbxDataEvent_tableName_AfterDeleteRowByKey

Function called after deleting a row in the table.

Syntax

PUBLIC FUNCTION dbxDataEvent_tableName_AfterDeleteRowByKey(
   p_key record-type)
   RETURNS (INTEGER)

The function has the following parameter:

  1. p_key. This is a RECORD type defined in the common file (my_entity_common.4gl). It contains the unique key fields from the schema of the database table.
It returns the following value:
  1. An integer specifying the SQLCA.SQLCODE error number. Codes are defined as constants in the libdbappSql and libdbappCore files in the libdbapp library. The errors that are relevant in this function are shown in the table.
    Table 1. SQLCA.SQLCODE
    Description Constant Value
    Success ERROR_SUCCESS 0
    Failure ERROR_FAILURE -1
    Cascade delete error ERROR_DELETE_CASCADE_ROW_USED - 4

Usage

When you select the After Delete Row By Key property for the creation of the event, a function shell is created. Enter your code in the function.

This function is called after attempting to delete a row in the database table. For example, you can check if the SQL operation to delete the row was successful, and revert any changes made to tables in the BeforeDeleteRowByKey function if not.

Example: After Delete Row By Key

This example uses the After Delete Row By Key code event for the lineitem table in the OfficeStore demo.

In this example, the function checks if the row of data referenced by the variable p_key is found in the table. If the row is not found, a message is displayed that the delete was successful.

 PUBLIC FUNCTION dbxDataEvent_lineitem_AfterDeleteRowByKey(p_key lineitem_pk)
    RETURNS (INTEGER)
    
    DEFINE errNo INTEGER
    CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_lineitem_AfterDeleteRowByKey (Table scope) is raised")
  
    SELECT * FROM lineitem WHERE @orderid = p_key.lineitem_orderid 
       AND @linenum = p_key.lineitem_linenum
   
    IF SQLCA.SQLCODE == NOTFOUND THEN
         -- the delete succeed
        MESSAGE "Delete succeeded"
    END IF
    CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_lineitem_AfterDeleteRowByKey (Table scope) is exited")
    
    RETURN errNo
END FUNCTION

For more information on the libdbappCore.log() function, go to DBAPPDEBUG and the debug level API.