* Added test for ftTime fields

* Fixed problem with ftTime field values that exceed 24 hours (odbc)

git-svn-id: trunk@17000 -
This commit is contained in:
joost 2011-02-24 22:15:46 +00:00
parent f8b01f76a4
commit 366a8dd966
4 changed files with 61 additions and 2 deletions

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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;