فهرست منبع

fcl-db: base: implement TParam.AsBCD + test

git-svn-id: trunk@27719 -
lacak 11 سال پیش
والد
کامیت
1004c8db6f
3فایلهای تغییر یافته به همراه36 افزوده شده و 20 حذف شده
  1. 2 0
      packages/fcl-db/src/base/db.pas
  2. 6 0
      packages/fcl-db/src/base/dsparams.inc
  3. 28 20
      packages/fcl-db/tests/testfieldtypes.pas

+ 2 - 0
packages/fcl-db/src/base/db.pas

@@ -1161,6 +1161,7 @@ type
     Function GetDisplayName: string; override;
     Function GetIsNull: Boolean;
     Function IsEqual(AValue: TParam): Boolean;
+    Procedure SetAsBCD(const AValue: Currency);
     Procedure SetAsBlob(const AValue: TBlobData);
     Procedure SetAsBoolean(AValue: Boolean);
     Procedure SetAsCurrency(const AValue: Currency);
@@ -1197,6 +1198,7 @@ type
     Procedure SetData(Buffer: Pointer);
     Property AsBlob : TBlobData read GetAsString write SetAsBlob;
     Property AsBoolean : Boolean read GetAsBoolean write SetAsBoolean;
+    Property AsBCD : Currency read GetAsCurrency write SetAsBCD;
     Property AsCurrency : Currency read GetAsCurrency write SetAsCurrency;
     Property AsDate : TDateTime read GetAsDateTime write SetAsDate;
     Property AsDateTime : TDateTime read GetAsDateTime write SetAsDateTime;

+ 6 - 0
packages/fcl-db/src/base/dsparams.inc

@@ -617,6 +617,12 @@ begin
           and (FValue=AValue.FValue);
 end;
 
+procedure TParam.SetAsBCD(const AValue: Currency);
+begin
+  FDataType:=ftBCD;
+  Value:=AValue;
+end;
+
 Procedure TParam.SetAsBlob(const AValue: TBlobData);
 begin
   FDataType:=ftBlob;

+ 28 - 20
packages/fcl-db/tests/testfieldtypes.pas

@@ -84,6 +84,7 @@ type
     procedure TestDateTimeParamQuery;
     procedure TestFmtBCDParamQuery;
     procedure TestFloatParamQuery;
+    procedure TestCurrencyParamQuery;
     procedure TestBCDParamQuery;
     procedure TestBytesParamQuery;
     procedure TestVarBytesParamQuery;
@@ -1508,6 +1509,11 @@ begin
   TestXXParamQuery(ftFloat,FieldtypeDefinitions[ftFloat],testFloatValuesCount);
 end;
 
+procedure TTestFieldTypes.TestCurrencyParamQuery;
+begin
+  TestXXParamQuery(ftCurrency,FieldtypeDefinitions[ftCurrency],testValuesCount);
+end;
+
 procedure TTestFieldTypes.TestBCDParamQuery;
 begin
   TestXXParamQuery(ftBCD,'NUMERIC(10,4)',testBCDValuesCount);
@@ -1559,7 +1565,7 @@ begin
     sql.append('insert into FPDEV2 (ID,FIELD1) values (:id,:field1)');
 
     // There is no Param.AsFixedChar, so the datatype has to be set manually
-    if ADatatype=ftFixedChar then
+    if ADataType=ftFixedChar then
       Params.ParamByName('field1').DataType := ftFixedChar;
 
     for i := 0 to testValuesCount -1 do
@@ -1567,28 +1573,29 @@ begin
       Params.ParamByName('id').AsInteger := i;
       case ADataType of
         ftSmallInt: Params.ParamByName('field1').AsSmallInt := testSmallIntValues[i];
-        ftInteger: Params.ParamByName('field1').AsInteger := testIntValues[i];
+        ftInteger : Params.ParamByName('field1').AsInteger := testIntValues[i];
         ftLargeInt: Params.ParamByName('field1').AsLargeInt := testLargeIntValues[i];
-        ftBoolean: Params.ParamByName('field1').AsBoolean := testBooleanValues[i];
-        ftFloat  : Params.ParamByName('field1').AsFloat   := testFloatValues[i];
-        ftBCD    : Params.ParamByName('field1').AsCurrency:= testBCDValues[i];
+        ftBoolean : Params.ParamByName('field1').AsBoolean := testBooleanValues[i];
+        ftFloat   : Params.ParamByName('field1').AsFloat   := testFloatValues[i];
+        ftCurrency: Params.ParamByName('field1').AsCurrency:= testCurrencyValues[i];
+        ftBCD     : Params.ParamByName('field1').AsBCD     := testBCDValues[i];
         ftFixedChar,
-        ftString : Params.ParamByName('field1').AsString  := testValues[ADataType,i];
-        ftTime   : Params.ParamByName('field1').AsTime    := TimeStringToDateTime(testTimeValues[i]);
-        ftDate   : if cross then
-                     Params.ParamByName('field1').AsString:= testDateValues[i]
-                   else
-                     Params.ParamByName('field1').AsDate := StrToDate(testDateValues[i],'yyyy/mm/dd','-');
-        ftDateTime:Params.ParamByName('field1').AsDateTime := StrToDateTime(testValues[ADataType,i], DBConnector.FormatSettings);
-        ftFMTBcd : Params.ParamByName('field1').AsFMTBCD := StrToBCD(testFmtBCDValues[i],DBConnector.FormatSettings);
-        ftBytes  : if cross then
-                     Params.ParamByName('field1').Value := StringToByteArray(testBytesValues[i])
-                   else
-                     Params.ParamByName('field1').AsBlob := testBytesValues[i];
-        ftVarBytes:if cross then
-                     Params.ParamByName('field1').AsString := testBytesValues[i]
+        ftString  : Params.ParamByName('field1').AsString  := testValues[ADataType,i];
+        ftTime    : Params.ParamByName('field1').AsTime    := TimeStringToDateTime(testTimeValues[i]);
+        ftDate    : if cross then
+                      Params.ParamByName('field1').AsString:= testDateValues[i]
                    else
-                     Params.ParamByName('field1').AsBlob := testBytesValues[i];
+                      Params.ParamByName('field1').AsDate := StrToDate(testDateValues[i],'yyyy/mm/dd','-');
+        ftDateTime: Params.ParamByName('field1').AsDateTime := StrToDateTime(testValues[ADataType,i], DBConnector.FormatSettings);
+        ftFMTBcd  : Params.ParamByName('field1').AsFMTBCD := StrToBCD(testFmtBCDValues[i], DBConnector.FormatSettings);
+        ftBytes   : if cross then
+                      Params.ParamByName('field1').Value := StringToByteArray(testBytesValues[i])
+                    else
+                      Params.ParamByName('field1').AsBlob := testBytesValues[i];
+        ftVarBytes: if cross then
+                      Params.ParamByName('field1').AsString := testBytesValues[i]
+                    else
+                      Params.ParamByName('field1').AsBlob := testBytesValues[i];
       else
         AssertTrue('no test for paramtype available',False);
       end;
@@ -1614,6 +1621,7 @@ begin
         ftLargeInt : AssertEquals(testLargeIntValues[i],FieldByName('FIELD1').AsLargeInt);
         ftBoolean  : AssertEquals(testBooleanValues[i],FieldByName('FIELD1').AsBoolean);
         ftFloat    : AssertEquals(testFloatValues[i],FieldByName('FIELD1').AsFloat);
+        ftCurrency : AssertEquals(testCurrencyValues[i],FieldByName('FIELD1').AsFloat,0); // TCurrencyField uses double data type (not currency) to store values!
         ftBCD      : AssertEquals(testBCDValues[i],FieldByName('FIELD1').AsCurrency);
         ftFixedChar : AssertEquals(PadRight(testStringValues[i],10),FieldByName('FIELD1').AsString);
         ftString   : AssertEquals(testStringValues[i],FieldByName('FIELD1').AsString);