Solved

Intebase Auto Increment field

Posted on 2001-09-03
3
193 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now