dbxDataEvent_tableName_AfterUpdateRowByKey

Function called after updating a row in the table.

Syntax

PUBLIC FUNCTION dbxDataEvent_tableName_AfterUpdateRowByKey(
   p_data record-type)
   RETURNS (INTEGER, STRING)

The function has the following parameter:

  1. p_data. This is a RECORD type defined according to the structure of the database table.
It returns the following values:
  1. An integer specifying the SQLCA.SQLCODE error number. Codes are defined as constants in the libdbappSql and libdbappCore files in the libdbapp library. If the code is a negative number, an SQL error has occurred. 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
    Concurrent access failure ERROR_CONCURRENT_ACCESS_FAILURE -2
    Concurrent access not found ERROR_CONCURRENT_ACCESS_NOTFOUND -3
  2. A string is returned with the SQLERRMESSAGE error message.

Usage

When you select the After Update 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 updating a row in the database table. Use this event for administration tasks, such as updating what might otherwise be performed in SQL triggers.

Note:

It is recommended to avoid duplicating a SQL trigger in the database. If a database trigger exists, there is no need to use this function.

Example: After Update Row By Key

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

In this example, the function returns a message with the quantity of the item in the inventory table.

PUBLIC FUNCTION dbxDataEvent_lineitem_AfterUpdateRowByKey(p_data RECORD LIKE lineitem.*)
    RETURNS (INTEGER, STRING)

    DEFINE errNo INTEGER
    DEFINE errMsg STRING
    DEFINE _qty INTEGER

    CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_lineitem_AfterUpdateRowByKey (Table scope) is raised")
  
    SELECT qty INTO _qty FROM inventory WHERE @itemid = p_data.itemid
    LET errMsg = "Available quantity: " || _qty

    CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_lineitem_AfterUpdateRowByKey (Table scope) is exited")

    RETURN errNo, errMsg
END FUNCTION

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