Subject Re: [firebird-support] Problem with my first stored procedure
Author Dimitry Sibiryakov
On 19 Apr 2005 at 13:57, Grant Brown wrote:

>When I try calling the following function I get ant exception when the
>Prepare statement is executed.

You could show us the error message...

>Could someone show me what I am doing wrong ?

Almost everything.

>SaveStoredProc.SQL is declared as
>
>EXECUTE PROCEDURE P_SAVE_DATA_LIST_ITEM (?FDTYPE, ?ITEM01,
>?CUR_DETECT_ID, ?RESULTID)

Your procedure has only _three_ input parameters. Remove the last.

> Params[0].Value := DT;
> Params[1].Value := ItemText;
> Params[2].Value := DetectID;

Using variants is not good practice, I'd say.

> Prepare;
> ExecProc;
> DetectID := Params[3].Value;

AFAIR, output parameters are accessed through Fields[] property.
Read FIB manual.

> if Transaction.InTransaction then Transaction.Commit;

Transaction here is in transaction for sure, so the check is
redundant.

Procedures that update a record or insert new one if it does not
exists usually look like this:

BEGIN
PK_VAR = NULL;
FOR SELECT PK_FIELD FROM A_TABLE WHERE ..... INTO :PK_VAR AS CURSOR
T DO
UPDATE A_TABLE SET ... WHERE CURRENT OF CURSOR Tl

IF(PK_VAR IS NULL) THEN
INSERT INTO A_TABLE ....;
END

>SiteDoc - Easy to Use - Powerful Results
>
>This email and any attached files (of whatsoever nature) are
>confidential, may be privileged and intended solely for the use of the
>intended recipient and are subject to copyright and the Privacy Act
>(Cth) Any confidentiality or privilege is not lost or waived because
>of any error in sending this email to you. If you have received this
>email in error, please advise by return email, delete it from your
>system and destroy any copies. Our company is not responsible for any
>viruses or harmful programs passed on down via email. You should have
>installed, up to date virus scanning software. The views expressed in
>this email are those of the sender and should not necessarily be taken
>as those of the company.

What to hell is this? Spam, I suppose.
--
SY, Dimitry Sibiryakov.