mysqldelphistored-proceduresblobunidac

Get an OUT BLOB type Parameter of a Stored Procedure as TStream


I have a stored procedure on my MySQL Database with 2 OUT parameters as Blob type

I want to get their values as TStream with UniDAC`s SP component, I have tried this code for testing :

 SP := TUniStoredProc.Create(nil);
 M := TMemoryStream.Create;
 try      
  try
   SP.StoredProcName := 'user_getpic';
   SP.PrepareSQL(False);

   SP.Params.ParamByName('fUID').AsString := '...';
   SP.Params.ParamByName('fDiceCode').AsString := '...';
   ...

   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;

The problem is 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 have tried casting to TBlobStream from Param.AsBlob but no chance !

I want to know how I can get an OUT blob parameter as TStream ?

I`m using Delphi XE6 and UniDAC 6.1.4


Solution

  • Use AsBlob. It returns the blob as a byte array. You can either use that directly, or if you need to access the data via a stream do so with TBytesStream.

    Stream := TBytesStream.Create(Param.AsBlob);