dataEvent_record_AfterDeleteRow
Function called after deleting a row.
Syntax
PUBLIC FUNCTION dataEvent_record_AfterDeleteRow(
errNo INTEGER,
errMsg STRING,
uniqueKey record-type )
RETURNS (INTEGER, STRING)
The function has these parameters:
errNo
. This is anSQLCA.SQLCODE
error.errMsg
. This is theSQLERRMESSAGE
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.
- An integer is returned 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 Cascade delete error ERROR_DELETE_CASCADE_ROW_USED
- 4 - A string is returned with the
SQLERRMESSAGE
error message.
Usage
When you select the After Delete Row property for the creation of the event, a function shell is created. Enter your code in the function.
This function is called after deleting a row in the database. For example, you can use this function to write the row of data to a log table before the row is deleted.
Example: AfterDeleteRow
This example uses the After Delete Row code event for the Account table in the OfficeStore demo.
In the example a row of data referenced by the variable uniqueKey
is written to
a log table. It is assumed that you have created the log table before saving the row to it.
The log table in the example has the following schema:
- an "id" field that is auto incremented
- a "date" timestamp field to record the date and time of the operation
- a "type" field to record the operation (Update/Insert/Delete)
- a "data" field to record a copy of all field values from the account table
PUBLIC FUNCTION dataEvent_recAccount_AfterDeleteRow(errNo INTEGER, errMsg STRING,
uniqueKey recAccount_br_uk_type)
RETURNS (INTEGER, STRING)
DEFINE log RECORD LIKE log.*
DEFINE l_data RECORD LIKE account.*
DISPLAY "dataEvent_recAccount_AfterDeleteRow (Row scope) is raised"
SELECT * INTO l_data.* FROM account WHERE @userid = uniqueKey.account_userid
LET log.id = NULL
LET log.date = util.Datetime.getCurrentAsUTC()
LET log.type = C_ACTION_DELETE
LET log.data = uniqueKey.account_userid, " email=", l_data.email,
"firstname=", l_data.firstname
TRY
INSERT INTO log VALUES log.*
CATCH
LET errNo = ERROR_FAILURE
LET errMsg = " - AfterDeleteRow failed to insert log ", log.*
END TRY
DISPLAY "dataEvent_recAccount_AfterDeleteRow (Row scope) is exited"
RETURN errNo, errMsg
END FUNCTION