Solved

Intebase Auto Increment field

Posted on 2001-09-03
3
206 Views
Last Modified: 2010-04-06
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
Comment
Question by:Motaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 6452207
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
 
LVL 10

Expert Comment

by:Jacco
ID: 6452311
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
 
LVL 7

Author Comment

by:Motaz
ID: 6452453
Thanks, I'll try it
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question