line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Lazy::DB; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1197
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use DBI; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
41
|
|
6
|
1
|
|
|
1
|
|
5
|
use CGI::Lazy::Globals; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
106
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1186
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
sub config { |
11
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
0
|
return $self->q->config; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
sub dbh { |
18
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
return $self->{_dbh}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
sub do { #run query with no return value |
25
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
my $query = shift; |
27
|
0
|
|
|
|
|
0
|
my @bindvars = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
my $dbh = $self->dbh; |
30
|
0
|
|
|
|
|
0
|
my $sth; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
eval { |
33
|
0
|
|
|
|
|
0
|
$sth = $dbh->prepare($query); |
34
|
0
|
0
|
|
|
|
0
|
$sth->execute(@bindvars) or carp $!; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
0
|
if ($@) { |
38
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->dbError; |
39
|
0
|
|
|
|
|
0
|
return; |
40
|
|
|
|
|
|
|
} else { |
41
|
0
|
|
|
|
|
0
|
return 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
46
|
|
|
|
|
|
|
sub get { #run query returning single value |
47
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
48
|
0
|
|
|
|
|
0
|
my $query = shift; |
49
|
0
|
|
|
|
|
0
|
my @bindvars = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
0
|
if (ref $bindvars[0]) { |
52
|
0
|
0
|
|
|
|
0
|
if (ref $bindvars[0] eq 'ARRAY') { |
53
|
0
|
|
|
|
|
0
|
@bindvars = @{$bindvars[0]}; |
|
0
|
|
|
|
|
0
|
|
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->getWithOtherThanArray; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my $dbh = $self->dbh; |
60
|
0
|
|
|
|
|
0
|
my $sth; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
eval { |
63
|
0
|
|
|
|
|
0
|
$sth = $dbh->prepare($query); |
64
|
0
|
|
|
|
|
0
|
$sth->execute(@bindvars); |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
0
|
if ($@) { |
68
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->dbError; |
69
|
0
|
|
|
|
|
0
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
my @results = $sth->fetchrow_array; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
return $results[0]; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
78
|
|
|
|
|
|
|
sub getarray { #run query with return value |
79
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
80
|
0
|
|
|
|
|
0
|
my $query = shift; |
81
|
0
|
|
|
|
|
0
|
my @bindvars = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
0
|
if (ref $bindvars[0]) { |
84
|
0
|
0
|
|
|
|
0
|
if (ref $bindvars[0] eq 'ARRAY') { |
85
|
0
|
|
|
|
|
0
|
@bindvars = @{$bindvars[0]}; |
|
0
|
|
|
|
|
0
|
|
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->getWithOtherThanArray; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
my $dbh = $self->dbh; |
92
|
0
|
|
|
|
|
0
|
my $sth; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
eval { |
95
|
0
|
|
|
|
|
0
|
$sth = $dbh->prepare($query); |
96
|
0
|
|
|
|
|
0
|
$sth->execute(@bindvars); |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
0
|
if ($@) { |
100
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->dbError; |
101
|
0
|
|
|
|
|
0
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
return $sth->fetchall_arrayref; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
109
|
|
|
|
|
|
|
sub gethash { #run query with return value |
110
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
111
|
0
|
|
|
|
|
0
|
my $query = shift; |
112
|
0
|
|
|
|
|
0
|
my $key = shift; |
113
|
0
|
|
|
|
|
0
|
my @bindvars = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
my $dbh = $self->dbh; |
116
|
0
|
|
|
|
|
0
|
my $sth; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
eval { |
119
|
0
|
|
|
|
|
0
|
$sth = $dbh->prepare($query); |
120
|
0
|
|
|
|
|
0
|
$sth->execute(@bindvars); |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
0
|
if ($@) { |
124
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->dbError; |
125
|
0
|
|
|
|
|
0
|
return; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
0
|
return $sth->fetchall_hashref($key); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
132
|
|
|
|
|
|
|
sub gethashlist { #run query with return value |
133
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
134
|
0
|
|
|
|
|
0
|
my $query = shift; |
135
|
0
|
|
|
|
|
0
|
my @bindvars = @_; |
136
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
0
|
if (ref $bindvars[0]) { |
138
|
0
|
0
|
|
|
|
0
|
if (ref $bindvars[0] eq 'ARRAY') { |
139
|
0
|
|
|
|
|
0
|
@bindvars = @{$bindvars[0]}; |
|
0
|
|
|
|
|
0
|
|
140
|
|
|
|
|
|
|
} else { |
141
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->getWithOtherThanArray; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
0
|
my $dbh = $self->dbh; |
146
|
0
|
|
|
|
|
0
|
my $sth; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
0
|
eval { |
149
|
0
|
|
|
|
|
0
|
$sth = $dbh->prepare($query); |
150
|
0
|
|
|
|
|
0
|
$sth->execute(@bindvars); |
151
|
|
|
|
|
|
|
}; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
0
|
if ($@) { |
154
|
0
|
|
|
|
|
0
|
$self->q->errorHandler->dbError; |
155
|
0
|
|
|
|
|
0
|
return; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
my $results = []; |
159
|
0
|
|
|
|
|
0
|
while (my $row = $sth->fetchrow_hashref) { |
160
|
0
|
|
|
|
|
0
|
push @$results, $row; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
0
|
return $results; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
167
|
|
|
|
|
|
|
sub new { |
168
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
169
|
1
|
|
|
|
|
3
|
my $q = shift; |
170
|
|
|
|
|
|
|
|
171
|
1
|
|
|
|
|
6
|
my $self = bless {_q => $q}, $class; |
172
|
|
|
|
|
|
|
|
173
|
1
|
50
|
|
|
|
5
|
if ($q->plugin->dbh) { |
174
|
0
|
|
|
|
|
0
|
my @list = split ':', $self->config->plugins->{dbh}->{dbDatasource}; |
175
|
0
|
|
|
|
|
0
|
my $type = $list[1]; |
176
|
0
|
|
|
|
|
0
|
$self->{_type} = $type; |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
0
|
eval { |
179
|
0
|
0
|
|
|
|
0
|
$self->{_dbh} = DBI->connect( |
180
|
|
|
|
|
|
|
$self->config->plugins->{dbh}->{dbDatasource}, |
181
|
|
|
|
|
|
|
$self->config->plugins->{dbh}->{dbUser}, |
182
|
|
|
|
|
|
|
$self->config->plugins->{dbh}->{dbPasswd}, |
183
|
|
|
|
|
|
|
$self->config->plugins->{dbh}->{dbArgs} |
184
|
|
|
|
|
|
|
) or die $!; |
185
|
|
|
|
|
|
|
}; |
186
|
|
|
|
|
|
|
|
187
|
0
|
0
|
|
|
|
0
|
if ($@) { |
188
|
0
|
|
|
|
|
0
|
$q->errorHandler->dbConnectFailed; |
189
|
0
|
|
|
|
|
0
|
exit; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} else { #using dbh from somewhere else |
192
|
1
|
50
|
|
|
|
4
|
if ($q->vars->{dbh} ) { #if a dbh is specified on cgi creation use that one |
|
|
50
|
|
|
|
|
|
193
|
0
|
|
|
|
|
0
|
$self->{_dbh} = $q->vars->{dbh}; |
194
|
|
|
|
|
|
|
} elsif ($q->config->dbhVar){ |
195
|
|
|
|
|
|
|
{ |
196
|
1
|
|
|
1
|
|
9
|
no strict 'vars'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
|
0
|
|
|
|
|
0
|
|
197
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
336
|
|
198
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
0
|
if ($self->config->plugins->{mod_perl}) { |
200
|
0
|
|
|
|
|
0
|
my $handler = $self->config->plugins->{mod_perl}->{PerlHandler}; |
201
|
0
|
|
|
|
|
0
|
require Apache2::RequestUtil; |
202
|
0
|
|
|
|
|
0
|
my $r = Apache2::RequestUtil->request(); |
203
|
0
|
|
|
|
|
0
|
my $mp = "$handler"->new($r); |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
0
|
$self->{_dbh} = ${$mp->make_namespace."::".$self->config->dbhVar}; |
|
0
|
|
|
|
|
0
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
} else { |
208
|
0
|
|
|
|
|
0
|
$self->{_dbh} = $main::{$self->config->dbhVar}; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} else { |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
5
|
return $self; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
221
|
|
|
|
|
|
|
sub q { |
222
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return $self->{_q}; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
228
|
|
|
|
|
|
|
sub recordset { |
229
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
230
|
0
|
|
|
|
|
|
my $args = shift; |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
|
return CGI::Lazy::DB::RecordSet->new($self, $args); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
#--------------------------------------------------------------------------------------- |
237
|
|
|
|
|
|
|
sub type { |
238
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
239
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
return $self->{_dbh}->{Driver}->{Name}; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
1 |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
__END__ |