dbxDataEvent_tableName_BeforeUpdateRowByKey

Function called before updating a row in the table.

Syntax

PUBLIC FUNCTION dbxDataEvent_tableName_BeforeUpdateRowByKey(
   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 Before 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 before updating a row in the database table. You can use this function if you are using a database for which constraints are missing, and where you cannot update the database schema. To preserve data integrity, you can implement constraints and referential integrity checks as if the schema was designed with them.

For example, you can check to ensure that the field value entered as a foreign key does exist in the related table.

Example: Before Update Row By Key

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

In this example, the function validates data before updating a row in the table. The user-defined function checkUpdateInventory is called to check the available quantity of the ordered item in the inventory table.

# officestore.4gl

-- import user-defined functions
IMPORT FGL myAccountFunc 

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

    DEFINE errNo INTEGER
    DEFINE errMsg STRING

    CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_lineitem_BeforeUpdateRowByKey (Table scope) is raised")
    CALL myAccountFunc.checkUpdateInventory(p_data) RETURNING errNo, errMsg
    CALL libdbappCore.log(C_LOG_INFO, "dbxDataEvent_lineitem_BeforeUpdateRowByKey (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.