130 likes | 233 Views
Triggers Unlimited 9/24/2009 11:30am Room 6 Jeff Butera -- Hampshire College Pieter Crow -- Central Wyoming College. Outline. What is a trigger? What can triggers do? How do you setup triggers? Trigger examples Tips and tricks Questions. What is a trigger?. Piece of executed code
E N D
Triggers Unlimited 9/24/2009 11:30am Room 6 Jeff Butera -- Hampshire College Pieter Crow -- Central Wyoming College
Outline • What is a trigger? • What can triggers do? • How do you setup triggers? • Trigger examples • Tips and tricks • Questions
What is a trigger? • Piece of executed code • Triggered by certain events Unidata specifics: • Code is a Unibasic subroutine or function • Trigger can be invoked when • Record Created/Updated (written) • Record Deleted
What can triggers do? Triggers are useful for automated, realtimeprocessing • ADDOPR, CHGOPR • Stored computed columns • Virtual fields too slow? • No problem, use SCC with a trigger • Status and/or status date fields • Notify (email?) when things happen
When not to use a trigger Never? • Triggers invoked realtime • Should run in 1 second or less • Time-consuming processes not good • Stored computed columns: • Status, time, dates, etc – OK • Recalculate student AR – Not OK
What about “expensive” calls? Time-consuming processes can be used • Write code as you would normally • Don’t place in trigger • In trigger, fork background process: /usr/local/bin/my_script.sh & • Background process can do work • This is *nix only!
What about “expensive” calls? Another approach… • Write program that runs 24x7 • Waits for a request • Trigger simply asks for calculation • Trigger doesn’t perform actual work • Background program does heavy lifting…
What about “expensive” calls? Background program Background program waits for new request Trigger requests something Background program executes request Background program stores result Background program loops
How do you setup triggers? • Create subroutine with 5 arguments: EXECSTAT out (0,1,2) DICT.FLAG in (“”,“DICT”) FILENAME in (“STUDENTS”) ID in (“0023450”) RECORD in/out • Compile and GLOBALLY catalog • CREATE.TRIGGER FILENAME SUBNAME UPDATE
Trigger examples at Hampshire • Find bad HTML in course descriptions • Edit A/R to NOT show dorm assignment • FMLA check on complete timecard • Log deletes, cleanup pointers • Auto assign ID Card type (& export) • Validate data entered • Stored computed columns (realtime)
Jeff’s tips and tricks * cleanup some simple HTML SWAP '<p>' WITH '<P>' IN X.DESC SWAP '</p>' WITH '</P>' IN X.DESC SWAP '<br>' WITH '<BR/>' IN X.DESC SWAP '<BR>' WITH '<BR/>' IN X.DESC SWAP '<hr>' WITH '<HR/>' IN X.DESC SWAP '<HR>' WITH '<HR/>' IN X.DESC SWAP '</a>' WITH '</A>' IN X.DESC SWAP '<a href' WITH '<A HREF' IN X.DESC SWAP '<a HREF' WITH '<A HREF' IN X.DESC * Strip out some bad binary multibyte chars CALL H08.IC.S.FIX.BAD.ASCII.CHARS(X.DESC)
More information • Unidata documentation (a little thin): • Developing Unibasic Applications Chapter 4 – Maintaining Data in Files Section on database triggers
Questions Jeff Butera jeff@hampshire.edu http://jeff.hampshire.edu