1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
{ TADOQuery }
//------------------------------------------------------------------------------
constructor TADOQuery.Create(AContext: TConfigContext);
begin
Create(AContext.Server, AContext.Catalog, AContext.Schema);
FContext := AContext;
end;
//------------------------------------------------------------------------------
constructor TADOQuery.Create(const AServer: string; const ACatalog: string = ''; const ASchema: string = '');
begin
inherited Create(nil);
FServer := AServer;
FCatalog := ACatalog;
FSchema := ASchema;
end;
//------------------------------------------------------------------------------
function TADOQuery.ExecSQL(): Integer;
var
Chrono: TStopwatch;
begin
Chrono := TStopwatch.StartNew();
try
Result := inherited ExecSQL();
except
on E: EOleException do
begin
if (E.ErrorCode = Winapi.Windows.E_FAIL) and Assigned(FContext) then
begin
// Pas de reconnexion pour un ExecSQL !
if ccoAutoReconnectIfDisconnected in FContext.ConnectionOptions then
Connection.Connected := False;
end;
raise;
end;
end;
// Log uniquement les requêtes qui ont réussi (sans Exception)
Chrono.Stop();
TADOQueryHelper.TSQLLogger.Instance.Push(FServer, FCatalog, FSchema, SQL, Round(Chrono.ElapsedTicks / Chrono.Frequency * 1000000));
end;
//------------------------------------------------------------------------------
procedure TADOQuery.Open();
var
Chrono: TStopwatch;
begin
Chrono := TStopwatch.StartNew();
try
inherited Open();
except
on E: EOleException do
begin
if (E.ErrorCode = Winapi.Windows.E_FAIL) and Assigned(FContext) then
begin
if ccoAutoReconnectAfterOpenError in FContext.ConnectionOptions then
begin
if FContext.ReConnection(Connection) then
begin
inherited Open();
Exit;
end;
end
else if ccoAutoReconnectIfDisconnected in FContext.ConnectionOptions then
Connection.Connected := False;
end;
raise;
end;
end;
// Log uniquement les requêtes qui sont ouvertes (sans Exception ni Reconnexion)
Chrono.Stop();
TADOQueryHelper.TSQLLogger.Instance.Push(FServer, FCatalog, FSchema, SQL, Round(Chrono.ElapsedTicks / Chrono.Frequency * 1000000));
end; |
Partager