tags:

views:

342

answers:

2

Hi

I have a Delphi 7 app using ADO/MSDASQL.1 provider and I wonder if it is possible to "log" the SQL queries sent to the DB in a easy way? Just like the SQL profiler in SQL Server?

//Andy

+6  A: 

Inside your application you can log the commands in TADOConnection.OnWillExecute event, you only have to save the CommandText, but you can also log a lot of other options.

procedure TForm23.ADOConnection1WillExecute(Connection: TADOConnection; var
  CommandText: WideString; var CursorType: TCursorType; var LockType:
  TADOLockType; var CommandType: TCommandType; var ExecuteOptions:
  TExecuteOptions; var EventStatus: TEventStatus; const Command: _Command;
  const Recordset: _Recordset);
begin
   LogToFile( CommandText );
end;
Cesar Romero
I can only log selects this way, how i can log other types of queries?
arthurprs
A: 

I do something similar, but all my queries go through a single point. It was a simple change to add logging at this point. Another option would be to create a TLogADOQuery class which descends from TADOQuery, and override ExecuteSQL and Open to log the SQL going to the database. You then replace all references to TADOQuery, with your new class.

Steve