11.04.2013 Views

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tip: The <strong>UniBasic</strong> STATUS function returns the status of the preceding command.<br />

You can place it within the trigger subroutine to learn about the status of individual<br />

commands executed within the trigger. If you place it immediately after the statement<br />

that calls the trigger, it returns the status of the <strong>UniBasic</strong> command as determined by<br />

the trigger. The trigger subroutine also returns a value indicating its status in the<br />

parameter execstat. These values returned in execstat are listed in the “Parameters”<br />

section.<br />

Return Value Description<br />

0 No error.<br />

Example<br />

The following example begins with a DELETE trigger subroutine called DEL_TRIG.<br />

This subroutine always returns 1 and always allows records to be deleted:<br />

1-886 <strong>UniBasic</strong> <strong>Commands</strong> <strong>Reference</strong><br />

1 System error, such as a damaged file.<br />

2 Constraint violation. In this case, the <strong>UniBasic</strong> trigger subroutine<br />

returns a value of 0 in the parameter execstat, indicating that the update<br />

or delete is not allowed.<br />

3 Trigger execution error or unexpected return from trigger routine (for<br />

example, the trigger subroutine is not cataloged).<br />

STATUS Function Return Values<br />

SUBROUTINE<br />

DEL_TRIG(exec.stat,dict.flag,trig.name,rec.id.expr,rec.val)<br />

exec.stat=1<br />

RETURN<br />

Note: After creating and compiling the subroutine, you must catalog it globally.<br />

Next, we create the trigger and associate it with the ORDERS file:<br />

:CREATE.TRIGGER ORDERS DEL_TRIG DELETE<br />

Finally, we delete records in the ORDERS file. The trigger always allows the deletion<br />

because the subroutine sets the execution status to 1.<br />

:DELETE ORDERS 912<br />

'912' deleted.<br />

:

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

Saved successfully!

Ooh no, something went wrong!