#1 2013-12-05 08:21:53

ncook
Member
From: Australia
Registered: 2013-08-13
Posts: 19

Incorrect results when reading Boolean fields from a Jet table

Hi,
I'm having a problem reading Boolean fields from a Jet table. They are always ending up with the value False, even when the value recorded in the table is True.

It seems to work ok when using ISQLDBRows with .Step, and it seems to work ok when using FetchAllAsJSON, both of which give a value of -1 for True, and 0 for False, as expected.

But when I try to access the data using the ORM with .CreateAndFillPrepare and .FillOne, the Boolean fields in my TSQLRecord descendant type always get the value False.

I think that I've tracked it down to the following routine, but I'm unsure how to fix it without breaking other things....

procedure TSQLPropInfoRTTIEnum.SetValue(Instance: TObject; Value: PUTF8Char; wasString: boolean);
var i,err: integer;
begin
  if Value=nil then
    i := 0 else begin
    i := GetInteger(Value,err);
    if err<>0 then // we allow a value stated as text
      i := fEnumType^.GetEnumNameValue(Value); // -> convert into integer
    if cardinal(i)>cardinal(fEnumType^.MaxValue) then
      i := 0;  // only set a valid value
  end;
  SetOrdProp(Instance,pointer(fPropInfo),i);
end;

In particular the following line...

if cardinal(i)>cardinal(fEnumType^.MaxValue) then
  i := 0;  // only set a valid value

When the Boolean is True, the value of i is -1, which passes the test (because of the typecast to cardinal, and fEnumType^.MaxValue = 1) and thus sets the value of i to 0.

I hope someone else knows enough about this area of the code to suggest a safe fix.

Offline

#2 2013-12-05 15:47:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: Incorrect results when reading Boolean fields from a Jet table

You are right.

The current implementation was confused by the boolean kind of variable.

I've fixed and enhanced boolean values parsing from JSON content.
Now "Yes" will be identified as true (in addition to "true").
See http://synopse.info/fossil/info/9692746f12

Thanks for the feedback.

Offline

#3 2013-12-05 23:21:05

ncook
Member
From: Australia
Registered: 2013-08-13
Posts: 19

Re: Incorrect results when reading Boolean fields from a Jet table

Thanks ab.

That works well.

Offline

Board footer

Powered by FluxBB