Subject Re: [firebird-support] problem with insert or update
Author Antonio Galicia
On Wed, Aug 13, 2008 at 9:48 AM, calou_3324 <calou_3324@...> wrote:

> CREATE TABLE CODECOMPTA
> (
...
> );

This is OK.

> 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 ; ^^

Do you have create the generator? Is the trigger generated? I Try
your code and get:

Statement failed, SQLCODE = -104
invalid request BLR at offset 43
-generator CODECOMPTA_GEN is not defined

After I created "CODECOMPTA_GEN" all work ok and when do

SQL> update or insert into CODECOMPTA
> (ID,TYPE_DEPENSE,CODE_COMPTA,TYPE_MONTANT,SOCIETE)values
> ('0','test','test','HT','VALOREM') returning(id);

get this:

ID
============
1

SQL> show trigger CODECOMPTA_ID;

Triggers on Table CODECOMPTA:
CODECOMPTA_ID, Sequence: 0, Type: BEFORE INSERT, Active
AS
begin
if ( (new.ID is null) or (new.ID = 0) )
then new.ID = gen_id(CODECOMPTA_GEN, 1);
end
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL>


--
Saludos,
PP