Firebird BYTES data type not compatible with TBlobStream

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
MN7
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 09.09.2019, 11:11

Firebird BYTES data type not compatible with TBlobStream

Post by MN7 »

BYTES field raises error
'Exception TZAbstractCLob in module Test.exe at 00000000007623A6.'
in this code:

Code: Select all

  BlobStream := FZQuery.CreateBlobStream(f, bmRead);
  try
    BlobSize := BlobStream.Size;
    BlobStream.Read(BlobMem^, BlobSize);
  finally
    BlobStream.Free;
  end;
BYTES data field have for example security3.fdb in FB 3.0 installation.
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 766
Joined: 18.11.2018, 17:37
Location: Hungary

Re: Firebird BYTES data type not compatible with TBlobStream

Post by aehimself »

Hello,

You can try reading it to a stream and then converting it to TBytes:

Code: Select all

Var
 ms: TMemoryStream;
 tb: TBytes;
Begin
 ms := TMemoryStream.Create;
 Try
  (ZQuery.FieldByName('TheField') As TBlobField).SaveToStream(ms);
  ms.Position := 0;
  SetLength(tb, ms.Size);
  ms.Read(tb, ms.Size);
  // Do something
 Finally
  FreeAndNil(ms);
 End;
End;
This usually worked for me.
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
MN7
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 09.09.2019, 11:11

Re: Firebird BYTES data type not compatible with TBlobStream

Post by MN7 »

For me works "f.AsBytes".
But "BlobStream := FZQuery.CreateBlobStream(f, bmRead);"
just crashed, not raise EZNotSupported or so (for example).
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Firebird BYTES data type not compatible with TBlobStream

Post by marsupilami »

Which version of Delphi and or / FPC do you use?
MN7
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 09.09.2019, 11:11

Re: Firebird BYTES data type not compatible with TBlobStream

Post by MN7 »

XE4. But test from scratch get new info.

Code: Select all

procedure Test;
var
  ZC: TZConnection;
  ZQ: TZQuery;
  BlobStream: TStream;
  B: TBytes;
begin
  ZC := TZConnection.Create(nil);
  try
    ZQ := TZQuery.Create(ZC);
    ZQ.Connection := ZC;

    ZC.Protocol := 'interbase';
    ZC.User := 'SYSDBA';
    ZC.Password := 'masterkey';
    ZC.LoginPrompt := False;
    ZC.Database := 'Firebird_3_0\security3.fdb'; // with full path
    ZC.Connect;

    ZQ.SQL.Text := 'select * from "PLG$USERS"';
    ZQ.Open;

    B := ZQ.FieldByName('PLG$PASSWD').AsBytes;
    ShowMessage(Length(B).ToString);

    BlobStream := ZQ.CreateBlobStream(ZQ.FieldByName('PLG$PASSWD'), bmRead);
    try
      ShowMessage(BlobStream.Size.ToString);
    finally
      BlobStream.Free;
    end;

  finally
    ZC.Free;
  end;
end;
'Length(B).ToString' show 64,
'BlobStream.Size.ToString' show 0.
Post Reply