Link to home
Start Free TrialLog in
Avatar of Stefan van Roosmalen
Stefan van Roosmalen

asked on

Lazarus: saving BLOBs from Sybase database

Hi there,

I am trying to save files which are stored in BLOB fields in a Sybase database.

The routine below seems to work, files are being saved in my folder, but when opening them they seem to be corrupt. For example when I open a Word or Excel file it needs to be repaired (by Office) before I can read the contents.

procedure TForm1.saveBlobs;
var tmpFilename: String;
    tmpList: TStringList;
begin
  Query1.First;
  While not Query1.Eof do begin
    tmpFilename := prgPath + '_output\' + Query1.FieldByName('DOCU_ORG_FILENAME').AsString;

    tmpList := TStringList.Create;
    tmpList.Append(Query1.FieldByName('DOCU_DOCUMENT').AsVariant);
    tmpList.SaveToFile(tmpFilename);
    tmpList.Free;

    Query1.Next;
  end;
end;

Open in new window

Could my routine be the root cause of these corruptions?

Could you please help me out? Notice: I am using Lazarus (@Windows), not all Delphi stuff is available.

Kind Regards,
Stefan
ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stefan van Roosmalen
Stefan van Roosmalen

ASKER

I have tried this but then I run into this error during compiling:
Error: Identifier not found "CreateBlobStream"
But I have found the trick:
BlobStream := Query1.CreateBlobStream(Query1.FieldByName('DOCU_DOCUMENT'), bmRead);

Open in new window

You have helped me with the right direction... thanks!