Link to home
Start Free TrialLog in
Avatar of Motaz
Motaz

asked on

Intebase Auto Increment field

I'm using Interbase 5.
My problem is that I want to apply the Auto-Increment field in dbGrid that linked with Interbase in Delphi.

I'm using generator, and I'm tring to use trigger:

create trigger for Test after insert as
begin
Ā  Test.ID = Gen_ID(TestGen, 1);
end

it compiles successfully but it do nothing, also what must I do for NOT NULL in primary key (Auto Inc)

I tried also to make it the default value in fields definition:

create Table Test (ID Integer not null primary key default Gen_ID(TestGen, 1), Name VarChar(30));

Also I'm getting an error on that (unknown function -Gen_ID )

Motaz Abdel Azeem
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I believe in Delphi 5 there is a property AutoInc of the TField. If you set it to true it might work better.

Also if you have the trigger you don't need the default.

The method meikle describes is a better approach (although a bit more work when you have a lot of generator keyed tables. It is hard (if not impossible) for delphi to retrieve the record if it doesn't know the primary key at the time of posting the record.

Regards Jacco.
Avatar of Motaz
Motaz

ASKER

Thanks, I'll try it