dataEvent_record_BeforeInsertRow
Function called before inserting rows.
Syntax
PUBLIC FUNCTION dataEvent_record_BeforeInsertRow(
dataInsert record-type)
RETURNS (INTEGER, STRING, record-type)
The function has one parameter:
dataInsert
. This is aRECORD
type 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 Insert Row property for the creation of the event, a function shell is created. Enter your code in the function.
This event is executed when a new row is created in an INPUT ARRAY
. It is
triggered before the row is inserted in the database. Use this event to validate values inserted in
a newly-created row. You can test several fields. Row creation can be stopped by setting the
errNo
with an ERROR_FAILURE
value.
Example: Before Insert Row
This example uses the Before Insert Row code event for the OrderItem form in the OfficeStore demo.
In this example, the modified value for the line item quantity is checked against the quantity in the inventory table. The function returns an error number and message if quantity is greater than the stock quantity in the inventory.
PUBLIC FUNCTION dataEvent_OrderItem_BeforeInsertRow(dataInsert RECORD LIKE lineitem.*)
RETURNS (INTEGER, STRING, RECORD LIKE lineitem.*)
DEFINE errNo INTEGER
DEFINE errMsg STRING
DEFINE res INTEGER
DISPLAY "dataEvent_OrderItem_BeforeInsertRow (Row scope) is raised"
SELECT qty INTO res FROM inventory WHERE @itemid=dataInsert.itemid
AND @qty >= dataInsert.quantity
CASE
WHEN sqlca.sqlcode = NOTFOUND
LET errNo = libdbappCore.ERROR_FAILURE
LET errMsg = " - Invalid value "
WHEN sqlca.sqlcode < 0
LET errNo = libdbappCore.ERROR_FAILURE
LET errMsg = SQLERRMESSAGE
END CASE
DISPLAY "dataEvent_OrderItem_BeforeInsertRow (Row scope) is exited"
RETURN errNo, errMsg, dataInsert.*
END FUNCTION