line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DMARC::Report::Store::SQL::Grammars::SQLite; |
2
|
|
|
|
|
|
|
our $VERSION = '1.20211209'; |
3
|
4
|
|
|
4
|
|
32
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
129
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
4869
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
10
|
|
|
10
|
0
|
35
|
my $class = shift; |
8
|
10
|
|
|
|
|
30
|
my $self = { }; |
9
|
10
|
|
|
|
|
31
|
bless $self, $class; |
10
|
10
|
|
|
|
|
37
|
return $self; |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub language { |
14
|
26
|
|
|
26
|
0
|
190
|
return 'sqlite'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub dsn { |
18
|
621
|
|
|
621
|
0
|
1523
|
return 'SQLite'; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub and_arg { |
22
|
16
|
|
|
16
|
0
|
37
|
my ($self, $column, $operator) = @_; |
23
|
16
|
|
100
|
|
|
81
|
$operator //= '='; |
24
|
|
|
|
|
|
|
|
25
|
16
|
|
|
|
|
85
|
return " AND $column $operator ?"; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub report_record_id { |
29
|
8
|
|
|
8
|
0
|
44
|
return 'SELECT id FROM report_record WHERE report_id=?'; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub delete_from_where_record_in { |
33
|
12
|
|
|
12
|
0
|
34
|
my ($self, $table) = @_; |
34
|
12
|
|
|
|
|
82
|
return "DELETE FROM $table WHERE report_record_id IN (??)" |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub delete_from_where_report { |
38
|
24
|
|
|
24
|
0
|
82
|
my ($self, $table) = @_; |
39
|
24
|
|
|
|
|
205
|
return "DELETE FROM $table WHERE report_id=?"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub delete_report { |
43
|
8
|
|
|
8
|
0
|
56
|
return "DELETE FROM report WHERE id=?"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub select_domain_id { |
47
|
48
|
|
|
48
|
0
|
260
|
return 'SELECT id FROM domain WHERE domain=?'; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub insert_domain { |
51
|
22
|
|
|
22
|
0
|
109
|
return 'INSERT INTO domain (domain) VALUES (?)'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub select_author_id { |
55
|
12
|
|
|
12
|
0
|
66
|
return 'SELECT id FROM author WHERE org_name=?'; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub insert_author { |
59
|
9
|
|
|
9
|
0
|
57
|
return 'INSERT INTO author (org_name,email,extra_contact) VALUES (?,?,?)'; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub select_report_id { |
63
|
0
|
|
|
0
|
0
|
0
|
return 'SELECT id FROM report WHERE uuid=? AND author_id=?'; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub select_id_with_end { |
67
|
9
|
|
|
9
|
0
|
103
|
return 'SELECT id FROM report WHERE from_domain_id=? AND end > ? AND author_id=?'; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub insert_report { |
71
|
9
|
|
|
9
|
0
|
69
|
return 'INSERT INTO report (from_domain_id, begin, end, author_id, uuid) VALUES (?,?,?,?,?)'; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub order_by { |
75
|
0
|
|
|
0
|
0
|
0
|
my ($self, $arg, $order) = @_; |
76
|
0
|
|
|
|
|
0
|
return " ORDER BY $arg $order"; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub count_reports { |
80
|
4
|
|
|
4
|
0
|
21
|
return 'SELECT COUNT(*) FROM report'; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub limit { |
84
|
2
|
|
|
2
|
0
|
5
|
my ($self, $number_of_entries) = @_; |
85
|
2
|
|
100
|
|
|
9
|
$number_of_entries //= 1; |
86
|
2
|
|
|
|
|
11
|
return " LIMIT $number_of_entries"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub limit_args { |
90
|
1
|
|
|
1
|
0
|
21
|
my ($self, $number_of_entries) = @_; |
91
|
1
|
|
|
|
|
4
|
my $return = ' LIMIT '; |
92
|
1
|
|
50
|
|
|
10
|
$number_of_entries //= 1; |
93
|
1
|
|
|
|
|
4
|
for (my $i = 1; $i <= $number_of_entries; $i++) { |
94
|
1
|
|
|
|
|
4
|
$return .= '?'; |
95
|
1
|
50
|
|
|
|
6
|
$return .= ',' if $i < $number_of_entries; |
96
|
|
|
|
|
|
|
} |
97
|
1
|
|
|
|
|
4
|
return $return; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub select_report_policy_published { |
101
|
6
|
|
|
6
|
0
|
35
|
return 'SELECT * from report_policy_published WHERE report_id=?'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub select_report_reason { |
105
|
0
|
|
|
0
|
0
|
0
|
return 'SELECT type,comment FROM report_record_reason WHERE report_record_id=?'; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub select_report_error { |
109
|
6
|
|
|
6
|
0
|
45
|
return 'SELECT error FROM report_error WHERE report_id=?'; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub select_report_record { |
113
|
0
|
|
|
0
|
0
|
0
|
return 'SELECT id FROM report_record WHERE report_id=? AND source_ip=? AND count=?' |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub select_todo_query { |
117
|
|
|
|
|
|
|
return <<'EO_TODO_QUERY' |
118
|
|
|
|
|
|
|
SELECT r.id AS rid, |
119
|
|
|
|
|
|
|
r.begin AS begin, |
120
|
|
|
|
|
|
|
r.end AS end, |
121
|
|
|
|
|
|
|
a.org_name AS author, |
122
|
|
|
|
|
|
|
fd.domain AS from_domain |
123
|
|
|
|
|
|
|
FROM report r |
124
|
|
|
|
|
|
|
LEFT JOIN report_record rr ON r.id=rr.report_id |
125
|
|
|
|
|
|
|
LEFT JOIN author a ON r.author_id=a.id |
126
|
|
|
|
|
|
|
LEFT JOIN domain fd ON r.from_domain_id=fd.id |
127
|
|
|
|
|
|
|
WHERE rr.count IS NULL |
128
|
|
|
|
|
|
|
AND rr.report_id IS NOT NULL |
129
|
|
|
|
|
|
|
AND r.end < ? |
130
|
|
|
|
|
|
|
GROUP BY r.id |
131
|
|
|
|
|
|
|
ORDER BY r.id ASC |
132
|
|
|
|
|
|
|
EO_TODO_QUERY |
133
|
5
|
|
|
5
|
0
|
50
|
; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub select_row_spf { |
137
|
|
|
|
|
|
|
return <<"EO_SPF_ROW" |
138
|
|
|
|
|
|
|
SELECT d.domain AS domain, |
139
|
|
|
|
|
|
|
s.result AS result, |
140
|
|
|
|
|
|
|
s.scope AS scope |
141
|
|
|
|
|
|
|
FROM report_record_spf s |
142
|
|
|
|
|
|
|
LEFT JOIN domain d ON s.domain_id=d.id |
143
|
|
|
|
|
|
|
WHERE s.report_record_id=? |
144
|
|
|
|
|
|
|
EO_SPF_ROW |
145
|
7
|
|
|
7
|
0
|
38
|
; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub select_row_dkim { |
150
|
|
|
|
|
|
|
return <<"EO_DKIM_ROW" |
151
|
|
|
|
|
|
|
SELECT d.domain AS domain, |
152
|
|
|
|
|
|
|
k.selector AS selector, |
153
|
|
|
|
|
|
|
k.result AS result, |
154
|
|
|
|
|
|
|
k.human_result AS human_result |
155
|
|
|
|
|
|
|
FROM report_record_dkim k |
156
|
|
|
|
|
|
|
LEFT JOIN domain d ON k.domain_id=d.id |
157
|
|
|
|
|
|
|
WHERE report_record_id=? |
158
|
|
|
|
|
|
|
EO_DKIM_ROW |
159
|
7
|
|
|
7
|
0
|
31
|
; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub select_row_reason { |
163
|
|
|
|
|
|
|
return <<"EO_ROW_QUERY" |
164
|
|
|
|
|
|
|
SELECT type,comment |
165
|
|
|
|
|
|
|
FROM report_record_reason |
166
|
|
|
|
|
|
|
WHERE report_record_id=? |
167
|
|
|
|
|
|
|
EO_ROW_QUERY |
168
|
7
|
|
|
7
|
0
|
33
|
; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub select_rr_query { |
172
|
|
|
|
|
|
|
return <<'EO_ROW_QUERY' |
173
|
|
|
|
|
|
|
SELECT rr.*, |
174
|
|
|
|
|
|
|
etd.domain AS envelope_to, |
175
|
|
|
|
|
|
|
efd.domain AS envelope_from, |
176
|
|
|
|
|
|
|
hfd.domain AS header_from |
177
|
|
|
|
|
|
|
FROM report_record rr |
178
|
|
|
|
|
|
|
LEFT JOIN domain etd ON etd.id=rr.envelope_to_did |
179
|
|
|
|
|
|
|
LEFT JOIN domain efd ON efd.id=rr.envelope_from_did |
180
|
|
|
|
|
|
|
LEFT JOIN domain hfd ON hfd.id=rr.header_from_did |
181
|
|
|
|
|
|
|
WHERE report_id = ? |
182
|
|
|
|
|
|
|
ORDER BY id ASC |
183
|
|
|
|
|
|
|
EO_ROW_QUERY |
184
|
6
|
|
|
6
|
0
|
29
|
; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub select_report_query { |
188
|
|
|
|
|
|
|
return <<'EO_REPORTS' |
189
|
|
|
|
|
|
|
SELECT r.id AS rid, |
190
|
|
|
|
|
|
|
r.uuid, |
191
|
|
|
|
|
|
|
r.begin AS begin, |
192
|
|
|
|
|
|
|
r.end AS end, |
193
|
|
|
|
|
|
|
a.org_name AS author, |
194
|
|
|
|
|
|
|
fd.domain AS from_domain |
195
|
|
|
|
|
|
|
FROM report r |
196
|
|
|
|
|
|
|
LEFT JOIN author a ON r.author_id=a.id |
197
|
|
|
|
|
|
|
LEFT JOIN domain fd ON r.from_domain_id=fd.id |
198
|
|
|
|
|
|
|
WHERE 1=1 |
199
|
|
|
|
|
|
|
EO_REPORTS |
200
|
10
|
|
|
10
|
0
|
29
|
; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub insert_error { |
204
|
2
|
|
|
2
|
0
|
7
|
my ( $self, $which ) = @_; |
205
|
2
|
100
|
|
|
|
12
|
if ( $which == 0 ) { |
206
|
1
|
|
|
|
|
5
|
return 'UPDATE report SET end=? WHERE id=?'; |
207
|
|
|
|
|
|
|
} else { |
208
|
1
|
|
|
|
|
7
|
return 'INSERT INTO report_error (report_id, error) VALUES (?,?)'; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub insert_rr_reason { |
213
|
8
|
|
|
8
|
0
|
62
|
return 'INSERT INTO report_record_reason (report_record_id, type, comment) VALUES (?,?,?)' |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub insert_rr_dkim { |
217
|
8
|
|
|
8
|
0
|
27
|
my ( $self, $fields ) = @_; |
218
|
8
|
|
|
|
|
39
|
my $fields_str = join ', ', @$fields; |
219
|
|
|
|
|
|
|
return <<"EO_DKIM" |
220
|
|
|
|
|
|
|
INSERT INTO report_record_dkim |
221
|
|
|
|
|
|
|
(report_record_id, $fields_str) |
222
|
|
|
|
|
|
|
VALUES (??) |
223
|
|
|
|
|
|
|
EO_DKIM |
224
|
8
|
|
|
|
|
43
|
; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub insert_rr_spf { |
228
|
13
|
|
|
13
|
0
|
44
|
my ( $self, $fields ) = @_; |
229
|
13
|
|
|
|
|
60
|
my $fields_str = join ', ', @$fields; |
230
|
13
|
|
|
|
|
78
|
return "INSERT INTO report_record_spf (report_record_id, $fields_str) VALUES(??)"; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub insert_rr { |
234
|
|
|
|
|
|
|
return <<'EO_ROW_INSERT' |
235
|
|
|
|
|
|
|
INSERT INTO report_record |
236
|
|
|
|
|
|
|
(report_id, source_ip, count, header_from_did, envelope_to_did, envelope_from_did, |
237
|
|
|
|
|
|
|
disposition, dkim, spf) |
238
|
|
|
|
|
|
|
VALUES (??) |
239
|
|
|
|
|
|
|
EO_ROW_INSERT |
240
|
6
|
|
|
6
|
0
|
21
|
; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub insert_policy_published { |
244
|
|
|
|
|
|
|
return <<"EO_RPP" |
245
|
|
|
|
|
|
|
INSERT INTO report_policy_published |
246
|
|
|
|
|
|
|
(report_id, adkim, aspf, p, sp, pct, rua) |
247
|
|
|
|
|
|
|
VALUES (??) |
248
|
|
|
|
|
|
|
EO_RPP |
249
|
10
|
|
|
10
|
0
|
37
|
; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
sub select_from { |
253
|
9
|
|
|
9
|
0
|
27
|
my ($self, $columns, $table) = @_; |
254
|
9
|
|
|
|
|
33
|
my $colStr = join( ', ', @$columns ); |
255
|
9
|
|
|
|
|
46
|
return "SELECT $colStr FROM $table WHERE 1=1"; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub insert_into { |
259
|
8
|
|
|
8
|
0
|
35
|
my ($self, $table, $cols) = @_; |
260
|
8
|
|
|
|
|
32
|
my $columns = join ', ', @$cols; |
261
|
8
|
|
|
|
|
68
|
return "INSERT INTO $table ($columns) VALUES (??)"; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub update { |
265
|
0
|
|
|
0
|
0
|
0
|
my ($self, $table, $cols) = @_; |
266
|
0
|
|
|
|
|
0
|
my $columns = join( ' = ?, ') . ' = ?'; |
267
|
0
|
|
|
|
|
0
|
return "UPDATE $table SET $columns WHERE 1=1"; |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub replace_into { |
271
|
1
|
|
|
1
|
0
|
5
|
my ($self, $table, $cols) = @_; |
272
|
1
|
|
|
|
|
6
|
my $columns = join ', ', @$cols; |
273
|
1
|
|
|
|
|
9
|
return "REPLACE INTO $table ($columns) VALUES (??)"; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub delete_from { |
277
|
5
|
|
|
5
|
0
|
29
|
my ($self, $table) = @_; |
278
|
5
|
|
|
|
|
25
|
return "DELETE FROM $table WHERE 1=1"; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
__END__ |