* Patch from Lasislav Karrach to implement ftTime parameter support to odbc+

test, bug #18824

git-svn-id: trunk@17401 -
This commit is contained in:
joost 2011-05-03 20:59:40 +00:00
parent 3152f93d23
commit 44f09afaf6
4 changed files with 56 additions and 11 deletions

View File

@ -309,6 +309,7 @@ var
StrVal: string;
FloatVal: cdouble;
DateVal: SQL_DATE_STRUCT;
TimeVal: SQL_TIME_STRUCT;
TimeStampVal: SQL_TIMESTAMP_STRUCT;
BoolVal: byte;
ColumnSize, BufferLength, StrLenOrInd: SQLINTEGER;
@ -400,6 +401,15 @@ begin
SqlType:=SQL_TYPE_DATE;
ColumnSize:=Size;
end;
ftTime:
begin
TimeVal:=DateTimeToTimeStruct(AParams[ParamIndex].AsTime);
PVal:=@TimeVal;
Size:=SizeOf(TimeVal);
CType:=SQL_C_TYPE_TIME;
SqlType:=SQL_TYPE_TIME;
ColumnSize:=Size;
end;
ftDateTime:
begin
DateTime2TimeStampStruct(TimeStampVal, AParams[ParamIndex].AsDateTime);

View File

@ -1922,22 +1922,12 @@ 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);
AssertEquals(testTimeValues[i],DateTimeToTimeString(fld.AsDateTime));
ds.Next;
end;
ds.close;

View File

@ -87,6 +87,7 @@ type
procedure TestFixedStringParamQuery;
procedure TestDateParamQuery;
procedure TestIntParamQuery;
procedure TestTimeParamQuery;
procedure TestFloatParamQuery;
procedure TestBCDParamQuery;
procedure TestAggregates;
@ -731,6 +732,11 @@ begin
TestXXParamQuery(ftInteger,'INT',testIntValuesCount);
end;
procedure TTestFieldTypes.TestTimeParamQuery;
begin
TestXXParamQuery(ftTime,FieldtypeDefinitionsConst[ftTime],testValuesCount);
end;
procedure TTestFieldTypes.TestFloatParamQuery;
begin
@ -791,6 +797,7 @@ begin
ftBCD : Params.ParamByName('field1').AsCurrency:= testBCDValues[i];
ftFixedChar,
ftString : Params.ParamByName('field1').AsString := testStringValues[i];
ftTime : Params.ParamByName('field1').AsTime := TimeStringToDateTime(testTimeValues[i]);
ftDate : if cross then
Params.ParamByName('field1').AsString:= testDateValues[i]
else
@ -815,6 +822,7 @@ begin
ftBCD : AssertEquals(testBCDValues[i],FieldByName('FIELD1').AsCurrency);
ftFixedChar : AssertEquals(PadRight(testStringValues[i],10),FieldByName('FIELD1').AsString);
ftString : AssertEquals(testStringValues[i],FieldByName('FIELD1').AsString);
ftTime : AssertEquals(testTimeValues[i],DateTimeToTimeString(FieldByName('FIELD1').AsDateTime));
ftdate : AssertEquals(testDateValues[i],FormatDateTime('yyyy/mm/dd',FieldByName('FIELD1').AsDateTime));
else
AssertTrue('no test for paramtype available',False);

View File

@ -202,6 +202,9 @@ var dbtype,
procedure InitialiseDBConnector;
procedure FreeDBConnector;
function DateTimeToTimeString(d: tdatetime) : string;
function TimeStringToDateTime(d: String): TDateTime;
implementation
uses
@ -318,6 +321,40 @@ begin
FreeAndNil(DBConnector);
end;
function DateTimeToTimeString(d: tdatetime): string;
var
millisecond: word;
second : word;
minute : word;
hour : word;
begin
// Format the datetime in the format hh:nn:ss:zzz, where the hours can be bigger then 23.
DecodeTime(d,hour,minute,second,millisecond);
hour := hour + (trunc(d) * 24);
result := Format('%.2d',[hour]) + ':' + format('%.2d',[minute]) + ':' + format('%.2d',[second]) + ':' + format('%.3d',[millisecond]);
end;
function TimeStringToDateTime(d: String): TDateTime;
var
millisecond: word;
second : word;
minute : word;
hour : word;
days : word;
begin
// Convert the string in the format hh:nn:ss:zzz to a datetime.
hour := strtoint(copy(d,1,2));
minute := strtoint(copy(d,4,2));
second := strtoint(copy(d,7,2));
millisecond := strtoint(copy(d,10,3));
days := hour div 24;
hour := hour mod 24;
result := ComposeDateTime(days,EncodeTime(hour,minute,second,millisecond));
end;
{ TTestDataLink }
{$IFDEF FPC}