Page 1 of 1
Firebird BYTES data type not compatible with TBlobStream
Posted: 09.09.2019, 11:22
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.
Re: Firebird BYTES data type not compatible with TBlobStream
Posted: 09.09.2019, 21:43
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.
Re: Firebird BYTES data type not compatible with TBlobStream
Posted: 11.09.2019, 11:13
by MN7
For me works "f.AsBytes".
But "BlobStream := FZQuery.CreateBlobStream(f, bmRead);"
just crashed, not raise EZNotSupported or so (for example).
Re: Firebird BYTES data type not compatible with TBlobStream
Posted: 12.09.2019, 18:07
by marsupilami
Which version of Delphi and or / FPC do you use?
Re: Firebird BYTES data type not compatible with TBlobStream
Posted: 13.09.2019, 17:41
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.