Subject Re: Exexcutable Stored Procedures
Author yahdominiek
> > Yes, but there seems to be no way of retrieving the 'RETURNING_VALUES'
> > without the use of 'suspend' and thus turning it into a selectable
> > stored procedure which is then unusable in DBExpress for instance.
> >
> > I find it very tedious to have an executable stored procedure
> > for 'normal' use and a selectable one which simply wraps the
executable.
> >
> > I know it's not part of DSQL but it would be very nice to be able to
> > use the same SP in each and every approach to Firebird.
> >
> > just my 2 cents...
> >
> > Dominiek D'hondt
>
> ??? can you explain this a bit more? I still can't see what your
problem is.
> Maybe give us the two SPs?
> Alan

Sorry for being unclear
it must be Friday :)

the executable SP :

SET TERM ^^ ;
CREATE PROCEDURE P_X_GETTEKST (
ITEM Integer,
LNG SmallInt,
CMP SmallInt)
returns (
TXT VarChar(1024))
AS
begin
SELECT A.TEKST
FROM TRANSLATIONS A
WHERE ((A.TEXT_ID = :item) AND (A.LANGUAGE_ID = :lng))
INTO :txt;

IF (txt IS NULL) THEN BEGIN
SELECT A.TEKST
FROM TRANSLATIONS A
WHERE ((A.TEXT_ID = :item) AND
(A.LANGUAGE_ID = (SELECT B.DEFLANG
FROM COMPANY_PARAMS B
WHERE COMPANY_ID = :cmp)))
INTO :txt;

END
end
^^
SET TERM ; ^^

Remark : no 'SUSPEND';
Output is through the return parameter.

In Delphi, DBExpress has a component TSQLStoredProcedure which I can
use like this :
//// the component is connected to the SP and :
////
SPGetTekst.ParamByName('ITEM').AsInteger := FiItem;
SPGetTekst.ParamByName('LNG').AsSmallInt := FiLang;
SPGetTekst.ParamByName('CMP').AsSmallint := FiComp;
SPGetTekst.ExecProc;
sTekst := SPGetTekst.ParamByName('TXT').AsString;
////
just setting of input parameters, executing and reading of
outputparameter(s).
no need for TSQLQuery...

I have found no way of doing this in PHP/FB except for making a
wrapper SELECTABLE SP :

SET TERM ^^ ;
CREATE PROCEDURE P_C_GETTEKST (
ITEM Integer,
LNG SmallInt,
CMP SmallInt)
returns (
TXT VarChar(1024))
AS
begin
EXECUTE PROCEDURE P_X_GETTEKST (:item, :lng, :cmp)
RETURNING_VALUES (:txt);
suspend;
end
^^
SET TERM ; ^^

This I use like this:

function fb_gettekst($item, $lng, $cmp)
{
$fbconn = fb_connect();
$stmt = "SELECT * FROM P_C_GETTEKST ( ? , ?, ? )";
$fbqry = ibase_prepare($fbconn, $stmt);
$res = ibase_execute($fbqry, $item, $lng, $cmp);
$result = ibase_fetch_row($res);
ibase_free_query($fbqry);
ibase_close($fbconn);

return htmlentities($result[0]);
}

It's the need for the wrapper-SP that bothers me. I have to make this
for all existing executable SP's while I'd wish to use them as they are.
I hope I make sense this time :)

Dominiek D'hondt