Subject RE: [ib-support] View or Stored Procedure
Author Gerhardus Geldenhuis
Thanks for your interest here is a sample database which I created

create generator gen_items;

CREATE TABLE ITEMS
(
ID INTEGER NOT NULL,
AMOUNT INTEGER,
CODE VARCHAR(10) CHARACTER SET NONE COLLATE NONE,
BOOKTYPE CHAR(5) CHARACTER SET NONE COLLATE NONE,
BRANCH VARCHAR(10) CHARACTER SET NONE COLLATE NONE,
CONSTRAINT PK_ITEMS PRIMARY KEY(ID)
);

SET TERM ^! ;
CREATE TRIGGER GGG FOR ITEMS ACTIVE BEFORE INSERT POSITION 0 AS
BEGIN
IF (NEW.id IS NULL) THEN
NEW.id = GEN_ID(GEN_ITEMS, 1);
END
^!
SET TERM ; ^!

CREATE VIEW ITEMVIEW4
(
CODE,
QTYAVAILABLE,
BRANCHNAME
) AS
Select CODE, SUM(AMOUNT), BRANCH
FROM ITEMS
GROUP BY CODE, Branch

SET TERM ^! ;
CREATE TRIGGER BEFORE_UPDATE FOR ITEMVIEW4 ACTIVE BEFORE UPDATE POSITION 0
AS
BEGIN
insert into items(AMOUNT,code)
values(2,'A6');
END
^!
SET TERM ; ^!


And here is sample data for the db.
ID AMOUNT CODE BOOKTYPE BRANCH
==== ====== =========== ======== ===========
1 10 A4 IN GLEN
2 20 A3 IN GLEN
3 -1 A4 OUT ALB
4 -1 A4 OUT ALB
5 -4 A3 OUT ALB
6 10 A4 IN ALB
7 5 PHOTO IN GLEN
8 3 PHOTO OUT ALB
9 1 PHOTO OUT ALB
11 10 A3 <null> ALB

I cant get the trigger to fire. Maybe I am doing something
wrong. I create this database totally from scratch so as to
eliminate any other problems. I try to edit the data with
IBW.
The booktype field is not really relevant here.

Groete
Gerhardus

>
>
> Gerhardus,
>
> > Yes that is so. IB does however allow triggers to be created but
> > they dont fire. I created all 6 posible triggers. It would be
> > nice if FB told you on creation that you cant create a trigger
> > on a read-only table.
>
> I haven't followed the thread, but in my experience IB does allow you to
> define "before" triggers for a non-updatable view to turn it into an
> updatable view, and they actually fire.
> There must be something more in your setup.
> Ciao
> --