[fpc-pascal] How can retrive value from OUT parameter?
takubo at e-parcel.co.jp
Fri Apr 19 09:26:31 CEST 2013
Thank you very much for your advice. I am sure your
code should work, but unfortunately I can not modify
the existing stored procedures.
I will explain what I have been trying so far.
Suppose you are using the following stored procedure,
CREATE procedure [dbo].[IncValue]
@Param int OUTPUT
SET NOCOUNT ON
set @Param = @Param + 1
The original program uses TADOStoredProc in Delphi 7,
which is very easy to handle stored procedure.
How to use it is like this:
DBP.Parameters.ParamValues['@Param']:=3; //set @Param as 3
r:=DBP.Parameters.ParamValues['@RETURN_VALUE']; //got r=100, OK!
i:=DBP.Parameters.ParamValues['@Param']; //got i=4, incremented OK!
If you don't have TADOStored, still you can do the equivalent thing
by using TADOQuery. (a little tricky, though...)
DBQ.Parameters.CreateParameter('@Param',ftInteger,pdInputOutput,0,3); //set @Param as 3
r:=DBQ.Parameters.ParamValues['@RETURN_VALUE']; //got r=100, OK!
i:=DBQ.Parameters.ParamValues['@Param']; //got i=4, incremented OK!
With analogical thinking, I expected that the following might work
for TSQLQuery in FPC:
r:=DBQ.ParamByName('@RETURN_VALUE').AsInteger; //got r=0, NG
i:=DBQ.ParamByName('@Param').AsInteger; //got i=3, unchanged NG
It does not work as I expected.
I read fpc db tutorials and googled, but I could not find the answer for
this specific issue. Would anyone have an idea which of the following
is the truth?
1. My program is wrong or incomplete.
2. TSQLQuery (or TMSSQLConnection) does not support OUTPUT parameter.
3. TSQLQuery should be able to handle OUTPUT parameter, but currently a bug exists.
Thank you very much for reading my long mail.
(2013/04/19 12:47), dmitry boyarintsev wrote:
> Hello Toru,
> Not sure if it works with SQLdb or ADO, but it has been working for some other tasks that I've been involved with (not FPC, but delphi based, though).
> You can have the result as through the select statement.
> Have a TSQLQuery to run the following query:
> SET NOCOUNT ON
> declare @var1 int; -- whatever type of the out parameter you need.
> exec YourStoredProc @outvar = @var1 output
> select @var1 as var1
> var q: TSQLQuery;
> if not q.eof then
> Hope that helps.
> On Wed, Apr 17, 2013 at 11:45 PM, Toru Takubo <takubo at e-parcel.co.jp <mailto:takubo at e-parcel.co.jp>> wrote:
> Hi All,
> I have an application build with Delphi7+ADO connecting
> to MSSQL database, and planning to migrate to FPC+SQLdb.
> It has many stored procedures which have OUT parameters
> to retrieve value from database. I am trying to migrate
> by using TMSSQLConnection+TSQLQuery, but still I can not
> settle it. I can execute and pass values to stored procedures,
> but not the other way. The RETURN_VALUE (default result)
> can not be retrieved either.
> I would appreciate any advice.
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org <mailto:fpc-pascal at lists.freepascal.org>
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
More information about the fpc-pascal