vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| > 19.1. CREATE TRIGGER Syntax > > That is your MySQL reference section. Yeah, I found that, printed it out, and got thoroughly confused before I posted my initial question. > I do not know the syntax for an "ignore" or "cancel" update. > Worst case scenario, you compare the required field, and > set all other fields to old or new values accordingly. You mean, instead of checking before the update and trying to cancel the changes, check after the update and reverse the changes if necessary? Something like: CREATE TRIGGER FY2007 AFTER UPDATE ON ITPLAN.REQ FOR EACH ROW BEGIN IF REQ.INIT_DATE < '2006-09-01' THEN IF REQ.FIELD1 <> OLD.FIELD1 THEN SET REQ.FIELD1 = OLD.FIELD1; IF REQ.FIELD2 <> OLD.FIELD2 THEN SET REQ.FIELD2 = OLD.FIELD2; IF REQ.FIELD3 <> OLD.FIELD3 THEN SET REQ.FIELD3 = OLD.FIELD3; ... ENDIF END I'm probably writing that code incorrectly, but as you've no doubt noticed, you could put everything I know about MySQL into a gnat's bellybutton. |
| ||||
| It isn't a pretty solution is it? <grin> Using a trigger to implement a lock on older records is not going to be pretty in any case. And the biggest problem is, it provides no feedback to the user whatsoever... A Stored Procedure would be better, where you don't even run the update in the first place if the date is in the "no-touchy" zone, rather than trying to catch it with a trigger. A Stored Procedure can also be geared to provide feedback in the way of a failure output parameter, that can be used by the UI. Triggers are usually used more for DB back-end maintenance, logging, integrity, creating child table records, and the like. Using them to control user updates is not usually recommended... but it can be done. Cheers! ~ Duane Phillips. "Leslie Houk" <lhouk@ghg.net> wrote in message news:1159303607.255706.194670@b28g2000cwb.googlegr oups.com... >> 19.1. CREATE TRIGGER Syntax >> >> That is your MySQL reference section. > > Yeah, I found that, printed it out, and got thoroughly confused before > I posted my initial question. > >> I do not know the syntax for an "ignore" or "cancel" update. >> Worst case scenario, you compare the required field, and >> set all other fields to old or new values accordingly. > > You mean, instead of checking before the update and trying to cancel > the changes, check after the update and reverse the changes if > necessary? Something like: > > CREATE TRIGGER FY2007 AFTER UPDATE ON ITPLAN.REQ > FOR EACH ROW BEGIN > IF REQ.INIT_DATE < '2006-09-01' THEN > IF REQ.FIELD1 <> OLD.FIELD1 THEN SET REQ.FIELD1 = > OLD.FIELD1; > IF REQ.FIELD2 <> OLD.FIELD2 THEN SET REQ.FIELD2 = > OLD.FIELD2; > IF REQ.FIELD3 <> OLD.FIELD3 THEN SET REQ.FIELD3 = > OLD.FIELD3; > ... > ENDIF > END > > I'm probably writing that code incorrectly, but as you've no doubt > noticed, you could put everything I know about MySQL into a gnat's > bellybutton. > |