Subject | Re: [ib-support] Returning ID on insert |
---|---|
Author | Lucas Franzen |
Post date | 2002-05-06T12:39:08Z |
Bob Lazarchik schrieb:
IF ( NEW.IV_VALUE IS NULL ) THEN NEW.IV_VALUE = GEN_ID ( G_GENNAME, 1
);
Change your procedure to:
Create PROCEDURE INTEGERVALUES_I
(
IV_VALUE INTEGER,
IV_DEFAULT INTEGER,
IV_MIN INTEGER,
IV_MAX INTEGER
)
RETURNS ( IV_ID INTEGER )
AS
BEGIN
IV_ID = GEN_ID ( G_GENNAME, 1 );
INSERT INTO INTEGERVALUES (
IV_VALUE, IV_DEFAULT, IV_MIN, IV_MAX )
VALUES ( :IV_ID, :IV_DEFAULT, :IV_MIN, :IV_MAX );
END
If you supply the value in a trigger there's no way to get this balue
back directly; neither to the client to a stored procedure.
HTH
Luc.
>Change your trigger to:
> 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.
IF ( NEW.IV_VALUE IS NULL ) THEN NEW.IV_VALUE = GEN_ID ( G_GENNAME, 1
);
Change your procedure to:
Create PROCEDURE INTEGERVALUES_I
(
IV_VALUE INTEGER,
IV_DEFAULT INTEGER,
IV_MIN INTEGER,
IV_MAX INTEGER
)
RETURNS ( IV_ID INTEGER )
AS
BEGIN
IV_ID = GEN_ID ( G_GENNAME, 1 );
INSERT INTO INTEGERVALUES (
IV_VALUE, IV_DEFAULT, IV_MIN, IV_MAX )
VALUES ( :IV_ID, :IV_DEFAULT, :IV_MIN, :IV_MAX );
END
If you supply the value in a trigger there's no way to get this balue
back directly; neither to the client to a stored procedure.
HTH
Luc.