August 13th, 2012, 12:21 PM
Firebird Trigger: Modify Value & Insert Record Problem
Hi all experts...
I am currently new in Firebird especially in trigger. Usually I done this in script manually, but I am really fascinating to create it with trigger.
Please let me explain my tables first.
And now my problems:
1. How to modify STOCK.GOOD and STOCK.BROKEN value before insert a new record into BROKEN? That will be: STOCK.GOOD-1, STOCK.BROKEN+1.
2. How to insert all record from BROKEN and SERVICE into LOGS before current record in SERVICE is deleted?
I hope my questions could be accepted.
Thank you very much in advance.
August 13th, 2012, 01:04 PM
I have some serious reservations about your schema.
Assuming that will not be changed, it looks as if you just need an after insert trigger on
the BROKEN table that updates the STOCK table as required.
Somewhere, of course, you will have to take care of all the possible logic error situations
e.g. GOOD turning negative.
However, the integrity of the math inside the trigger will be guaranteed by the transaction within which it runs.
August 13th, 2012, 09:45 PM
Yes, I mean after insert. My mistake I'm sorry
I've try to consider all logic error situations as possible I can.
I mean like this, the user cannot mark a stock detail as broken, before she/he insert a record detail from table stock. So, if there's no record in DETAIL, access to insert record in BROKEN (in app) is disabled, and GOOD will not turning negative.
August 14th, 2012, 03:29 AM
Never mind, I figured it out.