How can I save a File in my Database?

Patrick

Member
Hi,

i'm using Delphi 5 Enterprise and want to save Files (PDF, EXE ... ) in my database. In my table there is a "BLOB" Field.
The connection to the database is enabled an i can see the content from my table.

When i click on a button, i want to save a file from a temporary directory in my table.

Can someone tell me how to realize this ?
 
I have included an example below:

Code:
var LOB: TLOBLocator;
begin
  with BLOBInsertQuery do // insert into jpg_table (:v_id, :v_image)
  begin
    SetVariable('v_id', 1);
    // Create a new temporary BLOB and write the data
    LOB := TLOBLocator.CreateTemporary(Session, otBLOB, True);
    LOB.LoadFromFile('c:\temp\image1.jpg');
    // Assign it to the BLOB variable
    SetComplexVariable('v_image', LOB);
    // Execute insert statement and commit
    Execute;
    Session.Commit;
    // Free the BLOB
    LOB.Free;
  end;
end;
 
Thanks for your example.
But now i have the following problem. If i want to write the File in my table i get the error "Variable :ID not declared"
How can i fix this problem?

This is my code:

Code:
var
  myLob : TLOBlocator;
begin

  with oQuery do
  begin
    SetVariable('ID', 2);
    SetVariable('TEXTFELD', 'TOAST');
    SetVariable('NUMMERNFELD', 2);
    myLob := TLOBLocator.CreateTemporary(os1, otBLOB, True);
    myLob.LoadFromFile('C:\temp\TOAST.pdf');
    SetComplexVariable('BLOB', myLob);
    Execute;
    os1.Commit;
    myLob.Free;
  end;

end;
 
Back
Top