Browse Source

fcl-db: tests: improve testing for approximate numeric data types. SQL standard defines DOUBLE PRECISION (tested in TestSupportFloatFields), FLOAT (tested in TestFloat) and REAL (added new test TestSQLReal (single precision floating point values))

git-svn-id: trunk@23063 -
lacak 12 years ago
parent
commit
f58150e3fd

+ 3 - 3
packages/fcl-db/tests/sqldbtoolsunit.pas

@@ -35,7 +35,7 @@ const MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55];
           'INTEGER',
           'INTEGER',
           '',
           '',
           'BOOLEAN',
           'BOOLEAN',
-          'FLOAT',
+          'DOUBLE PRECISION', // ftFloat
           '',             // ftCurrency
           '',             // ftCurrency
           'DECIMAL(18,4)',// ftBCD
           'DECIMAL(18,4)',// ftBCD
           'DATE',
           'DATE',
@@ -43,7 +43,7 @@ const MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55];
           'TIMESTAMP',    // ftDateTime
           'TIMESTAMP',    // ftDateTime
           '',
           '',
           '',
           '',
-          '',
+          '',             // ftAutoInc
           'BLOB',         // ftBlob
           'BLOB',         // ftBlob
           'BLOB',         // ftMemo
           'BLOB',         // ftMemo
           'BLOB',         // ftGraphic
           'BLOB',         // ftGraphic
@@ -205,6 +205,7 @@ begin
       begin
       begin
       FieldtypeDefinitions[ftBoolean] := 'BIT';
       FieldtypeDefinitions[ftBoolean] := 'BIT';
       FieldtypeDefinitions[ftCurrency]:= 'MONEY';
       FieldtypeDefinitions[ftCurrency]:= 'MONEY';
+      FieldtypeDefinitions[ftFloat]   := 'FLOAT';
       FieldtypeDefinitions[ftDate]    := 'DATETIME';
       FieldtypeDefinitions[ftDate]    := 'DATETIME';
       FieldtypeDefinitions[ftTime]    := '';
       FieldtypeDefinitions[ftTime]    := '';
       FieldtypeDefinitions[ftDateTime]:= 'DATETIME';
       FieldtypeDefinitions[ftDateTime]:= 'DATETIME';
@@ -218,7 +219,6 @@ begin
       begin
       begin
       //MySQL recognizes BOOLEAN, but as synonym for TINYINT, not true sql boolean datatype
       //MySQL recognizes BOOLEAN, but as synonym for TINYINT, not true sql boolean datatype
       FieldtypeDefinitions[ftBoolean] := '';
       FieldtypeDefinitions[ftBoolean] := '';
-      FieldtypeDefinitions[ftFloat] := 'DOUBLE';
       // Use 'DATETIME' for datetime-fields instead of timestamp, because
       // Use 'DATETIME' for datetime-fields instead of timestamp, because
       // mysql's timestamps are only valid in the range 1970-2038.
       // mysql's timestamps are only valid in the range 1970-2038.
       // Downside is that fields defined as 'TIMESTAMP' aren't tested
       // Downside is that fields defined as 'TIMESTAMP' aren't tested

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

@@ -115,6 +115,7 @@ type
     procedure TestSQLLargeint;
     procedure TestSQLLargeint;
     procedure TestSQLInterval;
     procedure TestSQLInterval;
     procedure TestSQLIdentity;
     procedure TestSQLIdentity;
+    procedure TestSQLReal;
   end;
   end;
 
 
 implementation
 implementation
@@ -2030,6 +2031,33 @@ begin
   end;
   end;
 end;
 end;
 
 
+function TestSQLReal_GetSQLText(const i: integer) : string;
+begin
+  if i < 20 then // first 20 values fit into MySQL FLOAT data type
+    Result := FloatToStr(testFloatValues[i], DBConnector.FormatSettings)
+  else
+    Result := 'NULL';
+end;
+procedure TTestFieldTypes.TestSQLReal;
+  procedure CheckFieldValue(AField:TField; i: integer);
+  begin
+    if i < 20 then
+      AssertEquals(testFloatValues[i], AField.AsFloat)
+    else
+      AssertTrue(AField.IsNull);
+  end;
+var datatype: string;
+begin
+  case SQLServerType of
+    ssFirebird, ssInterbase,
+    ssMySQL:
+      datatype:='FLOAT';
+    else
+      datatype:='REAL';
+  end;
+  TestSQLFieldType(ftFloat, datatype, sizeof(double), @TestSQLReal_GetSQLText, @CheckFieldValue);
+end;
+
 procedure TTestFieldTypes.TestUpdateIndexDefs;
 procedure TTestFieldTypes.TestUpdateIndexDefs;
 var ds : TSQLQuery;
 var ds : TSQLQuery;
 begin
 begin