Blob 到 String:如何将 PostgreSQL 中的 StoredProcedure 参数中的 Blob 转换为字符串?

发布于 2025-01-06 04:54:17 字数 917 浏览 1 评论 0原文

我有这样的参数类型的存储过程(Postgres 中的函数):

Params[0] : result = ftBlob // postgresql function = text
Params[1] : 1 = ftString
Params[2] : 2 = ftInteger
Params[3] : 3 = ftInteger

我的代码是这样的:

procedure TForm1.Button1Click(Sender: TObject);
var
  ResultStr: TResultStr;
  BlobField: TBlobField;
  bStream: TStream;
  DataSet: TDataSet;
  StoredProc: TSQLStoredProc;
begin
  sp01.Close;
  sp01.Params[1].AsString := '2010/2011';
  sp01.Params[2].AsInteger := 2;
  sp01.Params[3].AsInteger := 1;
  sp01.ExecProc;

  if sp01.ParamByName('result').Value.IsBlob then
  begin
    BlobField := StoredProc.ParamByName('result') as TBlobField;
    bStream := sp01.CreateBlobStream(BlobField, bmRead);
    try
      bStream.Read(ResultStr,sizeof(TResultStr));
    finally
      bStream.Free;
    end;
  end;

  ShowMessage(ResultStr.Hasil);
end;

问题是,我想如何让结果(Blob)变成字符串?

I have stored procedure (function in Postgres) with type of parameter like this :

Params[0] : result = ftBlob // postgresql function = text
Params[1] : 1 = ftString
Params[2] : 2 = ftInteger
Params[3] : 3 = ftInteger

my code is like this :

procedure TForm1.Button1Click(Sender: TObject);
var
  ResultStr: TResultStr;
  BlobField: TBlobField;
  bStream: TStream;
  DataSet: TDataSet;
  StoredProc: TSQLStoredProc;
begin
  sp01.Close;
  sp01.Params[1].AsString := '2010/2011';
  sp01.Params[2].AsInteger := 2;
  sp01.Params[3].AsInteger := 1;
  sp01.ExecProc;

  if sp01.ParamByName('result').Value.IsBlob then
  begin
    BlobField := StoredProc.ParamByName('result') as TBlobField;
    bStream := sp01.CreateBlobStream(BlobField, bmRead);
    try
      bStream.Read(ResultStr,sizeof(TResultStr));
    finally
      bStream.Free;
    end;
  end;

  ShowMessage(ResultStr.Hasil);
end;

the question is, how do I want to get the result (Blob) become string ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少女净妖师 2025-01-13 04:54:17

我不知道 TResultString 是什么,但你可以用字符串来做到这一点:

var
  BlobResult: string;  // Changed to make clearer where changes were below
begin
  // Your other code here

  if sp01.ParamByName('result').Value.IsBlob then
  begin
    BlobField := StoredProc.ParamByName('result') as TBlobField;
    bStream := sp01.CreateBlobStream(BlobField, bmRead);
    try
      SetLength(BlobResult, bStream.Size);         // Note changes here
      bStream.Read(BlobResult[1], bStream.Size);   // and here
    finally
      bStream.Free;
    end;
  end;

I don't know what TResultString is, but you can do it with a string:

var
  BlobResult: string;  // Changed to make clearer where changes were below
begin
  // Your other code here

  if sp01.ParamByName('result').Value.IsBlob then
  begin
    BlobField := StoredProc.ParamByName('result') as TBlobField;
    bStream := sp01.CreateBlobStream(BlobField, bmRead);
    try
      SetLength(BlobResult, bStream.Size);         // Note changes here
      bStream.Read(BlobResult[1], bStream.Size);   // and here
    finally
      bStream.Free;
    end;
  end;
梦罢 2025-01-13 04:54:17

这是一篇旧帖子,但如果将来有人需要的话。

ShowMessage(BlobField.AsString);

This is an old post but if anyone needs in the future.

ShowMessage(BlobField.AsString);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文