Subject Re: problem with insert or update
Author calou_3324
Hello,
I have done just an insert and i have the same problem (with an
update it is good)
SQL> insert into CODECOMPTA (code_compta) values('test');
Statement failed, SQLCODE = -803
violation of PRIMARY or UNIQUE KEY constraint "PK_CODECOMPTA" on
table "CODECOMPTA"
i have done a gbak -b and -c and it is the same thing

Thank you for help

Regards

--- In firebird-support@yahoogroups.com, "calou_3324"
<calou_3324@...> wrote:
>
> Hello,
>
> Here is the declaration of a table:
>
> CREATE TABLE CODECOMPTA
> (
> ID INTEGER NOT NULL,
> TYPE_DEPENSE CHAR( 50) COLLATE FR_FR,
> CODE_COMPTA CHAR( 30) COLLATE FR_FR,
> TYPE_MONTANT CHAR( 4) COLLATE FR_FR,
> SOCIETE CHAR( 20) COLLATE FR_FR,
> CONSTRAINT PK_CODECOMPTA PRIMARY KEY (ID)
> );
>
>
> SET TERM ^^ ;
> CREATE TRIGGER CODECOMPTA_ID FOR CODECOMPTA ACTIVE BEFORE INSERT
> POSITION 0 AS
> begin
> if ( (new.ID is null) or (new.ID = 0) )
> then new.ID = gen_id(CODECOMPTA_GEN, 1);
> end
> ^^
> SET TERM ; ^^
>
> when i do this sql :
> update or insert into CODECOMPTA
> (ID,TYPE_DEPENSE,CODE_COMPTA,TYPE_MONTANT,SOCIETE)values
> ('0','test','test','HT','VALOREM') returning(id)
> i have this error :
> violation of PRIMARY or UNIQUE KEY constraint "PK_CODECOMPTA" on
> table "CODECOMPTA"
>
> I don't understand why because if id=0 then the insert should occur?
>
> Thank you for help
>
> Regards
>