-
Notifications
You must be signed in to change notification settings - Fork 91
/
LoggerPro.DBAppender.FireDAC.pas
101 lines (88 loc) · 3.04 KB
/
LoggerPro.DBAppender.FireDAC.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
unit LoggerPro.DBAppender.FireDAC;
// DB log appender for FireDAC
interface
uses
System.Classes,
LoggerPro, System.SysUtils, Data.DB,
LoggerPro.DBAppender,
FireDAC.Stan.Error,
FireDAC.DApt,
FireDAC.Phys,
FireDAC.Stan.Param,
FireDAC.Comp.Client;
type
TLoggerProDBAppenderFireDACCustom = class abstract(TLoggerProDBAppender<TFDStoredProc>)
protected
procedure RefreshParams(DataObj: TFDStoredProc); override;
procedure ExecuteDataObject(DataObj: TFDStoredProc); override;
end;
/// <summary>LoggerPro that persists to DB via a FireDAC stored procedure</summary>
TLoggerProDBAppenderFireDAC = class(TLoggerProDBAppenderFireDACCustom)
public
constructor Create(
const ConnectionDefName: String;
const StoredProcName: String;
const OnDBWriteError: TOnDBWriteError); reintroduce; overload;
constructor Create(
const ConnectionDefName: String;
const StoredProcName: String;
const SetParams: TSetParams<TFDStoredProc>;
const OnDBWriteError: TOnDBWriteError); reintroduce; overload;
end;
implementation
{ TLoggerProDBAppenderFireDAC }
constructor TLoggerProDBAppenderFireDAC.Create(const ConnectionDefName,
StoredProcName: String; const SetParams: TSetParams<TFDStoredProc>;
const OnDBWriteError: TOnDBWriteError);
begin
inherited Create(
function: TCustomConnection
begin
Result := TFDConnection.Create(nil);
Result.LoginPrompt := False;
TFDConnection(Result).ConnectionDefName := ConnectionDefName;
end,
function(Connection: TCustomConnection): TFDStoredProc
begin
Result := TFDStoredProc.Create(nil);
Result.StoredProcName := StoredProcName;
Result.Connection := Connection as TFDConnection;
end,
SetParams,
OnDBWriteError);
end;
procedure TLoggerProDBAppenderFireDACCustom.ExecuteDataObject(DataObj: TFDStoredProc);
begin
DataObj.ExecProc;
end;
procedure TLoggerProDBAppenderFireDACCustom.RefreshParams(DataObj: TFDStoredProc);
begin
DataObj.Prepare;
end;
constructor TLoggerProDBAppenderFireDAC.Create(const ConnectionDefName,
StoredProcName: String; const OnDBWriteError: TOnDBWriteError);
begin
inherited Create(
function: TCustomConnection
begin
Result := TFDConnection.Create(nil);
Result.LoginPrompt := False;
TFDConnection(Result).ConnectionDefName := ConnectionDefName;
end,
function(Connection: TCustomConnection): TFDStoredProc
begin
Result := TFDStoredProc.Create(nil);
Result.StoredProcName := StoredProcName;
Result.Connection := Connection as TFDConnection;
end,
procedure(SP: TFDStoredProc; LogItem: TLogItem)
begin
SP.ParamByName('p_log_type').Value := Integer(LogItem.LogType);
SP.ParamByName('p_log_tag').Value := LogItem.LogTag;
SP.ParamByName('p_log_message').Value := LogItem.LogMessage;
SP.ParamByName('p_log_timestamp').Value := LogItem.TimeStamp;
SP.ParamByName('p_log_thread_id').Value := LogItem.ThreadID;
end,
OnDBWriteError);
end;
end.