Subject Re: [IB-Architect] Trigger Templates
Author Dalton Calford
A tool is currently being developed that would allow such code
templating.
At the moment, all the work will be performed by the client, and
multiple triggers created on the server. Eventually, we are hoping
(once a full understanding of BLR occurs) that we can implement a
template style trigger system via blr with as little modification to the
base server design as we possible can.

regards

Dalton

Joseph Alba wrote:
>
> (I don't know if this should be for Architecture or Priorities. Apologies of
> Helen)
>
> I noticed that there are several triggers that have exactly the same body,
> but are for different tables.
>
> I would like to propose templates (like that of C++).
>
> Example:
>
> /* Template Definition */
> CREATE TEMPLATE TRIGGER INSERT_TIMESTAMP
> BEFORE INSERT POSITION 5
> AS
> BEGIN
> NEW.INSERT_BY=USER;
> NEW.INSERT_TIME=CURRENT_TIMESTAMP;
> END^
>
> /* Instantiation */
> CREATE TRIGGER ACCOUNTS_INSERT_TIMESTAMP FOR ACCOUNTS
> FROM INSERT_TIMESTAMP;
>
> CREATE TRIGGER ITEMS_INSERT_TIMESTAMP FOR PAYEE
> FROM INSERT_TIMESTAMP;
>
> /* MORE AMBITIOUS - Multiple Tables */
> CREATE TRIGGER ACTUAL_INSERT_TIMESTAMP FOR ACCOUNTS, PAYEE, CUSTOMER,
> GENERAL_LEDGER
> FROM INSERT_TIMESTAMP;
>
> -----------------------------
> Also, Triggers can be the same code for different "events" like, Before
> Update and Before Delete can share the same code.
> so, I would like to propose that multiple "events" can be included to the
> Trigger Header like
>
> CREATE TRIGGER Minus_OldValues FOR ITEMS
> BEFORE UPDATE
> BEFORE DELETE
> POSITION 10
> AS
> BEGIN
> UPDATE HEADER H
> SET TOTAL=TOTAL-OLD.AMOUNT
> WHERE H.MASTER_ID=OLD.MASTER_ID;
> END^
>
> CREATE TRIGGER Add_NewValues FOR ITEMS
> AFTER INSERT
> AFTER UPDATE
> POSITION 10
> AS
> BEGIN
> UPDATE HEADER H
> SET TOTAL=TOTAL+NEW.AMOUNT
> WHERE H.MASTER_ID=NEW.MASTER_ID
> END^
>
> This way, I write only two triggers instead of four.
>