Subject Help! Storing Blob image using IBO after upgrading FB 1.5 to 2.1 no longer works.
Author Chuck Belanger
Hello and HELP!

I've been using the following code for a number of years with IBO
(4.8.7) and Firebird 1.5 no problems. Everything works to store the URL
image file into the DB.

I changed to FB 2.1 a few months ago and am just getting around to
retesting this code, and it simply does not work!

The first event code is for IBO TDataset use and the second is for
native use. I tried both and they do not work.

The Blob field, ML_ITEM_IMAGE is subtype 0. I store JPG, GIF, BMP to it.

Can some please let me know what is up?

IBO TDataset:

procedure TMainForm.JvUrlListGrabber1DoneStream(Sender: TJvUrlListGrabber;
Grabber: TJvCustomUrlGrabber; Stream: TStream; StreamSize: integer;
Url: string);
//from jvcl examples
var
blobstream: TStream;

begin
//add line to message that stream is done
frmURLStatus.memStatus.Lines.Add('Download of ' + URL +' complete.');

with dsMLItem.DataSet do
begin
try
Edit;
blobstream := CreateBlobStream(FieldByName('ml_item_image') as
TBlobField, bmwrite);
try
begin
//10/8/09 Stream.size to StreamSize
blobstream.copyfrom(Stream, StreamSize);
end;
except
blobstream.Free;
dsMLItem.Dataset.Cancel;
end;
if (State in [dsInsert, dsEdit]) then
begin
Post; // Optional
//helen bonnie recommends commit, not commit retain as in autocommit
//to properly clean ups BLOBs, since the previous blob remains, i.e.
//garbage collection occurs with commit not autocommit or
committ-retain
ModData.IB_Transaction1.Commit;
end;
except
DoFPShowMessage('Invalid Picture!',0);
end
end;
try
LoadDBImage('mlVST', True, dsMLItem, fcMLTImager);
except
begin
DoFPShowMessage(URL + ' is not a valid image file.',0);
DLImage := False;
exit;
end;
end;

//picture added
frmURLStatus.memStatus.Lines.Add('Image added to database.');
frmURLStatus.memStatus.Lines.Add('Good bye!');
//reset status bar when image transfer done
frmURLStatus.fcProgressBar1.Progress := 0;
frmURLStatus.Close;



fcStatusBar1.Update;
end;

Native IBO

procedure TMainForm.JvUrlListGrabber1DoneStream(Sender: TJvUrlListGrabber;
Grabber: TJvCustomUrlGrabber; Stream: TStream; StreamSize: integer;
Url: string);
var
BinaryBlob : TIB_ColumnBlob; // Store static reference for performance.

begin
with ModData.dsql_AnyUse2 do
begin

BeginBusy( true );

SQL.Clear;
SQL.Add('Update MasterLibrary ');
SQL.ADD('Set ML_ITEM_IMAGE = :NewImage ');
SQL.ADD('Where ML_ID = :MLID');
Prepare;

ParamByName('MLID').asInteger :=
qryMLItem.FieldByName('ML_ID').asInteger;
// Use a direct pointer instead of ParamByName for every insert/update.
BinaryBlob := TIB_ColumnBlob(ParamByName('NewImage'));
try
BinaryBlob.Assign(Stream); //this is the equivalent to LoadFromStream
ExecSQL;

Moddata.IB_Transaction1.Commit;

Finally
EndBusy;
qryMLItem.Refresh;
end;
end;
try
LoadDBImage('mlVST', True, dsMLItem, fcMLTImager);
except
begin
DoFPShowMessage(URL + ' is not a valid image file.',0);
DLImage := False;
exit;
end;
end;
end;