Subject | Re: BUG IN FIREBIRD |
---|---|
Author | banzatto@ciagri.usp.br |
Post date | 2001-10-16T16:15:24Z |
The code below is code complete for table and trigger
/* Table: AREA */
CREATE TABLE AREA (
ID_AREA DO_CHAVE NOT NULL,
NOME DO_VARCHAR30,
DIVISAO1 DO_DIVISAO,
DIVISAO2 DO_DIVISAO,
DIVISAO3 DO_DIVISAO,
DIVISAO4 DO_DIVISAO,
AREA DO_NUM15,
LINHA DO_NUM15,
PLANTA DO_NUM15,
DT_PLANTIO DO_DATA,
ID_SITUACAO DO_CHAVE,
ID_MATERIAL_GENETICO DO_CHAVE,
ID_FASE DO_CHAVE,
ALTURA DO_NUM15,
ATIVO DO_BOOLEAN);
/* Primary keys definition */
ALTER TABLE AREA ADD PRIMARY KEY (ID_AREA);
/* Triggers definition */
SET TERM ^ ;
/* Trigger: AREA_BI */
CREATE TRIGGER AREA_BI FOR AREA
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.ID_AREA IS NULL) THEN
NEW.ID_AREA = GEN_ID(GEN_ID_AREA,1);
END
^
/* Trigger: AREA_BI0 */
CREATE TRIGGER AREA_BI0 FOR AREA
ACTIVE BEFORE INSERT POSITION 0
as
begin
if (EXISTS(SELECT A.DIVISAO1,A.DIVISAO2,A.DIVISAO3,A.DIVISAO4 FROM
AREA A WHERE
(A.DIVISAO1 = NEW.DIVISAO1) AND (A.DIVISAO2 =
NEW.DIVISAO2) AND
(A.DIVISAO3 = NEW.DIVISAO3) AND (A.DIVISAO4 =
NEW.DIVISAO4))) THEN
EXCEPTION CHAVE_DUPLICADA;
end
^
SET TERM ; ^
The fields DIVISAO1, DIVISAO2, DIVISAO3, DIVISAO4 cannot have to be
duplicate, but they can have null values , therefore the use of
trigger. Only that to trigger she does not function. Why ?
/* Table: AREA */
CREATE TABLE AREA (
ID_AREA DO_CHAVE NOT NULL,
NOME DO_VARCHAR30,
DIVISAO1 DO_DIVISAO,
DIVISAO2 DO_DIVISAO,
DIVISAO3 DO_DIVISAO,
DIVISAO4 DO_DIVISAO,
AREA DO_NUM15,
LINHA DO_NUM15,
PLANTA DO_NUM15,
DT_PLANTIO DO_DATA,
ID_SITUACAO DO_CHAVE,
ID_MATERIAL_GENETICO DO_CHAVE,
ID_FASE DO_CHAVE,
ALTURA DO_NUM15,
ATIVO DO_BOOLEAN);
/* Primary keys definition */
ALTER TABLE AREA ADD PRIMARY KEY (ID_AREA);
/* Triggers definition */
SET TERM ^ ;
/* Trigger: AREA_BI */
CREATE TRIGGER AREA_BI FOR AREA
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.ID_AREA IS NULL) THEN
NEW.ID_AREA = GEN_ID(GEN_ID_AREA,1);
END
^
/* Trigger: AREA_BI0 */
CREATE TRIGGER AREA_BI0 FOR AREA
ACTIVE BEFORE INSERT POSITION 0
as
begin
if (EXISTS(SELECT A.DIVISAO1,A.DIVISAO2,A.DIVISAO3,A.DIVISAO4 FROM
AREA A WHERE
(A.DIVISAO1 = NEW.DIVISAO1) AND (A.DIVISAO2 =
NEW.DIVISAO2) AND
(A.DIVISAO3 = NEW.DIVISAO3) AND (A.DIVISAO4 =
NEW.DIVISAO4))) THEN
EXCEPTION CHAVE_DUPLICADA;
end
^
SET TERM ; ^
The fields DIVISAO1, DIVISAO2, DIVISAO3, DIVISAO4 cannot have to be
duplicate, but they can have null values , therefore the use of
trigger. Only that to trigger she does not function. Why ?
--- In ib-support@y..., "Ann W. Harrison" <aharrison@i...> wrote:
> At 02:13 PM 10/16/2001 +0000, banzatto@c... wrote:
>
> >i have a trigger before insert with code below :
> >
> >if (EXISTS
> > (SELECT A.DIVISAO1,A.DIVISAO2,A.DIVISAO3,A.DIVISAO4
> > FROM AREA A
> > WHERE (A.DIVISAO1 = NEW.DIVISAO1)
> > AND (A.DIVISAO2 = NEW.DIVISAO2)
> > AND (A.DIVISAO3 = NEW.DIVISAO3)
> > AND (A.DIVISAO4 = NEW.DIVISAO4)))
> > THEN
> > EXCEPTION CHAVE_DUPLICADA;
> >
> >when it´s dispared the code is changed to
> >
> >SELECT COUNT(*) FROM RDB$DATABASE
> > WHERE (EXISTS
> > (SELECT A.DIVISAO1,A.DIVISAO2,A.DIVISAO3,A.DIVISAO4
> > FROM AREA A
> > WHERE (A.DIVISAO1 = 'A' )
> > AND (A.DIVISAO2 = 'A' )
> > AND (A.DIVISAO3 = cast(null as char) )
> > AND (A.DIVISAO4 = cast(null as char) )))
> >
> >the fields with <null> are changed for cast(null as char) don´t
> >executing the exception. i analized this code with IB expert
> >debug the trigger. what´s the problem ???
>
> That's a good question. Are you absolutely sure you didn't
> redefine the trigger? Could they actually be two different
> triggers? I've had a look at the code that parses and compiles
> triggers, and it's not nearly smart enough to transform the first
> trigger into the second ... and probably not venal enough either.
>
>
> Regards,
>
> Ann
> www.ibphoenix.com
> We have answers.