Subject | RE: [IBO] Primary Key->AutoInc Trigger Chicken & the Egg problem. |
---|---|
Author | Kevin Curtis |
Post date | 2001-02-05T20:52:50Z |
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]
-----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]