Subject RE: [IBO] Primary Key->AutoInc Trigger Chicken & the Egg problem.
Author Kevin Curtis
Opps, I spoke too soon. I am still receiving the message from the Dataset's
Post method that the CUST_NO field must have a value. Again, is there anyway
to eliminate this message without having to manually assign it in a
BeforePost method?

Thanks again!
Kevin

-----Original Message-----
From: Kevin Curtis [mailto:Kevin@...]
Sent: Monday, February 05, 2001 2:53 PM
To: IBObjects@yahoogroups.com
Subject: RE: [IBO] Primary Key->AutoInc Trigger Chicken & the Egg problem.


You've answered it perfectly. Thanks Helen!

-----Original Message-----
From: Helen Borrie [mailto:helebor@...]
Sent: Monday, February 05, 2001 8:43 AM
To: IBObjects@yahoogroups.com
Subject: Re: [IBO] Primary Key->AutoInc Trigger Chicken & the Egg problem.


Use the GeneratorLinks property and read FieldByName in the AfterPost
event.

Change the trigger to this:

CREATE TRIGGER INSERT_CREATE_DATE FOR "Customers"
ACTIVE BEFORE INSERT POSITION 0
as
begin
NEW.CREATE_DATE = 'NOW';
NEW.EDIT_DATE = NEW.CREATE_DATE;
if (new.Cust_No is null) then
NEW.CUST_NO = GEN_ID(gen_nextcustno, 1);
end

Reserve the firing of the trigger to interactive work; or perhaps for
batch work like pumping.

If you want to get the value *before* you post the insert, remove the
GeneratorLinks setting and call the Gen_ID() method in the AfterInsert
event, i.e.

with myDataset.InternalDataset do
begin
FieldByName('CUST_NO').AsInteger := Gen_ID(gen_nextcustno, 1);
...
end;

I guess you know that cancelling the transaction doesn't "roll back" the
generator. The number stays generated.

Helen





[Non-text portions of this message have been removed]



Yahoo! Groups Sponsor

www. .com