Permalink
Browse files

While executing a user query, display elapsed execution time in hh:mm…

…:ss format, on status bar. See https://www.heidisql.com/forum.php?t=24763
  • Loading branch information...
ansgarbecker committed Mar 4, 2018
1 parent f707a93 commit 886b0026616c5d71cc4417289db62c5926563539
Showing with 33 additions and 6 deletions.
  1. +3 −0 source/apphelpers.pas
  2. +30 −6 source/main.pas
View
@@ -96,6 +96,7 @@ TQueryThread = class(TThread)
FErrorMessage: String;
FBatchPosition: Integer;
FQueriesInPacket: Integer;
FQueryStartedAt: TDateTime;
FQueryTime: Cardinal;
FQueryNetTime: Cardinal;
FRowsAffected: Int64;
@@ -113,6 +114,7 @@ TQueryThread = class(TThread)
property TabNumber: Integer read FTabNumber;
property BatchPosition: Integer read FBatchPosition;
property QueriesInPacket: Integer read FQueriesInPacket;
property QueryStartedAt: TDateTime read FQueryStartedAt;
property QueryTime: Cardinal read FQueryTime;
property QueryNetTime: Cardinal read FQueryNetTime;
property RowsAffected: Int64 read FRowsAffected;
@@ -2915,6 +2917,7 @@ constructor TQueryThread.Create(Connection: TDBConnection; Batch: TSQLBatch; Tab
FBatch := Batch;
FTabNumber := TabNumber;
FBatchPosition := 0;
FQueryStartedAt := Now;
FQueryTime := 0;
FQueryNetTime := 0;
FRowsAffected := 0;
View
@@ -55,6 +55,7 @@ TQueryTab = class(TComponent)
procedure SetMemo(Value: TSynMemo);
procedure SetMemoFilename(Value: String);
procedure TimerLastChangeOnTimer(Sender: TObject);
procedure TimerStatusUpdateOnTimer(Sender: TObject);
procedure MemoOnChange(Sender: TObject);
public
Number: Integer;
@@ -81,6 +82,7 @@ TQueryTab = class(TComponent)
HistoryDays: TStringList;
ListBindParams: TBindParam;
TimerLastChange: TTimer;
TimerStatusUpdate: TTimer;
function GetActiveResultTab: TResultTab;
procedure DirectoryWatchNotify(const Sender: TObject; const Action: TWatchAction; const FileName: string);
procedure MemofileModifiedTimerNotify(Sender: TObject);
@@ -2691,6 +2693,7 @@ procedure TMainForm.actExecuteQueryExecute(Sender: TObject);
// Start the execution thread
Screen.Cursor := crAppStart;
Tab.QueryRunning := True;
Tab.TimerStatusUpdate.Enabled := True;
Tab.ExecutionThread := TQueryThread.Create(ActiveConnection, Batch, Tab.Number);
end;
@@ -2700,14 +2703,8 @@ procedure TMainForm.actExecuteQueryExecute(Sender: TObject);
procedure TMainForm.BeforeQueryExecution(Thread: TQueryThread);
var
Text: String;
begin
// Update GUI stuff
Text := _('query')+' #' + FormatNumber(Thread.BatchPosition+1);
if Thread.QueriesInPacket > 1 then
Text := f_('queries #%s to #%s', [FormatNumber(Thread.BatchPosition+1), FormatNumber(Thread.BatchPosition+Thread.QueriesInPacket)]);
ShowStatusMsg(TimeToStr(Now) + ': ' + f_('Executing %s of %s ...', [Text, FormatNumber(Thread.Batch.Count)]));
SetProgressPosition(Thread.BatchPosition);
end;
@@ -2726,6 +2723,9 @@ procedure TMainForm.AfterQueryExecution(Thread: TQueryThread);
ShowStatusMsg(_('Setting up result grid(s) ...'));
Tab := GetQueryTabByNumber(Thread.TabNumber);
// Disable status updates
Tab.TimerStatusUpdate.Enabled := False;
// Create result tabs
for Results in Thread.Connection.GetLastResults do begin
NewTab := TResultTab.Create(Tab);
@@ -12285,6 +12285,11 @@ constructor TQueryTab.Create;
TimerLastChange.OnTimer := TimerLastChangeOnTimer;
// Contain 2 columns of String : Params & Values
ListBindParams := TBindParam.Create;
// Update status bar every second while query runs
TimerStatusUpdate := TTimer.Create(Self);
TimerStatusUpdate.Enabled := False;
TimerStatusUpdate.Interval := 100;
TimerStatusUpdate.OnTimer := TimerStatusUpdateOnTimer;
end;
@@ -12294,6 +12299,7 @@ destructor TQueryTab.Destroy;
DirectoryWatch.Free;
ListBindParams.Free;
TimerLastChange.Free;
TimerStatusUpdate.Free;
end;
@@ -12544,6 +12550,24 @@ procedure TQueryTab.TimerLastChangeOnTimer(Sender: TObject);
end;
procedure TQueryTab.TimerStatusUpdateOnTimer(Sender: TObject);
var
Msg, ElapsedMsg: String;
Elapsed: Int64;
begin
// Update status bar every second with elapsed time
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);
MainForm.ShowStatusMsg(ElapsedMsg + ': ' + f_('Executing %s of %s ...', [Msg, FormatNumber(ExecutionThread.Batch.Count)]));
// Fix short interval after first timer hit
TimerStatusUpdate.Interval := 1000;
end;

0 comments on commit 886b002

Please sign in to comment.