Recent

Author Topic: Malformed blobs (jpg) - zeos + firebird  (Read 3382 times)

tomek1

  • New Member
  • *
  • Posts: 16
Malformed blobs (jpg) - zeos + firebird
« on: January 28, 2019, 01:57:46 pm »
Hi
I'm inserting jpg's to blob field, everything seems to work properly, but blob content is malformed. Here's the sample code:

Code: [Select]
  ZQuery1.SQL.Text := 'insert into PLATES (ID,'
                    + '                    PLATE_PIC)'
                    + 'values (gen_id(GEN_PLATES, 1),'
                    + '        :PLATE_PIC)';

  Stream := TMemoryStream.Create;
  try
    Stream.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'test.jpg');
    ZQuery1.ParamByName('PLATE_PIC').LoadFromStream(Stream, ftBlob);
    //ZQuery1.ParamByName('PLATE_PIC').SetBlobData(Stream.Memory, Stream.Size);
    ZQuery1.ExecSQL;
  finally
    Stream.Free;
  end;

Below printscreens with hex content of the file, and blob in db. Content differs more, not only first 4 bytes.
Firebird 2.5.2, charset utf8, PLATE_PIC is blob subtype binary.

Regards, Tomek

balazsszekely

  • Guest
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #1 on: January 28, 2019, 02:18:13 pm »
Try to set Stream.Position to 0 after Stream.LoadFromFile.

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #2 on: January 28, 2019, 02:36:31 pm »
You might even be able to just use LoadFromFile() directly.

Code: Pascal  [Select][+][-]
  1. TBlobField(ZQuery1.ParamByName('PLATE_PIC')).LoadFromFile(ExtractFilePath(ParamStr(0)) + 'test.jpg');
  2. ZQuery1.ExecSQL;

tomek1

  • New Member
  • *
  • Posts: 16
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #3 on: January 28, 2019, 03:31:12 pm »
Try to set Stream.Position to 0 after Stream.LoadFromFile.

It doesn't fix the problem.

You might even be able to just use LoadFromFile() directly.

The code above is actually a test case, real app gets the the pic in stream.

Regards, Tomek

rvk

  • Hero Member
  • *****
  • Posts: 6169
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #4 on: January 28, 2019, 03:47:50 pm »
Looking at those "?" I expect every $ff and subsequent character is converted (because of UTF-8).
That shouldn't happen but I'm not sure what happens in the parameters in Zeoslib.

Can you check what the type is of the parameter ZQuery1.ParamByName('PLATE_PIC').DataType?
It should be ftBlob. Otherwise you could clear and create the parameters by hand.

I also never worked with parameters to directly insert a blob.
You could try to do a SELECT ID, PLATE_PIC FROM PLATES and do a ZQuery1.Insert and fill in the fields at that point.

balazsszekely

  • Guest
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #5 on: January 28, 2019, 04:26:04 pm »
I used the following code for years and it works fine, you have to adapt it to your needs though:
Code: Pascal  [Select][+][-]
  1. var
  2.   St: TStream;
  3. begin
  4.   SQLQuery1.Edit;
  5.   St := SQLQuery1.CreateBlobStream(SQLQuery1.FieldByName('PICTURE'), bmWrite); //PICTURE --> BLOB SUB_TYPE 0 SEGMENT SIZE 80(binary)
  6.   try
  7.     Image1.Picture.SaveToStream(St);
  8.     SQLQuery1.ApplyUpdates;
  9.     SQLTransaction.CommitRetaining;
  10.   finally
  11.     St.Free;
  12.   end;
  13. end;    

tomek1

  • New Member
  • *
  • Posts: 16
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #6 on: January 29, 2019, 10:28:39 am »
Looking at those "?" I expect every $ff and subsequent character is converted (because of UTF-8).
That shouldn't happen but I'm not sure what happens in the parameters in Zeoslib.

Can you check what the type is of the parameter ZQuery1.ParamByName('PLATE_PIC').DataType?
It should be ftBlob. Otherwise you could clear and create the parameters by hand.

I also never worked with parameters to directly insert a blob.
You could try to do a SELECT ID, PLATE_PIC FROM PLATES and do a ZQuery1.Insert and fill in the fields at that point.

DataType of param is fbBlob.

Select/Insert/FieldByName isn't preferred nor optimal approach, but it works! (the ZQuery1 's only purpose is batch insert).

Thank you both for help.

Regards, Tomek

EgonHugeist

  • Jr. Member
  • **
  • Posts: 78
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #7 on: January 29, 2019, 10:39:39 am »
Hi tomek1,

Which version did you use? There was a regression(Buf overrun of 4Bytes with the Currency values) in the SVN version, i fixed yesterday evening.
If you don't use SVN than please open a ticked in the Zeos bugtracker https://sourceforge.net/p/zeoslib/tickets/
else update from SVN.

tomek1

  • New Member
  • *
  • Posts: 16
Re: Malformed blobs (jpg) - zeos + firebird
« Reply #8 on: January 30, 2019, 12:24:00 pm »
Hi
I was using 7.2.1-rc.
I've tested 7.2.4-stable - problem still remains.
Latest version (snapshot) solves the problem!

Thx for help.

Regards, Tomek

 

TinyPortal © 2005-2018