Browse Source

* Added test for ftTime fields
* Fixed problem with ftTime field values that exceed 24 hours (odbc)

git-svn-id: trunk@17000 -

joost 14 years ago
parent
commit
366a8dd966

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

@@ -27,7 +27,7 @@ const MySQLdbTypes = [mysql40,mysql41,mysql50];
           '',
           '',
           'DECIMAL(18,4)',
           'DECIMAL(18,4)',
           'DATE',
           'DATE',
-          'TIMESTAMP',
+          'TIME',
           'TIMESTAMP',
           'TIMESTAMP',
           '',
           '',
           '',
           '',

+ 26 - 0
packages/fcl-db/tests/testdbbasics.pas

@@ -54,6 +54,7 @@ type
     procedure TestSupportFloatFields;
     procedure TestSupportFloatFields;
     procedure TestSupportLargeIntFields;
     procedure TestSupportLargeIntFields;
     procedure TestSupportDateFields;
     procedure TestSupportDateFields;
+    procedure TestSupportTimeFields;
     procedure TestSupportCurrencyFields;
     procedure TestSupportCurrencyFields;
     procedure TestSupportBCDFields;
     procedure TestSupportBCDFields;
     procedure TestSupportfmtBCDFields;
     procedure TestSupportfmtBCDFields;
@@ -1917,6 +1918,31 @@ begin
   ds.close;
   ds.close;
 end;
 end;
 
 
+procedure TTestDBBasics.TestSupportTimeFields;
+var i          : byte;
+    ds         : TDataset;
+    Fld        : TField;
+    s          : string;
+    millisecond: word;
+    second     : word;
+    minute     : word;
+    hour       : word;
+begin
+  TestfieldDefinition(ftTime,8,ds,Fld);
+
+  for i := 0 to testValuesCount-1 do
+    begin
+    // Format the datetime in the format hh:nn:ss:zzz, where the hours can be bigger then 23.
+    DecodeTime(fld.AsDateTime,hour,minute,second,millisecond);
+    hour := hour + (trunc(Fld.AsDateTime) * 24);
+    s := Format('%.2d',[hour]) + ':' + format('%.2d',[minute]) + ':' + format('%.2d',[second]) + ':' + format('%.3d',[millisecond]);
+
+    AssertEquals(testTimeValues[i],s);
+    ds.Next;
+    end;
+  ds.close;
+end;
+
 procedure TTestDBBasics.TestSupportCurrencyFields;
 procedure TTestDBBasics.TestSupportCurrencyFields;
 
 
 var i          : byte;
 var i          : byte;

+ 30 - 0
packages/fcl-db/tests/toolsunit.pas

@@ -157,6 +157,35 @@ const
     '1900-01-01'
     '1900-01-01'
   );
   );
 
 
+  testTimeValues : Array[0..testValuesCount-1] of string = (
+    '10:45:12:000',
+    '00:00:00:000',
+    '24:00:00:000',
+    '33:25:15:000',
+    '04:59:16:000',
+    '05:45:59:000',
+    '16:35:42:000',
+    '14:45:52:000',
+    '12:45:12:000',
+    '18:45:22:000',
+    '19:45:12:000',
+    '14:45:14:000',
+    '16:45:12:000',
+    '11:45:12:000',
+    '15:35:12:000',
+    '16:45:12:000',
+    '13:55:12:000',
+    '13:46:12:000',
+    '15:35:12:000',
+    '17:25:12:000',
+    '19:45:12:000',
+    '10:54:12:000',
+    '12:25:12:000',
+    '20:15:12:000',
+    '12:25:12:000'
+  );
+
+
 var dbtype,
 var dbtype,
     dbconnectorname,
     dbconnectorname,
     dbconnectorparams,
     dbconnectorparams,
@@ -256,6 +285,7 @@ begin
   if DBConnectorRefCount>0 then exit;
   if DBConnectorRefCount>0 then exit;
   testValues[ftString] := testStringValues;
   testValues[ftString] := testStringValues;
   testValues[ftFixedChar] := testStringValues;
   testValues[ftFixedChar] := testStringValues;
+  testValues[ftTime] := testTimeValues;
   testValues[ftFMTBcd] := testFmtBCDValues;
   testValues[ftFMTBcd] := testFmtBCDValues;
   for i := 0 to testValuesCount-1 do
   for i := 0 to testValuesCount-1 do
     begin
     begin

+ 4 - 1
packages/odbc/src/odbcsql.inc

@@ -1711,7 +1711,10 @@ end;
 Function TimeStructToDateTime (B : PSQL_TIME_STRUCT) : TDateTime;
 Function TimeStructToDateTime (B : PSQL_TIME_STRUCT) : TDateTime;
 begin
 begin
   With B^ do
   With B^ do
-    Result:=EncodeTime(Hour,Minute,Second,0);
+    begin
+      // TryEncodeTime can not be used, because it doesn't supports times with more then 24 hours.
+      Result:=TDateTime(cardinal(Hour)*3600000+cardinal(Minute)*60000+cardinal(Second)*1000)/MSecsPerDay;
+    end;
 end;
 end;