Browse Source

* Patch from Ladislav Karrach to add msec support to sqlite-time fields,
bug #18840
* Adapted/fixed test for timefields, to allow testing for msec values,
bug #18763

git-svn-id: trunk@17415 -

joost 14 years ago
parent
commit
7f1a6b8e3e

+ 5 - 4
packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp

@@ -447,18 +447,19 @@ end;
 Function ParseSQLiteTime(S : ShortString; Interval: boolean) : TDateTime;
 
 Var
-  Hour, Min, Sec : Integer;
+  Hour, Min, Sec, MSec : Integer;
 
 begin
   Result:=0;
   If TryStrToInt(NextWord(S,':'),Hour) then
     if TryStrToInt(NextWord(S,':'),Min) then
-      if TryStrToInt(NextWord(S,':'),Sec) then
+      if TryStrToInt(NextWord(S,'.'),Sec) then
         begin
+        MSec:=StrToIntDef(S,0);
         if Interval then
-          Result:=EncodeTimeInterval(Hour,Min,Sec,0)
+          Result:=EncodeTimeInterval(Hour,Min,Sec,MSec)
         else
-          Result:=EncodeTime(Hour,Min,Sec,0);
+          Result:=EncodeTime(Hour,Min,Sec,MSec);
         end;
 end;
 

+ 6 - 0
packages/fcl-db/tests/sqldbtoolsunit.pas

@@ -114,6 +114,12 @@ begin
     for t := 0 to testValuesCount-1 do
       testStringValues[t] := TrimRight(testStringValues[t]);
     end;
+  if SQLDbType in [odbc,mysql40,mysql41,mysql50,mysql51] then
+    begin
+    // Some DB's do not support milliseconds in time-fields.
+    for t := 0 to testValuesCount-1 do
+      testTimeValues[t] := copy(testTimeValues[t],1,8)+'.000';
+    end;
   if SQLDbType = MYSQL50 then Fconnection := tMySQL50Connection.Create(nil);
   if SQLDbType = MYSQL51 then Fconnection := tMySQL51Connection.Create(nil);
   if SQLDbType = sqlite3 then

+ 26 - 26
packages/fcl-db/tests/toolsunit.pas

@@ -160,31 +160,31 @@ const
   );
 
   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'
+    '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.010',
+    '13:55:12.200',
+    '13:46:12.542',
+    '15:35:12.000',
+    '17:25:12.530',
+    '19:45:12.003',
+    '10:54:12.999',
+    '12:25:12.000',
+    '20:15:12.758',
+    '12:25:12.000'
   );
 
 
@@ -336,7 +336,7 @@ 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]);
+  result := Format('%.2d',[hour]) + ':' + format('%.2d',[minute]) + ':' + format('%.2d',[second]) + '.' + format('%.3d',[millisecond]);
 end;
 
 function TimeStringToDateTime(d: String): TDateTime;