Subject | Re: [ib-support] Returning ID on insert |
---|---|
Author | Martijn Tonies |
Post date | 2002-05-06T12:34:43Z |
Hi,
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.
user safe).
Change your procedure to:
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."
> I am using Delphi 6 C/S and Firebird 1.0.0.338. I have a table thatcontains 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_Ia generator before insert
> (
> 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
> ):IV_ID = gen_id(mygen, 1);
> AS
> BEGIN
> INSERT INTO INTEGERVALUES (IV_ID)
> IV_VALUE,
> IV_DEFAULT,
> IV_MIN,
> IV_MAX,
> VALUES (:IV_ID);
> :IV_VALUE,
> :IV_DEFAULT,
> :IV_MIN,
> :IV_MAX,
> ENDHope 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."