dbxDataEvent_tableName_BeforeDeleteRowByKey
Function called before deleting a row in the table.
Syntax
PUBLIC FUNCTION dbxDataEvent_tableName_BeforeDeleteRowByKey(
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 Before 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 before attempting to delete a row in the database table. For example, you can use this function to write the row of data to a backup table before the row is deleted.
Example: Before Delete Row By Key
This example uses the Before Delete Row By Key code event for the Account table in the OfficeStore demo.
The row of data referenced by the variable p_key
is written to a backup table.
It is assumed that you have created the backup table for account before saving the row to it.
PUBLIC FUNCTION dbxDataEvent_account_BeforeDeleteRowByKey(p_key account_pk)
RETURNS (INTEGER)
DEFINE errNo INTEGER
CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_account_BeforeDeleteRowByKey (Table scope) is raised")
INSERT INTO account_backup SELECT * FROM account
WHERE @account.userid = p_key.account_userid
LET errNo = SQLCA.SQLCODE
CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_account_BeforeDeleteRowByKey (Table scope) is exited")
RETURN errNo
END FUNCTION
For more information on the libdbappCore.log()
function,
go to DBAPPDEBUG and the debug level API.