dataEvent_record_BeforeDeleteRow
Function called before deleting a row.
Syntax
PUBLIC FUNCTION dataEvent_record_BeforeDeleteRow(
uniqueKey record-type)
RETURNS (INTEGER, STRING, uniqueKey)
The function has this parameter:
uniqueKey
. This is aRECORD
type defined in the BAM-generated common file (my_entity_common.4gl). It includes the unique key fields from the schema of the database table.
- An integer with the
SQLCA.SQLCODE
error number. Codes are defined as constants in the libdbappSql and libdbappCore libraries. The errors that are relevant to this function are shown in Table 1.Table 1. SQLCA.SQLCODE Description Constant Value Success ERROR_SUCCESS
0 Failure ERROR_FAILURE
-1 - A string is returned with the
SQLERRMESSAGE
error message. uniqueKey
. This is aRECORD
type defined in the BAM-generated common file (my_entity_common.4gl). It includes the unique key fields from the schema of the database table.
Usage
When you select the Before Delete Row property for the creation of the event, a function shell is created. Enter your code in the function.
This function is called before deleting a row in the database. For example, you can use this function to write the row of data to a backup table before the row is deleted.
Example: BeforeDeleteRow
This example uses the Before Delete Row code event for the Account table in the OfficeStore demo.
The row of data referenced by the variable uniqueKey
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 dataEvent_recAccount_BeforeDeleteRow(uniqueKey recAccount_br_uk_type)
RETURNS (INTEGER, STRING, recAccount_br_uk_type)
DEFINE errNo INTEGER
DEFINE errMsg STRING
DISPLAY "dataEvent_recAccount_BeforeDeleteRow (Row scope) is raised"
TRY
INSERT INTO account_backup SELECT * FROM account
WHERE @account.userid = uniqueKey.account_userid
CATCH
DISPLAY "SQL ERROR: ", SQLCA.SQLCODE
LET errNo = ERROR_FAILURE
LET errMsg = " - BeforeDeleteRow failed to insert in backup "
END TRY
DISPLAY "dataEvent_recAccount_BeforeDeleteRow (Row scope) is exited"
RETURN errNo, errMsg, uniqueKey.*
END FUNCTION