Subject Re: Newbie question (Interbase Insert error)
Author constantijnw
--- In IBObjects@yahoogroups.com, "richscheuermann" <rarchitect@c...>
wrote:
> I have a field called PROJ_ID which is the Primary Key in an
> interbase table.
>
> When I try to save a new record I get an exception
> 'PRJ_ID is a required field'.
>
> Is there a way to calculate the value in the client app?

>
> I am using IB_Query.
>
> Thanks
> Rich Scheuermann

Hi Rich,

Why do you want to have the pk calculated on the client?

All my integer pk's are calculated on the server.
The following script defines a generator which holds the last value
generated.

CREATE GENERATOR "GEN_PRJ_ID";

The script below defines a trigger. When you don't send a pk value to
the server, or when the value = 0, then this trigger (fired before the
new record is inserted) pulls a new unique PRJ_ID from the generator
defined above.

CREATE TRIGGER "SET_PRJ_ID" FOR "MYTABLE"
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
if ((new.PRJ_ID is Null) or (new.PRJ_ID = 0)) then
new.PRJ_ID = Gen_Id(GEN_PRJ_ID, 1);
END

Of course IBO can take care of having a pk value available on the
client, but I hope someone else can explain you how to do this.