From 83d6b02d7c2b38afc8b7199e94e5d1a4a04132a5 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 18 Mar 2018 21:17:33 +0100 Subject: [PATCH] Display tenths of a second through FormatTimeNumber. Used by query running status, table tools dialog and some more. --- source/apphelpers.pas | 29 ++++++++++++++++++----------- source/dbconnection.pas | 2 +- source/main.pas | 6 +++--- source/tabletools.pas | 4 ++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/source/apphelpers.pas b/source/apphelpers.pas index e294f3c3..8a5147e0 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -282,7 +282,7 @@ type function RegExprGetMatch(Expression: String; var Input: String; ReturnMatchNum: Integer; DeleteFromSource: Boolean): String; function FormatByteNumber( Bytes: Int64; Decimals: Byte = 1 ): String; Overload; function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload; - function FormatTimeNumber(Seconds: Cardinal; DisplaySeconds: Boolean): String; + function FormatTimeNumber(Seconds: Double; DisplaySeconds: Boolean): String; function GetTempDir: String; procedure SaveUnicodeFile(Filename: String; Text: String); procedure OpenTextFile(const Filename: String; out Stream: TFileStream; var Encoding: TEncoding); @@ -1078,11 +1078,12 @@ end; @param Cardinal Number of seconds @result String 12:34:56 } -function FormatTimeNumber(Seconds: Cardinal; DisplaySeconds: Boolean): String; +function FormatTimeNumber(Seconds: Double; DisplaySeconds: Boolean): String; var - d, h, m, s : Integer; + d, h, m, s, ts: Integer; begin - s := Seconds; + s := Trunc(Seconds); + ts := Trunc((Seconds - s) * 10); // ts = tenth of a second d := s div (60*60*24); s := s mod (60*60*24); h := s div (60*60); @@ -1090,15 +1091,21 @@ begin m := s div 60; s := s mod 60; if d > 0 then begin - if DisplaySeconds then - Result := Format('%d '+_('days')+', %.2d:%.2d:%.2d', [d, h, m, s]) - else + if DisplaySeconds then begin + Result := Format('%d '+_('days')+', %.2d:%.2d:%.2d', [d, h, m, s]); + Result := Result + '.' + IntToStr(ts); + end + else begin Result := Format('%d '+_('days')+', %.2d:%.2d h', [d, h, m]); + end; end else begin - if DisplaySeconds then - Result := Format('%.2d:%.2d:%.2d', [h, m, s]) - else - Result := Format('%.2d:%.2d h', [h, m]) + if DisplaySeconds then begin + Result := Format('%.2d:%.2d:%.2d', [h, m, s]); + Result := Result + '.' + IntToStr(ts); + end + else begin + Result := Format('%.2d:%.2d h', [h, m]); + end; end; end; diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 53e56281..0ce22241 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -4869,7 +4869,7 @@ begin if rx.Exec(Infos) then while True do begin Val := rx.Match[2]; if LowerCase(rx.Match[1]) = 'uptime' then - Val := FormatTimeNumber(StrToIntDef(Val, 0), True) + Val := FormatTimeNumber(StrToFloatDef(Val, 0), True) else Val := FormatNumber(Val); Result.Values[_(rx.Match[1])] := Val; diff --git a/source/main.pas b/source/main.pas index c59e85e4..1ec478d5 100644 --- a/source/main.pas +++ b/source/main.pas @@ -2841,7 +2841,7 @@ begin if Thread.QueryTime < 60*1000 then MetaInfo := MetaInfo + ': '+FormatNumber(Thread.QueryTime/1000, 3) +' sec.' else - MetaInfo := MetaInfo + ': '+FormatTimeNumber(Thread.QueryTime div 1000, True); + MetaInfo := MetaInfo + ': '+FormatTimeNumber(Thread.QueryTime/1000, True); if Thread.QueryNetTime > 0 then MetaInfo := MetaInfo + ' (+ '+FormatNumber(Thread.QueryNetTime/1000, 3) +' sec. network)'; LogSQL(MetaInfo); @@ -12565,8 +12565,8 @@ begin Msg := _('query')+' #' + FormatNumber(ExecutionThread.BatchPosition+1); if ExecutionThread.QueriesInPacket > 1 then Msg := f_('queries #%s to #%s', [FormatNumber(ExecutionThread.BatchPosition+1), FormatNumber(ExecutionThread.BatchPosition+ExecutionThread.QueriesInPacket)]); - Elapsed := SecondsBetween(ExecutionThread.QueryStartedAt, Now); - ElapsedMsg := FormatTimeNumber(Elapsed, True); + Elapsed := MilliSecondsBetween(ExecutionThread.QueryStartedAt, Now); + ElapsedMsg := FormatTimeNumber(Elapsed/1000, True); MainForm.ShowStatusMsg(ElapsedMsg + ': ' + f_('Executing %s of %s ...', [Msg, FormatNumber(ExecutionThread.Batch.Count)])); end; diff --git a/source/tabletools.pas b/source/tabletools.pas index 2f6794d9..2e417973 100644 --- a/source/tabletools.pas +++ b/source/tabletools.pas @@ -748,7 +748,7 @@ begin DeleteFile(FileName); LogRow := FResults.Last; LogRow[2] := _('Compressing done.'); - LogRow[3] := FormatTimeNumber((GetTickCount-StartTime) DIV 1000, True); + LogRow[3] := FormatTimeNumber((GetTickCount-StartTime) / 1000, True); ResultGrid.Repaint; end; @@ -1352,7 +1352,7 @@ const BytesDone := Max(DBObj.Size,0) div Max(DBObj.Rows,1) * RowsDone; FObjectSizesDoneExact := FObjectSizesDone + BytesDone; LogRow[2] := FormatNumber(RowsDone) + ' / ' + FormatNumber(Percent, 0)+'%'; - LogRow[3] := FormatTimeNumber((GetTickCount-StartTime) DIV 1000, True); + LogRow[3] := FormatTimeNumber((GetTickCount-StartTime) / 1000, True); UpdateResultGrid; end;