| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Apache::DBI; |
|
3
|
1
|
|
|
1
|
|
15
|
use strict; |
|
|
1
|
|
|
|
|
14
|
|
|
|
1
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
50
|
33
|
|
|
24
|
use constant MP2 => (exists $ENV{MOD_PERL_API_VERSION} && |
|
6
|
1
|
|
|
1
|
|
15
|
$ENV{MOD_PERL_API_VERSION} == 2) ? 1 : 0; |
|
|
1
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
BEGIN { |
|
9
|
1
|
50
|
33
|
1
|
|
50
|
if (MP2) { |
|
|
|
|
33
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require mod_perl2; |
|
11
|
|
|
|
|
|
|
require Apache2::Module; |
|
12
|
|
|
|
|
|
|
require Apache2::ServerUtil; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
elsif (defined $modperl::VERSION && $modperl::VERSION > 1 && |
|
15
|
|
|
|
|
|
|
$modperl::VERSION < 1.99) { |
|
16
|
0
|
|
|
|
|
0
|
require Apache; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
} |
|
19
|
1
|
|
|
1
|
|
29
|
use DBI (); |
|
|
1
|
|
|
|
|
2347
|
|
|
|
1
|
|
|
|
|
11
|
|
|
20
|
1
|
|
|
1
|
|
21
|
use Carp (); |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
9
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
require_version DBI 1.00; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$Apache::DBI::VERSION = '1.05'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$Apache::DBI::DEBUG = 0; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %Connected; |
|
32
|
|
|
|
|
|
|
my @ChildConnect; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %Rollback; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %PingTimeOut; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my %LastPingTime; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $TaintInOut = ($DBI::VERSION >= 1.31) ? 1 : 0; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub debug { |
|
46
|
0
|
0
|
|
0
|
0
|
|
print STDERR "$_[1]\n" if $Apache::DBI::DEBUG >= $_[0]; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub connect_on_init { |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
0
|
|
if (MP2) { |
|
57
|
|
|
|
|
|
|
if (!@ChildConnect) { |
|
58
|
|
|
|
|
|
|
my $s = Apache2::ServerUtil->server; |
|
59
|
|
|
|
|
|
|
$s->push_handlers(PerlChildInitHandler => \&childinit); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else { |
|
63
|
0
|
0
|
0
|
|
|
|
Carp::carp("Apache.pm was not loaded\n") |
|
64
|
|
|
|
|
|
|
and return unless $INC{'Apache.pm'}; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
if (!@ChildConnect and Apache->can('push_handlers')) { |
|
67
|
0
|
|
|
|
|
|
Apache->push_handlers(PerlChildInitHandler => \&childinit); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
push @ChildConnect, [@_]; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub setPingTimeOut { |
|
79
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
80
|
0
|
|
|
|
|
|
my $data_source = shift; |
|
81
|
0
|
|
|
|
|
|
my $timeout = shift; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
0
|
|
|
|
if ($data_source =~ /dbi:\w+:.*/ and $timeout =~ /\-*\d+/) { |
|
85
|
0
|
|
|
|
|
|
$PingTimeOut{$data_source} = $timeout; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub connect { |
|
91
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
92
|
0
|
0
|
|
|
|
|
unshift @_, $class if ref $class; |
|
93
|
0
|
|
|
|
|
|
my $drh = shift; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
my @args = map { defined $_ ? $_ : "" } @_; |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $dsn = "dbi:$drh->{Name}:$args[0]"; |
|
97
|
0
|
|
|
|
|
|
my $prefix = "$$ Apache::DBI "; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $Idx = join $;, $args[0], $args[1], $args[2]; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
0
|
0
|
|
|
|
if (3 == $#args and ref $args[3] eq "HASH") { |
|
|
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
map { |
|
107
|
0
|
|
|
|
|
|
$Idx .= "$;$_=" . |
|
108
|
|
|
|
|
|
|
(defined $args[3]->{$_} |
|
109
|
|
|
|
|
|
|
? $args[3]->{$_} |
|
110
|
|
|
|
|
|
|
: '') |
|
111
|
0
|
|
|
|
|
|
} sort keys %{$args[3]}; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
elsif (3 == $#args) { |
|
114
|
0
|
|
|
|
|
|
pop @args; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
if (MP2) { |
|
123
|
|
|
|
|
|
|
require Apache2::ServerUtil; |
|
124
|
|
|
|
|
|
|
if (Apache2::ServerUtil::restart_count() == 1) { |
|
125
|
|
|
|
|
|
|
debug(2, "$prefix skipping connection during server startup, read the docu !!"); |
|
126
|
|
|
|
|
|
|
return $drh->connect(@args); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
else { |
|
130
|
0
|
0
|
0
|
|
|
|
if ($Apache::ServerStarting and $Apache::ServerStarting == 1) { |
|
131
|
0
|
|
|
|
|
|
debug(2, "$prefix skipping connection during server startup, read the docu !!"); |
|
132
|
0
|
|
|
|
|
|
return $drh->connect(@args); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
0
|
0
|
|
|
|
if (!$Rollback{$Idx} and Apache->can('push_handlers')) { |
|
141
|
0
|
|
|
|
|
|
debug(2, "$prefix push PerlCleanupHandler"); |
|
142
|
0
|
|
|
|
|
|
if (MP2) { |
|
143
|
|
|
|
|
|
|
my $s = Apache2::ServerUtil->server; |
|
144
|
0
|
|
|
0
|
|
|
$s->push_handlers("PerlCleanupHandler", sub { cleanup($Idx) }); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
else { |
|
147
|
0
|
|
|
0
|
|
|
Apache->push_handlers("PerlCleanupHandler", sub { cleanup($Idx) }); |
|
|
0
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
$Rollback{$Idx} = 1; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
|
$PingTimeOut{$dsn} = 0 unless $PingTimeOut{$dsn}; |
|
156
|
0
|
0
|
|
|
|
|
$LastPingTime{$dsn} = 0 unless $LastPingTime{$dsn}; |
|
157
|
0
|
|
|
|
|
|
my $now = time; |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
0
|
0
|
|
|
|
my $needping = ($PingTimeOut{$dsn} == 0 or |
|
|
|
|
0
|
|
|
|
|
|
160
|
|
|
|
|
|
|
($PingTimeOut{$dsn} > 0 and |
|
161
|
|
|
|
|
|
|
$now - $LastPingTime{$dsn} > $PingTimeOut{$dsn}) |
|
162
|
|
|
|
|
|
|
) ? 1 : 0; |
|
163
|
0
|
0
|
|
|
|
|
debug(2, "$prefix need ping: " . ($needping == 1 ? "yes" : "no")); |
|
164
|
0
|
|
|
|
|
|
$LastPingTime{$dsn} = $now; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
0
|
0
|
|
|
|
if ($Connected{$Idx} and (!$needping or eval{$Connected{$Idx}->ping})) { |
|
|
0
|
|
0
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
debug(2, "$prefix already connected to '$Idx'"); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
&reset_startup_state($Idx); |
|
177
|
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return (bless $Connected{$Idx}, 'Apache::DBI::db'); |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
delete $Connected{$Idx}; |
|
184
|
0
|
|
|
|
|
|
$Connected{$Idx} = $drh->connect(@args); |
|
185
|
0
|
0
|
|
|
|
|
return undef if !$Connected{$Idx}; |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
set_startup_state($Idx); |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
debug(1, "$prefix new connect to '$Idx'"); |
|
192
|
0
|
|
|
|
|
|
return (bless $Connected{$Idx}, 'Apache::DBI::db'); |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub childinit { |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
|
|
0
|
0
|
|
my $prefix = "$$ Apache::DBI "; |
|
200
|
0
|
|
|
|
|
|
debug(2, "$prefix PerlChildInitHandler"); |
|
201
|
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
%Connected = () if MP2; |
|
203
|
|
|
|
|
|
|
|
|
204
|
0
|
0
|
|
|
|
|
if (@ChildConnect) { |
|
205
|
0
|
|
|
|
|
|
for my $aref (@ChildConnect) { |
|
206
|
0
|
|
|
|
|
|
shift @$aref; |
|
207
|
0
|
|
|
|
|
|
DBI->connect(@$aref); |
|
208
|
0
|
|
|
|
|
|
$LastPingTime{@$aref[0]} = time; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
1; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub cleanup { |
|
220
|
0
|
|
|
0
|
0
|
|
my $Idx = shift; |
|
221
|
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my $prefix = "$$ Apache::DBI "; |
|
223
|
0
|
|
|
|
|
|
debug(2, "$prefix PerlCleanupHandler"); |
|
224
|
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
my $dbh = $Connected{$Idx}; |
|
226
|
0
|
0
|
0
|
|
|
|
if ($Rollback{$Idx} |
|
|
0
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
227
|
|
|
|
|
|
|
and $dbh |
|
228
|
|
|
|
|
|
|
and $dbh->{Active} |
|
229
|
|
|
|
|
|
|
and !$dbh->{AutoCommit} |
|
230
|
|
|
|
|
|
|
and eval {$dbh->rollback}) { |
|
231
|
0
|
|
|
|
|
|
debug (2, "$prefix PerlCleanupHandler rollback for '$Idx'"); |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
delete $Rollback{$Idx}; |
|
235
|
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
1; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
my @attrs = qw( |
|
242
|
|
|
|
|
|
|
AutoCommit Warn CompatMode InactiveDestroy |
|
243
|
|
|
|
|
|
|
PrintError RaiseError HandleError |
|
244
|
|
|
|
|
|
|
ShowErrorStatement TraceLevel FetchHashKeyName |
|
245
|
|
|
|
|
|
|
ChopBlanks LongReadLen LongTruncOk |
|
246
|
|
|
|
|
|
|
Taint Profile |
|
247
|
|
|
|
|
|
|
); |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub set_startup_state { |
|
250
|
0
|
|
|
0
|
0
|
|
my $Idx = shift; |
|
251
|
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
|
foreach my $key (@attrs) { |
|
253
|
0
|
|
|
|
|
|
$Connected{$Idx}->{private_Apache_DBI}{$key} = |
|
254
|
|
|
|
|
|
|
$Connected{$Idx}->{$key}; |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
0
|
0
|
|
|
|
|
if ($TaintInOut) { |
|
258
|
0
|
|
|
|
|
|
foreach my $key qw{ TaintIn TaintOut } { |
|
259
|
0
|
|
|
|
|
|
$Connected{$Idx}->{private_Apache_DBI}{$key} = |
|
260
|
|
|
|
|
|
|
$Connected{$Idx}->{$key}; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
1; |
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub reset_startup_state { |
|
269
|
0
|
|
|
0
|
0
|
|
my $Idx = shift; |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
$Connected{$Idx}->{Active} |
|
273
|
|
|
|
|
|
|
and !$Connected{$Idx}->{AutoCommit} |
|
274
|
0
|
0
|
0
|
|
|
|
and eval {$Connected{$Idx}->rollback}; |
|
275
|
|
|
|
|
|
|
|
|
276
|
0
|
|
|
|
|
|
foreach my $key (@attrs) { |
|
277
|
0
|
|
|
|
|
|
$Connected{$Idx}->{$key} = |
|
278
|
|
|
|
|
|
|
$Connected{$Idx}->{private_Apache_DBI}{$key}; |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
|
|
281
|
0
|
0
|
|
|
|
|
if ($TaintInOut) { |
|
282
|
0
|
|
|
|
|
|
foreach my $key qw{ TaintIn TaintOut } { |
|
283
|
0
|
|
|
|
|
|
$Connected{$Idx}->{$key} = |
|
284
|
|
|
|
|
|
|
$Connected{$Idx}->{private_Apache_DBI}{$key}; |
|
285
|
|
|
|
|
|
|
} |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
|
1; |
|
289
|
|
|
|
|
|
|
} |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
|
|
294
|
0
|
|
|
0
|
0
|
|
sub all_handlers { return \%Connected } |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
@Apache::DBI::st::ISA = ('DBI::st'); |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
{ |
|
301
|
|
|
|
|
|
|
package Apache::DBI::db; |
|
302
|
1
|
|
|
1
|
|
26
|
no strict; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
20
|
|
|
303
|
|
|
|
|
|
|
@ISA=qw(DBI::db); |
|
304
|
1
|
|
|
1
|
|
15
|
use strict; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
13
|
|
|
305
|
|
|
|
|
|
|
sub disconnect { |
|
306
|
0
|
|
|
0
|
|
|
my $prefix = "$$ Apache::DBI "; |
|
307
|
0
|
|
|
|
|
|
Apache::DBI::debug(2, "$prefix disconnect (overloaded)"); |
|
308
|
0
|
|
|
|
|
|
1; |
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
; |
|
311
|
|
|
|
|
|
|
} |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub status_function { |
|
315
|
0
|
|
|
0
|
0
|
|
my($r, $q) = @_; |
|
316
|
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
|
my(@s) = qw(<TABLE><TR><TD>Datasource</TD><TD>Username</TD></TR>); |
|
318
|
0
|
|
|
|
|
|
for (keys %Connected) { |
|
319
|
0
|
|
|
|
|
|
push @s, '<TR><TD>', |
|
320
|
|
|
|
|
|
|
join('</TD><TD>', |
|
321
|
|
|
|
|
|
|
(split($;, $_))[0,1]), "</TD></TR>\n"; |
|
322
|
|
|
|
|
|
|
} |
|
323
|
0
|
|
|
|
|
|
push @s, '</TABLE>'; |
|
324
|
|
|
|
|
|
|
|
|
325
|
0
|
|
|
|
|
|
\@s; |
|
326
|
|
|
|