• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

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
0
Motaz
Asked:
Motaz
1 Solution
 
kretzschmarCommented:
usually i use in the afterinsert
table1.fieldByName('ID').AsInteger := -1;

in the beforepost event i use
if table1.state = dsinsert then
  table1.fieldByName('ID').AsInteger := GetID;

whereas getID is a function which uses a stored proc like

function getID : integer;
begin
  try
    storedproc1.execute;
    result := storedproc1.parambayname('ID').asinteger;
  except
    raise;
  end;
end;

in interbase the procedure is like
(have the correct syntax not in mind)

procedure getid(ID Integer)
is
begin
  id = gen_id(mygen,1);
end;

meikl ;-)



0
 
JaccoCommented:
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.
0
 
MotazAuthor Commented:
Thanks, I'll try it
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now