Subject Re: [IBO] Auto Inc Trigger
Author Paul Vinkenoog
Hi Rich,

> I have a Firebird database table with a primary key "Id", an
> integer.
>
> There is a trigger that auto increments it on insert. When I add
> a record in DBWorkbench all is well.
>
> But, when I try to add a record in a IBGrid I get the following
> message: "Project Schedule.exe raised an exception class
> EIB_DatasetError with message 'Id is a required field', Process
> stopped."

This exception is raised by IBO code *before* the new record is sent
to the server. The Id field is null, because the trigger code hasn't
been executed yet.

There are several ways around this:

1.
Force Required to false on that field. This is the easiest solution
but especially in browsable datasets it's not a good one because now
IBO doesn't know the PK value (since this is assigned on the server
side, after IBO posts the inserted record). The effect of this may be
that newly inserted records seem to disappear after you post them.

2.
Set GeneratorLinks for the dataset like this:

Id=MyIdGenerator

(replacing MyIdGenerator with the name of your generator).
You can do this from the Object Inspector or from the Query Editor.

Now IBO will get the generator value for you, and assign it to Id as
soon as the record is created on the client side.

If you take this approach, also check your trigger code. If it assigns
the generator value unconditionally, change it to this form:

if ( New.Id is null )
then New.Id = gen_id( MyIdgenerator, 1 );

If you don't do that, the Id value assigned by IBO will be overwritten
by the trigger and IBO will still "lose" the record because it's got a
new PK value that IBO doesn't know of.


Good luck,
Paul Vinkenoog