Page 1 of 1

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

Posted: Tue 10 Jan 2017 13:54
by Mahmood_M
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

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

Posted: Wed 11 Jan 2017 12:07
by ViktorV
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);

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

Posted: Fri 20 Jan 2017 09:08
by Mahmood_M
Thanks

This will solve the problem too :

Code: Select all

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

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

Posted: Fri 20 Jan 2017 10:11
by ViktorV
We are glad to see you have found a solution.
Feel free to contact us if you have any further questions about our products.