Page 1 of 1

How do I get the duration the SQL statement to run

Posted: Fri 12 Mar 2010 09:38
by CFaiga
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;


Posted: Fri 12 Mar 2010 12:21
by Challenger
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;