Forum Discussion

david_creelman's avatar
12 years ago

Need to save a blob from an ADO db field to a file

Hi,

I've tried the following while attempting to save a blob field off to a file.



The blob contains a PDF file.

I want to save the PDF off to a file.


procedure test;



var

 
qry, f, value: OleVariant;



 sql: string;



  i: Integer;



  val: char;



begin



  sql := 'select FILE_CONTENTS from PA_DOCUMENTS';



  qry := Query(SQL, 1);



  value := qry.Field[0].AsVariant;



// qry.FieldByNam



  f := aqFile.OpenBinaryFile('c:\test.pdf', aqFile.faWrite, true);



  for i:= 1 to Length(value) -1 do



  begin



//Log.Message(value);



    val := ord(value);



    log.message(VarToStr(val) + ' ' + VarToStr(value));



    f.Write(val);



  end;



  f.Close;

end;



The above code fails when it trys to write out what looks like a non-ASCII character (the pound symbol).



Any bright ideas about how to do this?



Regards

David