Using Delphi 2006; My aim is to check wether a TSQLConnection instance is idle or not. Therefore, i am setting a Datetime "m_dLastActivity" to "now" each time activity is seen.
As TSQLMonitor is buggy in its trace handling and causes memory problems (see http://qc.embarcadero.com/wc/qcmain.aspx?d=89216), i try to register a trace callback of my own using SetTraceCallbackEvent:
procedure TConnectionGuard.SetSQLConnection(const Value: TSQLConnection);
begin
...
if Assigned ( Value )
and not ( csDesigning in ComponentState ) then begin
...
m_SQLConnection.SetTraceCallbackEvent(U_ConnectionGuard.OnTraceCallBack, integer(self));
...
end;
end;
The callback is just returning the data to the TConnectionGuard object that registered it:
function OnTraceCallBack( CallType: TRACECat; CBInfo: Pointer): CBRType; stdcall;
var Desc: pSQLTraceDesc;
begin
Desc := pSQLTraceDesc(CBInfo);
Result := TConnectionGuard(Desc.ClientData).OnTraceCallBack(CallType, CBInfo);
end;
The event itself:
function TConnectionGuard.OnTraceCallBack(CallType: TRACECat; Desc: pSQLTraceDesc): CBRType;
begin
m_dLastActivity := now;
Result := cbrUSEDEF;
end;
So far, so good, it works. But i am quite uncomfortable with the fact that i have no idea what i have to pass back as CBRType result (defined in DBCommonTypes.pas) to have a minimum performance impact. In fact, i have no idea what i am answering, as the given parameter CallCAT provides no hint how to read / handle it.
Does anyone know if cbrUSEDEF is the right thing to have tracing at a minimum?
EDIT: I realized through the source code of TSQLMonitor that the CBInfo pointer given is not the client info i registered, but a psQLTraceDesc that contains the client info (in this case, the pointer to my Guard). I have adapted the methods to that fact...