dbxDataEvent_tableName_AfterInsertRowByKey

Function called after inserting a row in the table.

Syntax

PUBLIC FUNCTION dbxDataEvent_tableName_AfterInsertRowByKey(
   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. 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
  2. A string is returned with the SQLERRMESSAGE error message.

Usage

When you select the After Insert 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 inserting 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 Insert Row By Key

This example uses the After Insert 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_AfterInsertRowByKey(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_AfterInsertRowByKey (Table scope) is raised")   
    SELECT qty INTO _qty FROM inventory WHERE @itemid = p_data.itemid
    LET errMsg = "Available quantity: " || _qty

    RETURN errNo, errMsg
END FUNCTION

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