How do I get the duration the SQL statement to run

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
CFaiga
Posts: 14
Joined: Sun 12 Feb 2006 09:28

How do I get the duration the SQL statement to run

Post by CFaiga » Fri 12 Mar 2010 09:38

Hi

I am using MySQLMonitorSQL to log my sql commands.
How do I get the duration in milliseconds that the SQL took to run.

Thanks

Code: Select all

procedure TFrmMain.MySQLMonitorSQL(Sender: TObject; Text: string;Flag: TDATraceFlag); 
var 
  Duration : Integer; // how long the query takes
begin    
   Duration := ??; // how do I get this value ?
   LogSqlStament(Duration,Text)

end;


Challenger
Devart Team
Posts: 925
Joined: Thu 17 Nov 2005 10:53

Post by Challenger » Fri 12 Mar 2010 12:21

There is no simple way to do this. We can only suggest you to override TMySqlMonitor:

Code: Select all

  TUniSqlMonitorEx = class(TUniSqlMonitor)
  private
    FExecuteDuration: Cardinal;
  protected
    procedure InternalSQLExecute(Obj: TObject; const SQL: _string; Params: TDAParams; const Caption: string; BeforeEvent: boolean; var MessageID: Cardinal); override;
  public
    property ExecuteDuration: Cardinal read FExecuteDuration;
  end;

procedure TUniSqlMonitorEx.InternalSQLExecute(Obj: TObject;
  const SQL: _string; Params: TDAParams; const Caption: string;
  BeforeEvent: boolean; var MessageID: Cardinal);
begin
  if BeforeEvent then
    FExecuteDuration := GetTickCount;

  inherited;

  if not BeforeEvent then
    FExecuteDuration := GetTickCount - FExecuteDuration;
end;

Post Reply