Subject RE: Delphi + Firebird specific
Author Mick Arundell
Your Method is really inefficient.
A far better way to operate is to query database to get the RowId for your
master record and then set it in your table.

for example

create a query or keep one on hand like
select gen_id(GenWhitepage, 1) from RDB$DATABASE

fieldByName('WpIDSQ').asInteger := Query.Fields[0].asInteger

free your query.

and apply Id to appropriate field in Client data records.

Scanning databases for most recent RowId is an unsafe hangover from desktop
file based databases and AfterPost methods only work if the refresh sql is
set to suit.

Some components (FIB+) have a built in Gen_Id function and you can easily
put one in your datamodule that works with all the tables and generators you
specify.

Mick


If this forum is not the right one to answer my question would somebody
then please redirect me to the correct messagebord.

I have 2 tables one is the master one the slave. When I insert a record
into the master record everything is file. It calls the appropirate trigger
and the records is assigned a unique identifier for its primary key through
a generator.

DtSrcMaster.DataSet.AppendRecord([0,TheName,TheDescription]) ;

So far so good. This is the trigger.

CREATE TRIGGER TrigGenWhitePage FOR Whitepage
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF ((NEW.WpIDSQ = 0) OR (NEW.WpIDSQ IS NULL)) THEN
NEW.WpIDSQ = GEN_ID(GenWhitepage,1) ;
END !!

Then I immediately query the current master record for its primary key so I
can link the child record to the master record.