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
2 changed files with 31 additions and 3 deletions
  1. 3 3
      packages/fcl-db/tests/sqldbtoolsunit.pas
  2. 28 0
      packages/fcl-db/tests/testfieldtypes.pas

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

@@ -35,7 +35,7 @@ const MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55];
           'INTEGER',
           '',
           'BOOLEAN',
-          'FLOAT',
+          'DOUBLE PRECISION', // ftFloat
           '',             // ftCurrency
           'DECIMAL(18,4)',// ftBCD
           'DATE',
@@ -43,7 +43,7 @@ const MySQLConnTypes = [mysql40,mysql41,mysql50,mysql51,mysql55];
           'TIMESTAMP',    // ftDateTime
           '',
           '',
-          '',
+          '',             // ftAutoInc
           'BLOB',         // ftBlob
           'BLOB',         // ftMemo
           'BLOB',         // ftGraphic
@@ -205,6 +205,7 @@ begin
       begin
       FieldtypeDefinitions[ftBoolean] := 'BIT';
       FieldtypeDefinitions[ftCurrency]:= 'MONEY';
+      FieldtypeDefinitions[ftFloat]   := 'FLOAT';
       FieldtypeDefinitions[ftDate]    := 'DATETIME';
       FieldtypeDefinitions[ftTime]    := '';
       FieldtypeDefinitions[ftDateTime]:= 'DATETIME';
@@ -218,7 +219,6 @@ begin
       begin
       //MySQL recognizes BOOLEAN, but as synonym for TINYINT, not true sql boolean datatype
       FieldtypeDefinitions[ftBoolean] := '';
-      FieldtypeDefinitions[ftFloat] := 'DOUBLE';
       // Use 'DATETIME' for datetime-fields instead of timestamp, because
       // mysql's timestamps are only valid in the range 1970-2038.
       // 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 TestSQLInterval;
     procedure TestSQLIdentity;
+    procedure TestSQLReal;
   end;
 
 implementation
@@ -2030,6 +2031,33 @@ begin
   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;
 var ds : TSQLQuery;
 begin