Subject Re: [ib-support] Why Firebird AutoIncrement not trigger?
Author Helen Borrie
At 02:22 AM 10/05/2003 +0000, you wrote:
>I'm using Borland 6 & Firebird 1.0 and created a table with three
>fields:
>
>DEPARTMENTID : INTERGER NOT NULL <== P.KEY
>DEPARTMENTCODE : VACHAR(8)
>DEPARTMENTNAME : VACHAR(40)
>
>Where the column special of DEPARTMENTID is set to Create
>AutoIncrement Trigger & Generator as follow:
>
>begin
>if (new.DEPARTMENTID is null)
>then new.DEPARTMENTID = gen_id(DEPARTMENT_GEN, 1);
>end
>
>The problem is when I insert data using the DBgrid, it always
>prompted me to enter the Value of DEPARTMENTID.
>If I don't enter the value for DEPARTMENTID, error occured.
>Until I enter an unique value then I can continue. Why?

You are encountering a Delphi restriction. Delphi places the Required
attribute on any column which has the NOT NULL constraint. Without going
into detail (because this is not a Delphi forum), you need to set the
Required attribute of the field object to False. Delphi doesn't have any
knowledge of your triggers or generators.

There are better ways to do this, such as using components like IBO or
FIBPlus, which provide support for linking generators to non-null field
objects that need to use them; or using a custom INSERT statement that
doesn't include that field; or writing your own Gen_ID function in Delphi
to get the generator value. The native VCL components + BDE for
client/server databases are deprecated from Delphi 6 onward, though, so
it's NOT a good idea to put much energy into trying to make a BDE
application for Firebird.

heLen