[英]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我的 MySQL 数据库上有一个存储过程,其中有 2 个 OUT 参数作为 Blob 类型
I want to get their values as TStream with UniDAC`s SP component, I have tried this code for testing :我想使用 UniDAC 的 SP 组件将它们的值作为 TStream 获取,我已经尝试使用此代码进行测试:
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问题是 Param.AsStream 返回 Nil 但 Param.AsBlob 不是 Nil
When I Call this SP on MySQL directly fUPic have blob data and there is no problem on SP当我在 MySQL 上直接调用这个 SP 时 fUPic 有 blob 数据,SP 上没有问题
I have tried SP.CreateBlobStream() but what I should pass to it`s first parameter as TField ?!我已经尝试过 SP.CreateBlobStream() 但是我应该将什么作为 TField 传递给它的第一个参数?!
I have tried casting to TBlobStream from Param.AsBlob but no chance !我曾尝试从 Param.AsBlob 投射到 TBlobStream 但没有机会!
I want to know how I can get an OUT blob parameter as TStream ?我想知道如何将 OUT blob 参数作为 TStream 获取?
I`m using Delphi XE6 and UniDAC 6.1.4我正在使用 Delphi XE6 和 UniDAC 6.1.4
Use AsBlob
.使用
AsBlob
。 It returns the blob as a byte array.它将 blob 作为字节数组返回。 You can either use that directly, or if you need to access the data via a stream do so with
TBytesStream
.您可以直接使用它,或者如果您需要通过流访问数据,请使用
TBytesStream
。
Stream := TBytesStream.Create(Param.AsBlob);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.