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:
p_key
. This is aRECORD
type defined in the common file (my_entity_common.4gl). It contains the unique key fields from the schema of the database table.
- 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 code to record the executed action in a log table.
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
has been deleted.
PUBLIC FUNCTION dbxDataEvent_lineitem_AfterDeleteRowByKey(p_key lineitem_pk)
RETURNS (INTEGER)
DEFINE errNo INTEGER
DISPLAY "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
LET errNo = libdbappCore.ERROR_SUCCESS
END IF
DISPLAY "dbxDataEvent_lineitem_AfterDeleteRowByKey (Table scope) is exited"
RETURN errNo
END FUNCTION