Browse Source

Patch from Luiz Americo, mantis 12700
- Fix setting negative double values

git-svn-id: trunk@12223 -

joost 16 years ago
parent
commit
ad9d126239
1 changed files with 18 additions and 5 deletions
  1. 18 5
      packages/fcl-db/src/sqlite/customsqliteds.pas

+ 18 - 5
packages/fcl-db/src/sqlite/customsqliteds.pas

@@ -1166,6 +1166,8 @@ procedure TCustomSqliteDataset.SetFieldData(Field: TField; Buffer: Pointer;
   NativeFormat: Boolean);
   NativeFormat: Boolean);
 var
 var
   TempStr:String;
   TempStr:String;
+  FloatStr: PChar;
+  FloatLen: Integer;
 begin
 begin
   if not (State in [dsEdit, dsInsert]) then
   if not (State in [dsEdit, dsInsert]) then
     DatabaseErrorFmt(SNotEditing,[Name],Self);
     DatabaseErrorFmt(SNotEditing,[Name],Self);
@@ -1192,11 +1194,22 @@ begin
       end;  
       end;  
     ftFloat,ftDateTime,ftDate,ftTime,ftCurrency:
     ftFloat,ftDateTime,ftDate,ftTime,ftCurrency:
       begin
       begin
-        Str(Double(Buffer^),TempStr);  
-        FCacheItem^.Row[Pred(Field.FieldNo)]:=StrAlloc(Length(TempStr));
-        //Skips the first space that str returns
-        //todo: make a custom Str?
-        Move((PChar(TempStr)+1)^,(FCacheItem^.Row[Pred(Field.FieldNo)])^,Length(TempStr));
+        Str(Double(Buffer^),TempStr);
+        //Str returns a space as the first character for positive values
+        //and the - sign for negative values. It's necessary to remove the extra
+        //space while keeping the - sign
+        if TempStr[1] = ' ' then
+        begin
+          FloatStr := PChar(TempStr) + 1;
+          FloatLen := Length(TempStr);
+        end
+        else
+        begin
+          FloatStr := PChar(TempStr);
+          FloatLen := Length(TempStr) + 1;
+        end;
+        FCacheItem^.Row[Pred(Field.FieldNo)] := StrAlloc(FloatLen);
+        Move(FloatStr^, (FCacheItem^.Row[Pred(Field.FieldNo)])^, FloatLen);
       end;
       end;
     ftLargeInt:
     ftLargeInt:
       begin
       begin