Getting Value of a Blob type OUT Parameter from a MySQL SP

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Mahmood_M
Posts: 20
Joined: Thu 24 Sep 2015 21:18

Getting Value of a Blob type OUT Parameter from a MySQL SP

Post by Mahmood_M » Tue 10 Jan 2017 13:54

Hi
I have a Stored Procedure on my MySQL Database with 2 Blob parameters as OUT Parameter
I want to get their values as TStream, I have tried this code for test :

Code: Select all

 SP := TUniStoredProc.Create(nil);
 M := TMemoryStream.Create;
 try
  SP.StoredProcName := 'user_getpic';
  SP.PrepareSQL(False);
  try
   SP.Params.ParamByName('fUID').AsString := '';
   SP.Params.ParamByName('fDiceCode').AsString := '00010052';
   ...

   SP.ExecProc;

   M.LoadFromStream(SP.Params.ParamByName('fUPic').AsStream);
  except
   on E:EXception do
    begin
     ShowMessage('Error : ' + E.Message);
    end;
  end;
 finally
  SP.Free;
  M.Free;
 end
;

There is an AV on LoadFromStream of M because the Param.AsStream returns Nil but Param.AsBlob is not Nil
When I Call this SP on MySQL directly fUPic have blob data and there is no problem on SP
I have tried SP.CreateBlobStream() but what I should pass to it`s first parameter as TField ?!
I want to know how I can get an OUT blob parameter as TStream ?

I`m using Delphi XE6 and UniDAC 6.1.4
thanks

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Getting Value of a Blob type OUT Parameter from a MySQL SP

Post by ViktorV » Wed 11 Jan 2017 12:07

To solve the problem, please replace the line in your code:

Code: Select all

  M.LoadFromStream(SP.Params.ParamByName('fUPic').AsStream);
with

Code: Select all

  SP.Params.ParamByName('fUPic').AsBlobRef.SaveToStream(M);

Mahmood_M
Posts: 20
Joined: Thu 24 Sep 2015 21:18

Re: Getting Value of a Blob type OUT Parameter from a MySQL SP

Post by Mahmood_M » Fri 20 Jan 2017 09:08

Thanks

This will solve the problem too :

Code: Select all

M.LoadFromStream(TBytesStream.Create(SP.Params.ParamByName('fUPic').AsBlob));

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Getting Value of a Blob type OUT Parameter from a MySQL SP

Post by ViktorV » Fri 20 Jan 2017 10:11

We are glad to see you have found a solution.
Feel free to contact us if you have any further questions about our products.

Post Reply