Subject Re: [ib-support] Re: Interbase Transactions
Author Helen Borrie
OK, now that I understand we are talking about Delphi and IBX, we are
getting somewhere.

Yes, it is true that if you are depending on the trigger to populate the
key column, then you won't see the new ID column until the transaction commits.

If you want to see it BEFORE the transactions commits, you must fetch it
from the generator before you post the insert. You will need a way to do
this and there are several. With IB Objects you can do it transparently by
using the GeneratorLinks property of the dataset.

This is how I do it for non-IB Objects applications:
Declare this function:

function GetGeneratorValue(GeneratorName: String;): integer;
var
Q: TIBQuery;
begin
Q := TIBQuery.Create(nil);
with Q do
try
DatabaseName := TheDatabase; // check these property names, IBX
might be slightly different from BDE
Transaction := TheTransaction; // ditto
SQL.Add('Select GenID(' + GeneratorName + ',1) from RDB$Database');
Prepare;
Open;
Result := Fields[0].Value;
Close;
finally
Free;
end;
end;

Then, in your BeforeInsert event, include this call:

Table1.FieldByName('IDField').AsInteger :=
GetGeneratorValue('TheGenerator');

Check those property names of TIBDatabase and TIBQuery for IBX - I can't as
I no longer have IBX installed on my system.

Others use a stored procedure that does the same. IB Objects and FIB-Plus
have methods and properties that make it unnecessary.

Helen

All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________