【问题标题】:How can I monitor the SQL my Delphi application executes?如何监控我的 Delphi 应用程序执行的 SQL?
【发布时间】:2011-10-30 03:41:28
【问题描述】:

Delphi XE 中有没有一种方法可以让 SQL 监视器跟踪我的应用程序执行的所有 SQL? Delphi 5 有一个组件。

【问题讨论】:

  • SQL Monitor 与 BDE 一起工作,您还在使用 BDE 或其他组件吗?
  • @RRUZ - TSQLMonitor 是 dbexpress 的一部分。
  • @Sertac,我认为哪个 OP 在谈论 Sql Monitor 工具,它是 Delphi IDE 5 的一部分。
  • 欢迎来到 StackOverflow。您的问题只能以您提出的“可能”方式回答。您没有提及您正在使用哪个数据库引擎或哪些数据访问控制,这对问题至关重要。请编辑您的问题并提供更多信息(例如正在使用的数据库引擎、您用于访问该 DBMS 的组件以及您在 Delphi 5 中使用的引用的组件)。谢谢。 :)
  • @Sam 如果不是特定于 DBMS,至少是特定于组件的。例如,我们提供auto SQL logging for the DB access layer of our ORM。将适用于所有 DBMS,因为 SQL 日志记录是在抽象层中进行的。但是 AFAIK 在 Delphi 中没有“通用”解决方案。甚至 Delphi 5 解决方案也是特定于 BDE 的。

标签: sql delphi monitoring delphi-xe


【解决方案1】:

正如here 已经建议的那样,您可以使用 TAdoConnection.OnWillExecute 事件向控制台发送查询,例如:

procedure TDataModuleProd.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
  {$ifdef DEBUG}
     OutputDebugString(PChar('SQL Execute: ' + CommandText));
  {$endif}
end;

【讨论】:

  • 抱歉...您在问题中的哪个位置看到提到了 ADO?我一定在某个地方错过了它。 :)
  • ...您将失去绑定的参数值...与此无关的信息...至少需要检索它们并将它们添加到记录的文本中。
  • 谢谢,请问如何在 Delphi XE 中显示控制台,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-30
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 2010-09-08
相关资源
最近更新 更多