Subject Re: [IBO] Problem with Trigger on Table during insert.
Author Helen Borrie
At 09:46 AM 30/11/2006, you wrote:

>This code has worked in using the BDE for the last 5 years, but in the
>converted I am having a problem with a table checks and using a
>TIBOQuery to add a row to this table and the software complains the
>'CHECK_KEY must have a value'.
>
>this trigger is created on the CHECKS table.
>
>CREATE TRIGGER SET_CHECK_NUM FOR CHECKS
>BEFORE INSERT AS
>BEGIN
>NEW.CHECK_KEY = GEN_ID(CHECK_KEY_GEN, 1);
>END^
>
>In the code below when I try to post I get the Error.
>
>Query_Checks.Close;
>Query_Checks.Open;
>Query_Checks.Insert;
>Query_Checks.FieldByName('ACC_KEY').AsInteger := WWAccKey;
>Query_Checks.FieldByName('EMP_KEY').AsInteger := EEmp_Key;
>Query_Checks.FieldByName('CHECK_DATE').AsDateTime :=
>DTP_CheckDate.Date;
>Query_Checks.FieldByName('PAY_DATE').AsDateTime := Date;
>Query_Checks.FieldByName('CHECK_NUM').AsString := Edit_check.Text;
>Query_Checks.FieldByName('AMT').AsCurrency := Amt;
>Query_Checks.Post;
>Query_Checks.Close;
>
>Can somebody give some pointers how to get around this problem??

You need to do two things:

1) make a GeneratorLinks entry for this dataset. The entry would be:

CHECK_KEY=CHECK_KEY_GEN

-- or you can do it on the GeneratorLinks property of the IBODatabase, as

CHECKS.CHECK_KEY=CHECK_KEY_GEN

Then it will be available whenever the application encounters an
insert to this table.

2) alter the trigger (this is really important, and is what you
should do in any case):


ALTER TRIGGER SET_CHECK_NUM
AS
BEGIN
if (new.CHECK_KEY IS NULL) then
NEW.CHECK_KEY = GEN_ID(CHECK_KEY_GEN, 1);
END^

Helen