恢复在sql数据库中存储为blob的文档

时间:2016-01-19 11:07:44

标签: sql-server delphi blob documents

我从客户那里得到了一个sql数据库。在sql数据库中有一个名为" documents"的表。文档存储为blob(查看屏幕截图)。

我想通过Delphi(FileStream?)恢复文件。你有什么想法怎么做吗?

此致 丹尼斯弗里德里希

Screenshot table documents

1 个答案:

答案 0 :(得分:1)

function SaveFieldBlobToFile(FQuery: TDataSet): boolean;
var MyStream : TMemoryStream;
begin
   Result:= false;
   MyStream:= TMemoryStream.Create;
   try
     (FQuery.Fieldbyname('MODELE') as TBlobField).SaveToStream(MyStream);
    if (MyStream<>nil) and (MyStream.Size > 0) then
    begin
      MyStream.Position := 0;
      MyStream.SaveToFile('C:\Temp\tempMyFile.zip');
      Result:= true;
    end
    else Result:= false;
  finally
    MyStream.Free;
  end;
end;


function LoadFileToBlob(FQuery: TDataSet): boolean;
var MyStream : TMemoryStream;
begin
  Result:= false;
  MyStream := TMemoryStream.Create;
  try
    MyStream.LoadFromFile('C:\Temp\tempMyFile.zip');
    MyStream.Position := 0;
    TryEdit(FQuery);
    (FQuery.FieldByName('MODELE') As TBlobField).LoadFromStream(MyStream);
    TryPost(FQuery);
    Result := True;
  finally
    MyStream.Free;
  end;
end;