Ubuntu 20.04 + Lazarus 2.0.12
I use the IBSQL component from ibx4lazarus2. 4-0 to access the Firebird 3 database
I need to write and read a BLOB field from my database.
There are no problems with reading from db:
IBSQL1.FieldByName('blob').AsBlob.SaveToFile(MyFile);
I get the desired file.
But writing to db does not work:
IBSQL1.ParamByName('blob').AsBlob.LoadFromFile(MyFile);
The problem is that you are using TIBSQL in the way that you would use TIBDataset. However, TIBSQL is working directly with the underlying Firebird interface and that requires a different approach.
The call to ParamByName('blob').AsBlob returns the interface IBlob. The input parameter has not yet been set and so this always returns nil - hence the exception.
To set the value of the blob, you have to create a TIBBlobstream, load it from a file and assign the IBlob interface returned by TIBBlobStream to the param e.g.
var b:TIBBlobStream;
begin
b := TIBBlobStream.create;
try
b.Database := IBSQL.Database;
b.Mode := bmWrite;
b.LoadFromFile(...);
IBSQL.ParamByName('blob').asBlob := b.blob;
finally
b.free;
end;