Subject Re: [ib-support] Returning ID on insert
Author Martijn Tonies
Hi,

> I am using Delphi 6 C/S and Firebird 1.0.0.338. I have a table that
contains a primary key, the value of which is supplied by a generator at
insert time. When I insert a new record I need the value of the primary Key
returned to me ( I am using it as a pointer from a record in another
table ). I wrote the stored procedure below but I get a parameter
mismatch error from Delphi. Could anyone explain to me the proper way to
return an autogenerated value from an insert procecure.
>

You cannot read the auto-generated value by the trigger (at least not multi
user safe).

Change your procedure to:

> Create PROCEDURE INTEGERVALUES_I
> (
> IV_VALUE INTEGER,
> IV_DEFAULT INTEGER,
> IV_MIN INTEGER,
> IV_MAX INTEGER
> )
> RETURNS
> (
> IV_ID INTEGER // this is the value I need returned. It is created by
a generator before insert
> )
> AS
> BEGIN

:IV_ID = gen_id(mygen, 1);

> INSERT INTO INTEGERVALUES (
> IV_VALUE,
> IV_DEFAULT,
> IV_MIN,
> IV_MAX,
IV_ID)
> VALUES (
> :IV_VALUE,
> :IV_DEFAULT,
> :IV_MIN,
> :IV_MAX,
:IV_ID);
> END

Hope this helps,

Martijn Tonies
InterBase Workbench - the developer tool for InterBase and Firebird
http://www.interbaseworkbench.com

Upscene Productions
http://www.upscene.com

"This is an object-oriented system.
If we change anything, the users object."