Subject Re: [firebird-support] How to handle Autonumbering - Parent/Child
Author Nando Dessena
Johan,

J> Are we from Clarion World doing it correctly?

No; you should start a new thread for new questions, instead of
hitting "reply" and then overwrite the subject. You might think it's
the same. Intelligent mail software think otherwise. ;-)

J> CREATE PROCEDURE whatever
J> RETURNS (AUTOINCNO INTEGER) AS
J> BEGIN
J> AUTOINCNO = GEN_ID(column, 1);
J> SUSPEND;
J> END !!
J> SET TERM ; !!

this looks OK to me, except that it's not mandatory to call it with
the "select" syntax flavour. Stored procedure that output a single row
of results can be called with the "execute procedure" syntax as well,
AFAIK. You can get away with "select" and forget my warning, if it's
the same for you.

J> CREATE GENERATOR whatever
J> SET TERM !! ;
J> CREATE TRIGGER whatever FOR FileName
J> ACTIVE BEFORE INSERT POSITION 0
J> AS
J> BEGIN
J> IF new.column IS NULL THEN new.column = GEN_ID(column, 1);
J> END !!
J> SET TERM ; !!

This also looks like old time common practice. You might want to check
for 0 as well as null, to cater for client tools that don't perfectly
understand null (assuming your generator starts returning numbers from
1, as it's the usual case).

P.S. in the listings "column" is a rather stange name for a generator.
As it's FileName for a table, BTW. ;-)

Ciao
--
Nando Dessena
mailto:nandod@...