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:
p_dataT0
. This is aRECORD
containing a row of data. It is defined according to the structure of the database table.
- 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 - A string is returned with the
SQLERRMESSAGE
error message. - 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.
# AccountForm.4gl
-- import user-defined functions
IMPORT FGL myAccountFunc
PUBLIC FUNCTION dataEvent_recAccount_BeforeDeleteRowWithConcurrentAccess(p_dataT0 RECORD LIKE account.*)
RETURNS (INTEGER, STRING, RECORD LIKE account.*)
DEFINE errNo INTEGER
DEFINE errMsg STRING
CALL libdbappCore.log(C_LOG_INFO, "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
CALL libdbappCore.log(C_LOG_INFO, "dataEvent_recAccount_BeforeDeleteRowWithConcurrentAccess (Row scope) is exited")
RETURN errNo, errMsg, p_dataT0.*
END FUNCTION
For more information on the libdbappCore.log()
function,
go to DBAPPDEBUG and the debug level API.
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.
# MyAccountFunc.4gl
IMPORT FGL libdbappCore
FUNCTION writeDataToAccBackup(dataRec RECORD LIKE account.*)
RETURNS (INTEGER)
DEFINE errNo INTEGER
TRY
INSERT INTO account_backup VALUES (dataRec.*)
CATCH
DISPLAY "SQL ERROR: ", sqlca.sqlcode
LET errNo = libdbappCore.ERROR_FAILURE
END TRY
RETURN errNo
END FUNCTION