Blob into firebirb

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
darkbrain
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 28.12.2005, 11:56

Blob into firebirb

Post 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
User avatar
aperger
Expert Boarder
Expert Boarder
Posts: 129
Joined: 24.08.2005, 08:24
Location: Veszprém
Contact:

Post 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
darkbrain
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 28.12.2005, 11:56

Post 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
darkbrain
Fresh Boarder
Fresh Boarder
Posts: 13
Joined: 28.12.2005, 11:56

Post by darkbrain »

Solved with a workaround: i've replaced

Code: Select all

Memo1.Lines.SaveToStream(Stream);
with:

Code: Select all

stream.WriteComponent(Memo1);
bye,
DarkBrain
Post Reply