Screen update during long query

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
hardstyleuk
Posts: 5
Joined: Mon 23 Mar 2009 04:59

Screen update during long query

Post by hardstyleuk » Mon 10 Sep 2012 21:47

Hi,
Was wondering how to get the main form to refresh during the execution of a long query. If fact, how to get any response from the program while running a query. I can't seem to get the After or On Events for a TMyQuery to activate.

Thanks,

kbrad1
Posts: 3
Joined: Sun 09 Sep 2012 13:52

Re: Screen update during long query

Post by kbrad1 » Tue 11 Sep 2012 01:00

I have used several query components for several databases. I keep my apps responsive by threading.

Hope this helps.

hardstyleuk
Posts: 5
Joined: Mon 23 Mar 2009 04:59

Re: Screen update during long query

Post by hardstyleuk » Tue 11 Sep 2012 03:19

I see where you are coming from, however, how would you get progress or events from the long running query and/or a stored procedure?

AndreyZ

Re: Screen update during long query

Post by AndreyZ » Tue 11 Sep 2012 07:14

Unfortunately, there is no way to show the progress of running a query (or a stored procedure) that is executed on a server, for example, the UPDATE, INSERT, and DELETE operations. But if you want to show the progress of fetching data, it can be shown using the AfterFetch event handler. Here is a code example:

Code: Select all

procedure TMainForm.BitBtn1Click(Sender: TObject);
begin
  MyQuery1.SQL.Text := 'select count(*) from big_table';
  MyQuery1.Open;
  ProgressBar1.Max := MyQuery1.Fields[0].AsInteger;
  ProgressBar1.Position := 0;
  MyQuery1.FetchAll := False;
  MyQuery1.SQL.Text := 'select * from big_table';
  MyQuery1.Open;
  MyQuery1.Last; // to fetch all data
end;

procedure TMainForm.MyQuery1AfterFetch(DataSet: TCustomDADataSet);
begin
  ProgressBar1.Position := ProgressBar1.Position + DataSet.FetchRows; 
end;
And about threads usage. If you execute UPDATE, INSERT, or DELETE statements in the main thread, the execution of your application is stopped until server responds about the end of execution. In this case you cannot check if execution is in progress. If you execute UPDATE, INSERT, or DELETE statements in additional threads, your application continues working without any stops (because query execution is performed in another thread). In this case you can check if query execution is in progress using the TMyQuery.Executing property (you should check it in a separate thread).

Post Reply