dataEvent_record_BeforeDeleteRowWithConcurrentAccess

Function called before deleting a row with concurrent access.

Syntax

PUBLIC FUNCTION dataEvent_record_BeforeDeleteRowWithConcurrentAccess( 
   p_dataT0 record-type)
   RETURNS (INTEGER, STRING, record-type)

The function has one parameter:

  1. p_dataT0. This is a RECORD containing a row of data. It is defined according to the structure of the database table.
It returns 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.
  3. record-type. This is a RECORD type defined according to the structure of the database table.

Usage

When you select the Before Delete Row With ConcurrentAccess 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 a database where access is concurrent and where a table can be locked. Use this function to perform some operation, typically a SQL operation, on another table. For example, you could write the row of data to a backup table before the row is deleted. This event is called before deleting a row in the database .

Example: BeforeDeleteRowWithConcurrentAccess

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 p_dataT0 is written to a backup table with a call to the function writeDataToAccBackup.

The writeDataToAccBackup function has a parameter that stores the row of data from the account table.

PUBLIC FUNCTION dataEvent_recAccount_BeforeDeleteRowWithConcurrentAccess(p_dataT0 RECORD LIKE account.*)
    RETURNS (INTEGER, STRING, RECORD LIKE account.*)

    DEFINE errNo INTEGER
    DEFINE errMsg STRING

    DISPLAY "dataEvent_recAccount_BeforeDeleteRowWithConcurrentAccess (Row scope) is raised"
    CALL myAccountFunc.writeDataToAccBackup(p_dataT0) RETURNING errNo
    IF errNo = libdbappCore.ERROR_FAILURE THEN
       LET errMsg = " - BeforeDeleteRowWithConcurrentAccess failed to insert row in backup "  
    END IF
    DISPLAY "dataEvent_recAccount_BeforeDeleteRowWithConcurrentAccess (Row scope) is exited"

    RETURN errNo, errMsg, p_dataT0.*
END FUNCTION

In this section there is an example of the function writeDataToAccBackup called to write data to a backup account table. It is assumed that you have created the backup table for account before saving the row to it.

All functions that you would reuse across forms and applications would reside in a module you create. To use these functions in your project, you would import your module into the entity module (for example, AccountForm.4gl) using the IMPORT FGL statement.

FUNCTION writeDataToAccBackup(dataRec) 
  RETURNS (INTEGER)
  DEFINE dataRec RECORD LIKE account.*
  DEFINE errNo INTEGER
    
  TRY
    INSERT INTO account_backup VALUES (dataRec.*)
  CATCH
     DISPLAY "SQL ERROR: ", sqlca.sqlcode
     LET errNo = -1
  END TRY
  RETURN errNo
 
END FUNCTION