Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Intebase Auto Increment field

Posted on 2001-09-03
3
Medium Priority
?
213 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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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