-
Notifications
You must be signed in to change notification settings - Fork 91
/
LoggerPro.DBAppender.ADO.pas
85 lines (67 loc) · 1.85 KB
/
LoggerPro.DBAppender.ADO.pas
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
84
85
unit LoggerPro.DBAppender.ADO;
// DB log appender - using dbGo aka ADO
interface
uses
System.Classes,
LoggerPro, System.SysUtils, Data.DB,
LoggerPro.DBAppender,
Data.Win.ADODB;
type
ESQLException = class(Exception)
private
FErrorCode: Integer;
public
constructor Create(AMessage: string; AErrorCode: Integer); overload;
constructor Create(StoredProc: TADOStoredProc); overload;
end;
/// <summary>LoggerPro that persists to DB via ADO stored procedure</summary>
TLoggerProDBAppenderADO = class(TLoggerProDBAppender<TADOStoredProc>)
protected
procedure RefreshParams(DataObj: TADOStoredProc); override;
procedure ExecuteDataObject(DataObj: TADOStoredProc); override;
public
procedure Setup; override;
procedure TearDown; override;
end;
implementation
uses
System.IOUtils, Winapi.ActiveX;
{ ESQLException }
constructor ESQLException.Create(AMessage: string; AErrorCode: Integer);
begin
inherited Create(AMessage);
FErrorCode := AErrorCode;
end;
constructor ESQLException.Create(StoredProc: TADOStoredProc);
var
LastErrorIdx: Integer;
begin
if StoredProc.Connection <> nil then
begin
LastErrorIdx := StoredProc.Connection.Errors.Count - 1;
Create(StoredProc.Connection.Errors.Item[LastErrorIdx].Description, StoredProc.Connection.Errors.Item[LastErrorIdx]
.NativeError);
end;
end;
{ TLoggerProDBAppenderADO }
procedure TLoggerProDBAppenderADO.ExecuteDataObject(DataObj: TADOStoredProc);
begin
DataObj.ExecProc;
if DataObj.Connection.Errors.Count > 0 then
raise ESQLException.Create(DataObj);
end;
procedure TLoggerProDBAppenderADO.RefreshParams(DataObj: TADOStoredProc);
begin
DataObj.Parameters.Refresh;
end;
procedure TLoggerProDBAppenderADO.Setup;
begin
CoInitialize(nil);
inherited;
end;
procedure TLoggerProDBAppenderADO.TearDown;
begin
inherited;
CoUninitialize;
end;
end.