Browse Source

* Patch from Lasislav Karrach to implement ftTime parameter support to odbc+
test, bug #18824

git-svn-id: trunk@17401 -

joost 14 years ago
parent
commit
44f09afaf6

+ 10 - 0
packages/fcl-db/src/sqldb/odbc/odbcconn.pas

@@ -309,6 +309,7 @@ var
   StrVal: string;
   StrVal: string;
   FloatVal: cdouble;
   FloatVal: cdouble;
   DateVal: SQL_DATE_STRUCT;
   DateVal: SQL_DATE_STRUCT;
+  TimeVal: SQL_TIME_STRUCT;
   TimeStampVal: SQL_TIMESTAMP_STRUCT;
   TimeStampVal: SQL_TIMESTAMP_STRUCT;
   BoolVal: byte;
   BoolVal: byte;
   ColumnSize, BufferLength, StrLenOrInd: SQLINTEGER;
   ColumnSize, BufferLength, StrLenOrInd: SQLINTEGER;
@@ -400,6 +401,15 @@ begin
           SqlType:=SQL_TYPE_DATE;
           SqlType:=SQL_TYPE_DATE;
           ColumnSize:=Size;
           ColumnSize:=Size;
         end;
         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:
       ftDateTime:
         begin
         begin
           DateTime2TimeStampStruct(TimeStampVal, AParams[ParamIndex].AsDateTime);
           DateTime2TimeStampStruct(TimeStampVal, AParams[ParamIndex].AsDateTime);

+ 1 - 11
packages/fcl-db/tests/testdbbasics.pas

@@ -1922,22 +1922,12 @@ procedure TTestDBBasics.TestSupportTimeFields;
 var i          : byte;
 var i          : byte;
     ds         : TDataset;
     ds         : TDataset;
     Fld        : TField;
     Fld        : TField;
-    s          : string;
-    millisecond: word;
-    second     : word;
-    minute     : word;
-    hour       : word;
 begin
 begin
   TestfieldDefinition(ftTime,8,ds,Fld);
   TestfieldDefinition(ftTime,8,ds,Fld);
 
 
   for i := 0 to testValuesCount-1 do
   for i := 0 to testValuesCount-1 do
     begin
     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;
     ds.Next;
     end;
     end;
   ds.close;
   ds.close;

+ 8 - 0
packages/fcl-db/tests/testfieldtypes.pas

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

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

@@ -202,6 +202,9 @@ var dbtype,
 procedure InitialiseDBConnector;
 procedure InitialiseDBConnector;
 procedure FreeDBConnector;
 procedure FreeDBConnector;
 
 
+function DateTimeToTimeString(d: tdatetime) : string;
+function TimeStringToDateTime(d: String): TDateTime;
+
 implementation
 implementation
 
 
 uses
 uses
@@ -318,6 +321,40 @@ begin
     FreeAndNil(DBConnector);
     FreeAndNil(DBConnector);
 end;
 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 }
 { TTestDataLink }
 
 
 {$IFDEF FPC}
 {$IFDEF FPC}