TMyQuery: get execute time?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
vindac
Posts: 20
Joined: Tue 18 Mar 2014 16:44

TMyQuery: get execute time?

Post by vindac » Fri 24 Nov 2017 09:35

Hi,
is there a way to get the time it took to execute a query (TMyQuery.Execute) ?
Thanks:)

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TMyQuery: get execute time?

Post by ViktorV » Fri 24 Nov 2017 12:46

You can use the event handlers TMyQuery.BeforeExecute and TMyQuery.AfterExecute to calculate the time of the TMyQuery.Execute method execution.
If you want to know the query execution time on the server, you can use the following code:

Code: Select all

var
  Time : Double;
...
  MyQuery.SQL.Text := 'SET PROFILING = 1;' +
    'INSERT INTO DEPT (DNAME) VALUES (''Test'');' +
    'SHOW PROFILES;';
  MyQuery.Execute;
  Time := MyQuery.FieldByName('Duration').AsFloat;
  ShowMessage(Format('Took execute query on server: %f sec', [Time]));

Post Reply