Page 1 of 1

Float fields return 0

Posted: 15.10.2009, 12:27
by merlin352
Hello

I have a problem with 6.6.5 stable, Latarus 0.9.29 beta and FPC 2.5.1.

I have some float fields in a Sqlite3 database. Under Zeos I get only 0 values. A TSQLQuery with a TSQLite3Connection returns the right values.

Has anyone an idea what may be wrong?

thx

Posted: 15.10.2009, 13:13
by merlin352
Hi


I managed to debug ZSysUtils and found whats going wrong. Why this code in :

Code: Select all

function SQLStrToFloatDef(Str: string; Def: Extended): Extended;

.
.
{$IFDEF FPC}
  if OldDecimalSeparator = ',' then
  begin
    DecimalSeparator := OldDecimalSeparator;
    Result := StrToFloatDef(Str, Def);
  end
  else
    Result := StrToFloatDef(Str, Def);
{$ELSE}
    Result := StrToFloatDef(Str, Def);
{$ENDIF}
Why this coding for FPC? The value that SQLite returns has a '.' as decimal separator.

Posted: 16.10.2009, 19:11
by mdaems
I have no clue. I did find it myself some weeks ago and I removed it from the sources now. The simple version is in 6.6-patches branch, so will be included in next stable release.

Code: Select all

function SQLStrToFloatDef(Str: string; Def: Extended): Extended;
var
  OldDecimalSeparator: Char;
begin
  OldDecimalSeparator := DecimalSeparator;
  DecimalSeparator := '.';
  if Pos('$', Str) = 1 then
    Str := Copy(Str, 2, Pred(Length(Str)));
  If Str = '' then
    Result := Def
  else
    Result := StrToFloatDef(Str, Def);
  DecimalSeparator := OldDecimalSeparator;
end;
Mark