Subject | problem with insert or update |
---|---|
Author | calou_3324 |
Post date | 2008-08-13T14:48:08Z |
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
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