1

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 ?

dayat
  • 57
  • 3
  • 8

2 Answers2

1

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;
Ken White
  • 123,280
  • 14
  • 225
  • 444
0

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

ShowMessage(BlobField.AsString);