From 366a8dd96643b9b3d6e745d54819b40211142e71 Mon Sep 17 00:00:00 2001 From: joost Date: Thu, 24 Feb 2011 22:15:46 +0000 Subject: [PATCH] * Added test for ftTime fields * Fixed problem with ftTime field values that exceed 24 hours (odbc) git-svn-id: trunk@17000 - --- packages/fcl-db/tests/sqldbtoolsunit.pas | 2 +- packages/fcl-db/tests/testdbbasics.pas | 26 ++++++++++++++++++++ packages/fcl-db/tests/toolsunit.pas | 30 ++++++++++++++++++++++++ packages/odbc/src/odbcsql.inc | 5 +++- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/packages/fcl-db/tests/sqldbtoolsunit.pas b/packages/fcl-db/tests/sqldbtoolsunit.pas index 3e18104c27..0c4482fbd2 100644 --- a/packages/fcl-db/tests/sqldbtoolsunit.pas +++ b/packages/fcl-db/tests/sqldbtoolsunit.pas @@ -27,7 +27,7 @@ const MySQLdbTypes = [mysql40,mysql41,mysql50]; '', 'DECIMAL(18,4)', 'DATE', - 'TIMESTAMP', + 'TIME', 'TIMESTAMP', '', '', diff --git a/packages/fcl-db/tests/testdbbasics.pas b/packages/fcl-db/tests/testdbbasics.pas index 35fb9ff8d7..1874fd5545 100644 --- a/packages/fcl-db/tests/testdbbasics.pas +++ b/packages/fcl-db/tests/testdbbasics.pas @@ -54,6 +54,7 @@ type procedure TestSupportFloatFields; procedure TestSupportLargeIntFields; procedure TestSupportDateFields; + procedure TestSupportTimeFields; procedure TestSupportCurrencyFields; procedure TestSupportBCDFields; procedure TestSupportfmtBCDFields; @@ -1917,6 +1918,31 @@ begin ds.close; 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; var i : byte; diff --git a/packages/fcl-db/tests/toolsunit.pas b/packages/fcl-db/tests/toolsunit.pas index 4ef3b38049..8ad6a59ebd 100644 --- a/packages/fcl-db/tests/toolsunit.pas +++ b/packages/fcl-db/tests/toolsunit.pas @@ -157,6 +157,35 @@ const '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, dbconnectorname, dbconnectorparams, @@ -256,6 +285,7 @@ begin if DBConnectorRefCount>0 then exit; testValues[ftString] := testStringValues; testValues[ftFixedChar] := testStringValues; + testValues[ftTime] := testTimeValues; testValues[ftFMTBcd] := testFmtBCDValues; for i := 0 to testValuesCount-1 do begin diff --git a/packages/odbc/src/odbcsql.inc b/packages/odbc/src/odbcsql.inc index 769ee89b4a..49a15b66b1 100644 --- a/packages/odbc/src/odbcsql.inc +++ b/packages/odbc/src/odbcsql.inc @@ -1711,7 +1711,10 @@ end; Function TimeStructToDateTime (B : PSQL_TIME_STRUCT) : TDateTime; begin 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;