Subject Re: Master/Detail and GENERATORS
Author Marco Menardi <mmenaz@lycosmail.com>
Generators provide always UNIQUE values, i.e. can't be provided two
equal values from a generator called by two or multiple users.
If you don't have to use the generated value in the client side, let
the Before Insert trigger do the job for you.
If you have do use it in the client side, and you use IBO native
components, you can use the property GeneratorLinks, in the form or:
MY_FIELD_ID=GENERATOR_NAME
like
CUSTOMER_ID=CUST_GEN
and IBO will do the work for you.
If you have detail queries, put the above in the master record and
automatically IBO will propagate to the details tables as the master
key. Of course, you can have a specific generator for uniqueness of
the detail rows too, like
DET_ORDER_ID=ORDER_GEN
To have triggers set the ID using generators if client does not
provide one, use code like this in Before Insert triggers:
IF ((NEW.CUSTOMER_ID IS NULL) OR (NEW.CUSTOMER_ID < 1)) THEN
BEGIN
NEW.CUSTOMER_ID = gen_id(CUST_GEN, 1);
END

If you instead want to get the generated value without IBO doing it
for you, you can use Gen_ID() property of your master table, like:
with qryCustomer do
FieldByName('CUSTOMER_ID').AsInt64 = gen_id('CUST_GEN', 1);
possibly in the after insert or before post event of the table

regards
Marco Menardi

--- In IBObjects@yahoogroups.com, "jubassauro <hipersimples@t...>"
<hipersimples@t...> wrote:
> How to work correctly in a net with several inserts?
>
> I am needing help in catching the values of a TRIGGER or of a
> GENERATOR using IBO.
>
> Actually I am developing a system of sales and I need with urgency
> to know as to catch a GENERATOR without there is duplication of data
> among the users.
>
> I have the following fields:
>
> Table of Sales
> == == == == == == ==
> CODESALE
> ...
>
> Table of requested products
> == == == == == == == == == == ==
> CODE PRODUCT
> CODESALE
>
> Did I already create a generator for CODESALE even so me precise to
> catch this value in advance because in a net as I can guarantee that
> other station doesn't catch the same code that of another stations?
> When catching this value me precise to throw it in the table DETAIL
> in the field CODESALE. Would a functional example be possible of
> that? Using IBX I got to find a component that the number of
> GENERATOR came back. How to do that with IBO?
> Thank you
>
> Juarez