Retrieving a numeric field value equal to the delphi MaxDouble returns an incorrect value

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Hendrikse
Posts: 2
Joined: Fri 31 Aug 2018 11:40

Retrieving a numeric field value equal to the delphi MaxDouble returns an incorrect value

Post by Hendrikse » Fri 31 Aug 2018 12:10

Hi,

I'm currently using double precision fields in my postgres database.
I want them over to numeric fields.
While testing this change in our software I ran into an odd situation.

If I try using a pgQuery to retrieve a double equal to the delphi MaxDouble it returns an incorrect value.

For an example take this table structure

Code: Select all

CREATE TABLE public.testtable
(
  idfield integer NOT NULL DEFAULT nextval('testtable_idfield_seq'::regclass),
  testnumeric numeric,
  CONSTRAINT testtable_pkey PRIMARY KEY (idfield)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE public.testtable
  OWNER TO postgres;
Then in a delphi project the code would look something like this.

Code: Select all

var query: TPgQuery;
  id: Integer;
begin
  query := TPgQuery.Create(nil);
  try
    query.Connection := PgConnection1; // Connection to database with newly created table
    query.Sql.Text := 'INSERT INTO testtable (testnumeric) values (:val) returning idfield';
    query.ParamByName('val').Value := MaxDouble;
    query.Open;

    id := query.FieldByName('idfield').AsInteger;

    query.Close;

    query.Sql.Text := 'SELECT testnumeric FROM testtable WHERE idfield = :id';
    query.ParamByName('id').Value := id;
    query.Open;

    if(query.FieldByName('testnumeric').AsFloat = MaxDouble) then
    begin
      ShowMessage('Success');
    end
    else
    begin
      ShowMessage('Failed');
    end;
  finally
    query.Free;
  end;
end;
This code will result in the message Failed while i would expect it to reach Success.
If I check the database the value does seem to be stored correctly in there, so it seems to be a problem with retrieving it.
Coincidentally the same code does show Success if we change the testnumeric field to a double precision field.

Is this a know problem, am i doing something wrong or neither?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Retrieving a numeric field value equal to the delphi MaxDouble returns an incorrect value

Post by ViktorV » Wed 05 Sep 2018 13:23

Thank you for the information. We have reproduced the issue and investigation is in progress. We will inform you when we have any results.

Post Reply