Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the elapsed time while a long SQL Query is executed?

I need to show a popup window before a query execution, show the time elapsed while the sql query is being executed, and close that window when the query ends.

Actually I do something like this

var
  frm : tFrmPopupElapsed;
  // this form has a TTimer and a TLabel to show the elapsed time
  // but the label is not updated, I tried using update and refresh
  // but nothing happens
begin
  frm := tFrmPopupElapsed.Create(nil);
  try
    frm.Init; // this procedure enables the timer
    frm.Show();
    ExecuteMyVeryLongQuery();
  finally
    frm.Close; 
  end;
end;

How can the label be updated to show the elapsed time while the query executes? Using a timer? Or a thread?

like image 761
Salvador Avatar asked Mar 26 '10 21:03

Salvador


2 Answers

You need to run the query asynchronously, allowing you to update the Form in the meantime.
The simplest way to do it without getting your hands dirty with the threads is to use Andreas Hausladen's AsynCalls library.
You can also give a look at the OmniThread Library by Primoz Gabrijelcic.

like image 56
Francesca Avatar answered Nov 15 '22 09:11

Francesca


You will need to run the query in a background thread if you want the user interface to be responsive during the query execution. If the query supports cancellation, you could also add a cancel button. I believe only ADO queries support this, however.

like image 22
Alan Clark Avatar answered Nov 15 '22 09:11

Alan Clark