Subject Re: Generators and Triggers
Author mmenaz
So:
a) it's paramount that the database has code to do the generator assigment, so does not metter who/from where/how records are inserted, they get their right ID
b) for client side work, it's necessary that the client knows the value being assigned after an insert, so it can locate the record and read it back for refresh/positioning

The right aproach is mix the two needs:
on the server side (BEFORE INSERT TRIGGER):
IF ((NEW.MovCon_ID IS NULL) OR (NEW.MovCon_ID < 1)) THEN
BEGIN
NEW.MovCon_ID = gen_id(MovCon_ID_GEN, 1);
END
(the <1 check is done so you can use interactive tools for editing (like IB_SQL) that would prevent you post a record with null value if the column is required. Setting it to -1 does the trick)

On the client side you can have:
GeneratorLinks
or
BeforePost event with a stored procedure to retrieve the generator
IBO allows you the BeforePost solution even in master/detail, since does a "phantom post" to the master record before any post of a detail one, so master ID is defined.
Hope this will help
Marco Menardi


--- In IBObjects@y..., "Don Gollahon" <dlgllhn@t...> wrote:
> I have an app that is working fine. There is a trigger that uses a
> generator to set the key field automatically on insert of a new record. The
> problem is that when posting the record is done then the user is no longer
> on the record they just entered. The record is now at the "bottom" since it
> used the next higher key value. Is there any way to keep the user on the
> same record? It would probably work if I used the generatorlinks but that
> seems to defeat the purpose of letting the database do it.
>
> Thanks.
>
> --
>
> Don Gollahon
> (dlgllhn@t...)