Page 1 of 1
Blob into firebirb
Posted: 08.01.2006, 13:59
by darkbrain
Does Blob field works on firebird? I have a TZTable with a blob field and a memo into a form. I'm trying to save and load memo's lines into/from a Blob field, but nothing happens no exception raised. It shold be the load from stream problem?
tnx,
DarkBrain
Posted: 08.01.2006, 14:44
by aperger
Hello,
I must work! There were some discussion about blob fields in these forum.....
I use ZeOS BLOB fields with FireBird 1.5 (Win32/Linux-kernel_2.6.x), PostgreSQL 8 (Win32/Linux-kernel_2.6.x) and MSSQL2000-ADO (Win32). I use streams to handle them:
Code: Select all
procedure ReadBlobField(ImageField:TBlobField;Image:TImage;DeCompress:boolean);
var
memoStream:TMemoryStream;
compStream:TMemoryStream;
begin
if ImageField.IsNull then begin
memoStream:=TMemoryStream.Create;
Image.AutoSize:=true;
Image.Picture.Bitmap.LoadFromStream(memoStream);
Image.AutoSize:=false;
exit;
end;
memoStream:=TMemoryStream.Create;
if DeCompress then compStream:=TMemoryStream.Create else compStream:=nil;
try
// blob kiolvasása
try
if DeCompress then begin
ImageField.SaveToStream(compStream);
compStream.Position:=0;
DecompressStream(compStream,memoStream);
end else begin
ImageField.SaveToStream(memoStream);
end;
except
on E:Exception do begin
ShowPSError('Blob field reading error: '+#13+E.Message);
memoStream.Size:=0;
if DeCompress then compStream.Size:=0;
end;
end;
try
Image.AutoSize:=true;
memoStream.Position:=0;
Image.Picture.Bitmap.FreePixmap;
Image.Picture.Bitmap.FreeImage;
if memoStream.Size>0 then begin
memoStream.Position:=0;
Image.Picture.Bitmap.LoadFromStream(memoStream);
end;
Image.AutoSize:=false;
except
on E:Exception do ShowPSError('Image creating error: '+#13+E.Message);
end;
finally
memoStream.Free;
if DeCompress then compStream.Free;
end;
end;
procedure WriteBlobParam(ImageParam:TParam;Image:TImage;Compress:boolean);
var
memoStream:TMemoryStream;
compStream:TMemoryStream;
begin
memoStream:=TMemoryStream.Create;
if Compress then compStream:=TMemoryStream.Create else compStream:=nil;
try
Image.Picture.Bitmap.SaveToStream(memoStream);
if memoStream.Size=0 then begin
if AnsiContainsText(DM.conDB.Protocol,'mssql') or
(AnsiContainsText(DM.conDB.Database, 'SQLOLEDB')) then begin
ImageParam.Value:=0
end else begin
ImageParam.Value:=Null;
// ImageParam.LoadFromStream(memoStream,ImageParam.DataType);
end;
end else begin
// memoStream.Size;
memoStream.Position:=0;
if Compress then begin
CompressStream(memoStream,compStream);
compStream.Position:=0;
ImageParam.LoadFromStream(compStream,ImageParam.DataType);
end else begin
memoStream.Position:=0;
ImageParam.LoadFromStream(memoStream,ImageParam.DataType);
end;
memoStream.Position:=0;
end;
finally
memoStream.Free;
if Compress then compStream.Free
end;
end;
Attila Perger
Posted: 09.01.2006, 12:46
by darkbrain
Ok they work. It's all ok if a put a DBMemo, but if i want to do it manually it's doesn't save my strings:
Code: Select all
TZTable1.Edit;
Stream := TZTable1.CreateBlobStream(TZTable.FieldByName('memo'), bmWrite);
try
Memo1.Lines.SaveToStream(Stream);
TZTable1.Post;
finally
Stream.Free;
end;
The LoadFromStream instead work correctly.
Any help or workaround?
tnx,
DarkBrain
Posted: 09.01.2006, 16:35
by darkbrain
Solved with a workaround: i've replaced
with:
bye,
DarkBrain