Stream Error/Manipulation with BYTEA and Unprepared Execute=True

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Stream Error/Manipulation with BYTEA and Unprepared Execute=True

Post by dschuch » Fri 03 Jul 2015 10:05

Hi,

PGDAC 4.5.14

When storing binary data in a BYTEA field with unpreparedExecute=True, the data is manipulated and corrupted. Please check out the following Testcode. Attached u have an example file (this is a DevExpress Filter File).

http://prodat-sql.de/tmp/Testfilter.dat

Can u reproduce the error?

Thanks, Daniel.

Code: Select all

procedure TForm1.Button4Click(Sender: TObject);
var
  Data1, Data2: TFileStream;
  B:            Byte;
  A1, A2:       TBytes;
begin
  Data1 := TFileStream.Create('S:\Testfilter.dat', fmOpenRead);
  Data2 := TFileStream.Create('S:\Testfilter_pg.dat', fmCreate);
  try
    PgQuery2.Connection := DM1.DataBase1;
    PgQuery1.Connection := DM1.DataBase1;

    //PgQuery1.Options.UnknownAsString := True;  // This one has no effect.
    PgQuery1.Options.UnpreparedExecute := True;  // The GUILTY.

    PgQuery1.SQL.Text :=
        'CREATE TABLE IF NOT EXISTS datatest ( '#10
      + '  ident SERIAL PRIMARY KEY, '#10
      + '  data  BYTEA '#10
      + ');';
    PgQuery1.Execute;

    PgQuery1.Close;
    PgQuery1.SQL.Text := 'SELECT * FROM datatest';
    PgQuery1.Open;
    PgQuery1.Locate('ident', 0, []);
    PgQuery1.Edit;
    PgQuery1.FieldByName('ident').AsInteger := 0;
    //TBlobField(PgQuery1.FieldByName('data')).LoadFromFile('S:\Testfilter.dat');
    TBlobField(PgQuery1.FieldByName('data')).LoadFromStream(Data1);
    PgQuery1.Post;

    PgQuery2.Close;
    PgQuery2.SQL.Text := 'SELECT * FROM datatest WHERE ident = 0';
    PgQuery2.Open;
    //TBlobField(PgQuery2.FieldByName('data')).SaveToFile('S:\Testfilter_pg.dat');
    TBlobField(PgQuery2.FieldByName('data')).SaveToStream(Data2);

    Data2.Position := $34;
    Data2.ReadBuffer(B, 1);
    if B <> $85 then
      ShowMessage('byte modified');

    SetLength(A1, Data1.Size);
    SetLength(A2, Data2.Size);
    Data1.Position := 0;
    Data2.Position := 0;
    Data1.ReadBuffer(A1[0], Length(A1));
    Data2.ReadBuffer(A2[0], Length(A2));
    if (Length(A1) <> Length(A2)) or not CompareMem(@A1[0], @A2[0], Length(A1)) then
      ShowMessage('data modified');
  finally
    Data1.Free;
    Data2.Free;
  end;
end;

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Stream Error/Manipulation with BYTEA and Unprepared Execute=True

Post by azyk » Mon 06 Jul 2015 08:14

Thank you for the information. We have reproduced this issue. We will investigate it and inform you as soon as we get any results.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Stream Error/Manipulation with BYTEA and Unprepared Execute=True

Post by azyk » Tue 07 Jul 2015 09:36

We have fixed this problem. This fix will be included in the next PgDAC build.

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Re: Stream Error/Manipulation with BYTEA and Unprepared Execute=True

Post by dschuch » Thu 09 Jul 2015 09:46

thx, is it is possible to get the sourcecode-snipped (diff), so we can checkout the fix it and fix it in our release immediatly. if it is much work we will wait for the next relase, no problem. (acutally we switched PreparedExecute to true for the affected Query)

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Stream Error/Manipulation with BYTEA and Unprepared Execute=True

Post by azyk » Thu 09 Jul 2015 11:18

PgDAC release is planned within the next week. If you want to get this fix before the next PgDAC release, send your e-mail and license number to andreyz*devart*com - and we will send you a night build.

Post Reply