Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone perhaps give me some id 1

Status
Not open for further replies.

delphiman

Programmer
Dec 13, 2001
422
ZA
Can someone perhaps give me some ideas please?

Unlike an MS-SQL DataBase the IB-SQL dataBase does not have an "AutoIncrement" field and one has to handle this with a Generator.

Which works fine BUT the number does not arrive into the field "UponNewRecord" as I would have expected - so that UpDate crashes.

I can force a (hard-coded) "1" into it - which works with the DataBase simply correcting it to whatever the number is supposed to be when I leave the program - when for some mysterious reason THEN UpDate works. As becomes obvious after I go back into the program.

But that is too late for what I am doing.

Does someone know of code .... something like "INC(MyTableTheField)" whereby the correct number will
be forced into the field?

 
The are two ways (at least ;-)) using generators:
0. create a generator:
CREATE GENERATOR GEN_MYTABLE_ID;

1. write an insert trigger:
CREATE TRIGGER TRG_MYTABLE_ID FOR MYTABLE BEFORE INSERT POSITION 0 AS BEGIN
IF (NEW.ID IS NULL) THEN NEW.ID=GEN_ID(GEN_MYTABLE_ID, 1);
END;

2. do it manually:
insert into MYTABLE (ID, ...) values (
(select gen_id(GEN_MYTABLE_ID, 1) from rdb$database), ...)

Otto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top