UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software UniBasic Commands Reference - Rocket Software

rocketsoftware.com
from rocketsoftware.com More from this publisher
11.04.2013 Views

SUBROUTINE (Update Trigger) Syntax SUBROUTINE trigname(execstat, dictflag, filename, record.ID.expr, recordval) FUNCTION trigname(dictflag, filename, record.ID.expr, recordval) Description Triggers enforce user-defined constraints that must be met before data can be updated. The trigger is associated with the data file, so it verifies any access to the data. A UniBasic trigger subroutine or function serves as an UPDATE trigger. The SUBROUTINE or FUNCTION definition must be the first line in the UniBasic trigger. You must include a RETURN statement in the function: RETURN [execstat] Points to Remember 1-880 UniBasic Commands Reference When you attempt to update a record, UniData calls the trigger, passing the file name, DICT if dictionary file, record ID, and the input value before updating the record. The subroutine returns the execution status and the new record value. If the update request fails, the subroutine must return an execstat value of 0. If the request passes, the return value must be 1. Tip: You can call a C routine from the UniBasic subroutine or function that is called from a trigger.

Parameters The following table describes each parameter of the syntax. Paragraph Description trigname Name of the globally cataloged subroutine. execstat Execution status returned by the trigger subroutine: 0 – No updates allowed. 1 – Update is allowed. 2 – Update is allowed; uses the return recordval. dictflag “DICT” – Indicates that the trigger is operating on the dictionary file. “” – Indicates that the trigger is operating on the data file. The quotation marks are required. filename The name of the file on which the trigger is operating. record.ID.expr The record to be updated. recordval The input record value submitted to the UPDATE trigger. recordval is both an input and output parameter. The trigger can change this value (for example, by performing a conversion). Then, if the trigger sets execstat to 2, this value is passed back in recordval and updates the data record. Only strings and numbers are valid. If the value returned in recordval is invalid, the record is not updated, even if the trigger subroutine sets execstat to 2. In this case, the UniBasic STATUS function returns 3 when executed immediately after the command that calls the trigger. Only strings and numbers are valid. SUBROUTINE Update Trigger Parameters STATUS Function Return Values After you execute a trigger subroutine, the STATUS function returns one of the values described in the following table. SUBROUTINE (Update Trigger) 1-881

Parameters<br />

The following table describes each parameter of the syntax.<br />

Paragraph Description<br />

trigname Name of the globally cataloged subroutine.<br />

execstat Execution status returned by the trigger subroutine:<br />

0 – No updates allowed.<br />

1 – Update is allowed.<br />

2 – Update is allowed; uses the return recordval.<br />

dictflag “DICT” – Indicates that the trigger is operating on the dictionary file.<br />

“” – Indicates that the trigger is operating on the data file.<br />

The quotation marks are required.<br />

filename The name of the file on which the trigger is operating.<br />

record.ID.expr The record to be updated.<br />

recordval The input record value submitted to the UPDATE trigger. recordval is<br />

both an input and output parameter. The trigger can change this value<br />

(for example, by performing a conversion). Then, if the trigger sets<br />

execstat to 2, this value is passed back in recordval and updates the data<br />

record. Only strings and numbers are valid.<br />

If the value returned in recordval is invalid, the record is not updated,<br />

even if the trigger subroutine sets execstat to 2. In this case, the<br />

<strong>UniBasic</strong> STATUS function returns 3 when executed immediately after<br />

the command that calls the trigger. Only strings and numbers are valid.<br />

SUBROUTINE Update Trigger Parameters<br />

STATUS Function Return Values<br />

After you execute a trigger subroutine, the STATUS function returns one of the<br />

values described in the following table.<br />

SUBROUTINE (Update Trigger) 1-881

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!