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,
Screen update during long query
Re: Screen update during long query
I have used several query components for several databases. I keep my apps responsive by threading.
Hope this helps.
Hope this helps.
-
hardstyleuk
- Posts: 5
- Joined: Mon 23 Mar 2009 04:59
Re: Screen update during long query
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
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:
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).
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;