Download
slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Triggers Unlimited 9/24/2009 11:30am Room 6 Jeff Butera -- Hampshire College PowerPoint Presentation
Download Presentation
Triggers Unlimited 9/24/2009 11:30am Room 6 Jeff Butera -- Hampshire College

Triggers Unlimited 9/24/2009 11:30am Room 6 Jeff Butera -- Hampshire College

93 Views Download Presentation
Download Presentation

Triggers Unlimited 9/24/2009 11:30am Room 6 Jeff Butera -- Hampshire College

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Triggers Unlimited 9/24/2009 11:30am Room 6 Jeff Butera -- Hampshire College Pieter Crow -- Central Wyoming College

  2. Outline • What is a trigger? • What can triggers do? • How do you setup triggers? • Trigger examples • Tips and tricks • Questions

  3. 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

  4. 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

  5. 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

  6. 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!

  7. 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…

  8. 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

  9. 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

  10. 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)

  11. 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)

  12. More information • Unidata documentation (a little thin): • Developing Unibasic Applications Chapter 4 – Maintaining Data in Files Section on database triggers

  13. Questions Jeff Butera jeff@hampshire.edu http://jeff.hampshire.edu