120 likes | 215 Views
Session 4718. Triggers Unlimited National Harbor 6 & 7 Tuesday 4/07/2009 3:45pm 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.
E N D
Session 4718 Triggers Unlimited National Harbor 6 & 7 Tuesday 4/07/2009 3:45pm 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 a record is • Created • Modified (written) • Deleted
What can triggers do? Triggers are useful for automated processing • ADDOPR, CHGOPR • Virtual fields too slow? • No problem, make ‘em computed with a trigger • Stored computed columns • Status and/or status date fields • Notify (email?) when certain things happen
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 Pieter Crow pcrow@cwc.edu