Subject Re: [IBO] refresh data when it is post
Author Frank Ingermann
Hi,

Ronaldo Rezende Vilela Luiz wrote:
>
> Do you think that it's a better idea than use a trigger to gennerate the
> autoincrement fields? If I use the generator links property, I don't have to
> use the triggers and stored procedure that I have created in the server?

maybe i can share my experience on that subject. there are two different
approaches to this:

A) post the new record without the ID field, and let the server-side
trigger feed it. works ok, but has the major drawback that there is
*no safe way* to know from the client side which generator value was
assigned to the record you just inserted. (remember: you're in a
multi-user environment AND generators are outside of transaction
control (!) - so don't even think about SELECT MAX(ID) FROM MYTABLE
after posting !)

B) (recommended): use IBO's GeneratorLinks property to let IBO fill the
autoinc field. In this case you don't need a server-side Before Insert
trigger to fill the id, and the major benefit is that you know the value
on the client side *before* the record gets posted. Instead of using
GeneratorLinks, you can also put the line

qry.FieldByName['myautoincfield'].AsInteger :=
qry.GEN_ID('mygeneratorname',1);

in the OnBeforeInsert event of your query - same effect, but more work :-)

I still have Before Insert triggers defined in the database for every table
that look something like

CREATE TRIGGER tbi_MyTable FOR MyTable
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF ((NEW.ID = 0) OR (NEW.ID IS NULL)) THEN
NEW.ID = GEN_ID(gen_id_mytable,1);
END

but that is more of a "safety net" to make really sure that every record
will get an ID, even if it's not posted by the IBO application.

hth & regards,
fingerman