ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/fbintf/client/FBSQLData.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/FBSQLData.pas (file contents):
Revision 349 by tony, Mon Oct 18 08:39:40 2021 UTC vs.
Revision 353 by tony, Sat Oct 23 14:11:37 2021 UTC

# Line 122 | Line 122 | type
122    private
123       FFirebirdClientAPI: TFBClientAPI;
124       FTimeZoneServices: IExTimeZoneServices;
125     function AdjustScale(Value: Int64; aScale: Integer): Double;
126     function AdjustScaleToInt64(Value: Int64; aScale: Integer): Int64;
127     function AdjustScaleToCurrency(Value: Int64; aScale: Integer): Currency;
125       function GetDateFormatStr(IncludeTime: boolean): AnsiString;
126       function GetTimeFormatStr: AnsiString;
127       function GetTimestampFormatStr: AnsiString;
# Line 132 | Line 129 | type
129       procedure InternalGetAsDateTime(var aDateTime: TDateTime; var dstOffset: smallint;
130         var aTimezone: AnsiString; var aTimeZoneID: TFBTimeZoneID);
131    protected
132 +     function AdjustScale(Value: Int64; aScale: Integer): Double;
133 +     function AdjustScaleToInt64(Value: Int64; aScale: Integer): Int64;
134 +     function AdjustScaleToStr(Value: Int64; aScale: Integer): AnsiString;
135 +     function AdjustScaleToCurrency(Value: Int64; aScale: Integer): Currency;
136       function AdjustScaleFromCurrency(Value: Currency; aScale: Integer): Int64;
137       function AdjustScaleFromDouble(Value: Double; aScale: Integer): Int64;
138       procedure CheckActive; virtual;
# Line 205 | Line 206 | type
206       procedure SetAsShort(Value: short); virtual;
207       procedure SetAsString(Value: AnsiString); virtual;
208       procedure SetAsVariant(Value: Variant);
209 <     procedure SetAsNumeric(Value: Int64; aScale: integer);
209 >     procedure SetAsNumeric(Value: Int64; aScale: integer); virtual;
210       procedure SetAsBcd(aValue: tBCD); virtual;
211       procedure SetIsNull(Value: Boolean); virtual;
212       procedure SetIsNullable(Value: Boolean); virtual;
# Line 906 | Line 907 | begin
907      result := Val;
908   end;
909  
910 + function TSQLDataItem.AdjustScaleToStr(Value: Int64; aScale: Integer
911 +  ): AnsiString;
912 + var Scaling : AnsiString;
913 +    i: Integer;
914 + begin
915 +  Result := IntToStr(Value);
916 +  Scaling := '';
917 +  if aScale > 0 then
918 +  begin
919 +    for i := 1 to aScale do
920 +      Result := Result + '0';
921 +  end
922 +  else
923 +  if aScale < 0 then
924 +  {$IF declared(DefaultFormatSettings)}
925 +  with DefaultFormatSettings do
926 +  {$ELSE}
927 +  {$IF declared(FormatSettings)}
928 +  with FormatSettings do
929 +  {$IFEND}
930 +  {$IFEND}
931 +  begin
932 +    if Length(Result) > -aScale then
933 +      system.Insert(DecimalSeparator,Result,Length(Result) + aScale)
934 +    else
935 +    begin
936 +      Scaling := '0' + DecimalSeparator;
937 +      for i := -1 downto aScale + Length(Result) do
938 +        Scaling := Scaling + '0';
939 +      Result := Scaling + Result;
940 +    end;
941 +  end;
942 + end;
943 +
944   function TSQLDataItem.AdjustScaleToCurrency(Value: Int64; aScale: Integer
945    ): Currency;
946   var
# Line 2425 | Line 2460 | end;
2460   var b: IBlob;
2461      dt: TDateTime;
2462      timezone: AnsiString;
2428    FloatValue: Double;
2463      Int64Value: Int64;
2464      BCDValue: TBCD;
2465      aScale: integer;
# Line 2463 | Line 2497 | begin
2497    SQL_SHORT,
2498    SQL_LONG,
2499    SQL_INT64:
2500 <    {If the string contains an integer then convert and set directly}
2501 <    if TryStrToInt64(Value,Int64Value) then
2468 <      SetAsInt64(Int64Value)
2469 <    else
2470 <    if getColMetaData.getScale = 0 then {integer expected but non-integer string}
2471 <    begin
2472 <      if TryStrToFloat(Value,FloatValue) then
2473 <        {truncate it if the column is limited to an integer}
2474 <        SetAsInt64(Trunc(FloatValue))
2475 <      else
2476 <        DoSetString;
2477 <    end
2478 <    else
2479 <    if TryStrToFloat(Value,FloatValue) then
2480 <    begin
2481 <      aScale := getColMetaData.getScale;
2482 <      {Set as int64 with adjusted scale}
2483 <      SetAsNumeric(AdjustScaleFromDouble(FloatValue,aScale),aScale)
2484 <    end
2500 >    if TryStrToNumeric(Value,Int64Value,aScale) then
2501 >      SetAsNumeric(Int64Value,aScale)
2502      else
2503        DoSetString;
2504  
# Line 2497 | Line 2514 | begin
2514    SQL_D_FLOAT,
2515    SQL_DOUBLE,
2516    SQL_FLOAT:
2517 <    if TryStrToFloat(Value,FloatValue) then
2518 <      SetAsDouble(FloatValue)
2517 >    if TryStrToNumeric(Value,Int64Value,aScale) then
2518 >      SetAsDouble(NumericToDouble(Int64Value,aScale))
2519      else
2520        DoSetString;
2521  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines