如何跟踪应用程序执行的SQL语句
如何跟踪Delphi应用程序和数据库交互的SQL语句内容,使用TSQLMonitor只能获取到SQL语句,不能获取到参数值。以下是某程序SQL跟踪器的示例。
Select StoreLocID, QtyUnit, CostPrice, AmtBlc, QtyBlc
from Stgenleg
where Sysid=? and AccYear=? and AccMonth=?
and Itemid=?
PARAMCOUNT = 4, Owner = (UnNamed: TSQLQuery)
PARAMS[0] : Name = Sysid , DataType = Integer , Value = "1"
PARAMS[1] : Name = AccYear , DataType = Integer , Value = "2013"
PARAMS[2] : Name = AccMonth, DataType = Integer , Value = "11"
PARAMS[3] : Name = Itemid , DataType = Integer , Value = "484"
type
TADOQueryHook = class(TADOQuery);
function GetSetActiveAddr : Pointer;
begin
Result := @TADOQueryHook.SetActive;
end;
//用GetSetActiveAddr得到SetActive过程的地址,然后用InLine_HOOK,新入口格式如下:
procedure NewSetAvtiveProc(Self : TDataSet; Value : Boolean);
begin
if Value and (PPointer(Self)^ = TADOQuery) then begin
ShowMessage(TADOQuery(Self).SQL.Text);
end;
end;