Page 1 of 1

TMyQuery: get execute time?

Posted: Fri 24 Nov 2017 09:35
by vindac
Hi,
is there a way to get the time it took to execute a query (TMyQuery.Execute) ?
Thanks:)

Re: TMyQuery: get execute time?

Posted: Fri 24 Nov 2017 12:46
by ViktorV
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]));