Solved

Intebase Auto Increment field

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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