line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Free::DB; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
65
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
185
|
|
4
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
124
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
31
|
use File::Glob; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
329
|
|
7
|
6
|
|
|
6
|
|
35
|
use File::Basename; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
387
|
|
8
|
6
|
|
|
6
|
|
7481
|
use DBI; |
|
6
|
|
|
|
|
85955
|
|
|
6
|
|
|
|
|
389
|
|
9
|
6
|
|
|
6
|
|
63
|
use File::Spec; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
158
|
|
10
|
6
|
|
|
6
|
|
2103
|
use File::pfopen 0.02; |
|
6
|
|
|
|
|
2796
|
|
|
6
|
|
|
|
|
254
|
|
11
|
6
|
|
|
6
|
|
2775
|
use File::Temp; |
|
6
|
|
|
|
|
90566
|
|
|
6
|
|
|
|
|
449
|
|
12
|
6
|
|
|
6
|
|
1495
|
use Gzip::Faster; |
|
6
|
|
|
|
|
6929
|
|
|
6
|
|
|
|
|
464
|
|
13
|
6
|
|
|
6
|
|
2304
|
use DBD::SQLite::Constants qw/:file_open/; # For SQLITE_OPEN_READONLY |
|
6
|
|
|
|
|
51810
|
|
|
6
|
|
|
|
|
12945
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @databases; |
16
|
|
|
|
|
|
|
our $directory; |
17
|
|
|
|
|
|
|
our $logger; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
6
|
|
|
6
|
0
|
1730
|
my $proto = shift; |
21
|
6
|
50
|
|
|
|
29
|
my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
22
|
|
|
|
|
|
|
|
23
|
6
|
|
33
|
|
|
30
|
my $class = ref($proto) || $proto; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# init(\%args); |
26
|
|
|
|
|
|
|
|
27
|
6
|
|
66
|
|
|
86
|
return bless { logger => $args{'logger'} || $logger, directory => $args{'directory'} || $directory }, $class; |
|
|
|
33
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Can also be run as a class level Geo::Coder::Free::DB::init(directory => '../databases') |
31
|
|
|
|
|
|
|
sub init { |
32
|
5
|
50
|
|
5
|
0
|
239
|
my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
33
|
|
|
|
|
|
|
|
34
|
5
|
|
33
|
|
|
39
|
$directory ||= $args{'directory'}; |
35
|
5
|
|
33
|
|
|
26
|
$logger ||= $args{'logger'}; |
36
|
5
|
50
|
|
|
|
14
|
if($args{'databases'}) { |
37
|
0
|
|
|
|
|
0
|
@databases = $args{'databases'}; |
38
|
|
|
|
|
|
|
} |
39
|
5
|
50
|
|
|
|
22
|
throw Error::Simple('directory not given') unless($directory); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub set_logger { |
43
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
my %args; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
0
|
if(ref($_[0]) eq 'HASH') { |
|
|
0
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
%args = %{$_[0]}; |
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
} elsif(scalar(@_) % 2 == 0) { |
50
|
0
|
|
|
|
|
0
|
%args = @_; |
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
0
|
$args{'logger'} = shift; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
$self->{'logger'} = $args{'logger'}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _open { |
59
|
7
|
|
|
7
|
|
18
|
my $self = shift; |
60
|
|
|
|
|
|
|
my %args = ( |
61
|
|
|
|
|
|
|
sep_char => '!', |
62
|
7
|
50
|
|
|
|
45
|
((ref($_[0]) eq 'HASH') ? %{$_[0]} : @_) |
|
0
|
|
|
|
|
0
|
|
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
7
|
|
|
|
|
18
|
my $table = ref($self); |
66
|
7
|
|
|
|
|
32
|
$table =~ s/.*:://; |
67
|
|
|
|
|
|
|
|
68
|
7
|
100
|
|
|
|
26
|
if($self->{'logger'}) { |
69
|
4
|
|
|
|
|
23
|
$self->{'logger'}->trace("_open $table"); |
70
|
|
|
|
|
|
|
} |
71
|
7
|
100
|
|
|
|
48
|
return if($self->{$table}); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Read in the database |
74
|
6
|
|
|
|
|
14
|
my $dbh; |
75
|
|
|
|
|
|
|
|
76
|
6
|
|
33
|
|
|
20
|
my $directory = $self->{'directory'} || $directory; |
77
|
6
|
|
|
|
|
107
|
my $slurp_file = File::Spec->catfile($directory, "$table.sql"); |
78
|
|
|
|
|
|
|
|
79
|
6
|
100
|
|
|
|
231
|
if(-r $slurp_file) { |
80
|
2
|
|
|
|
|
29
|
$dbh = DBI->connect("dbi:SQLite:dbname=$slurp_file", undef, undef, { |
81
|
|
|
|
|
|
|
sqlite_open_flags => SQLITE_OPEN_READONLY, |
82
|
|
|
|
|
|
|
}); |
83
|
2
|
100
|
|
|
|
3547
|
if($self->{'logger'}) { |
84
|
1
|
|
|
|
|
8
|
$self->{'logger'}->debug("read in $table from SQLite $slurp_file"); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} else { |
87
|
4
|
|
|
|
|
6
|
my $fin; |
88
|
4
|
|
|
|
|
25
|
($fin, $slurp_file) = File::pfopen::pfopen($directory, $table, 'csv.gz:db.gz'); |
89
|
4
|
50
|
33
|
|
|
301
|
if(defined($slurp_file) && (-r $slurp_file)) { |
90
|
0
|
|
|
|
|
0
|
$fin = File::Temp->new(SUFFIX => '.csv', UNLINK => 0); |
91
|
0
|
|
|
|
|
0
|
print $fin gunzip_file($slurp_file); |
92
|
0
|
|
|
|
|
0
|
$slurp_file = $fin->filename(); |
93
|
0
|
|
|
|
|
0
|
$self->{'temp'} = $slurp_file; |
94
|
|
|
|
|
|
|
} else { |
95
|
4
|
|
|
|
|
16
|
($fin, $slurp_file) = File::pfopen::pfopen($directory, $table, 'csv:db'); |
96
|
|
|
|
|
|
|
} |
97
|
4
|
50
|
33
|
|
|
455
|
if(defined($slurp_file) && (-r $slurp_file)) { |
98
|
4
|
|
|
|
|
22
|
close($fin); |
99
|
4
|
|
|
|
|
14
|
my $sep_char = $args{'sep_char'}; |
100
|
4
|
50
|
|
|
|
13
|
if($args{'column_names'}) { |
101
|
|
|
|
|
|
|
$dbh = DBI->connect("dbi:CSV:csv_sep_char=$sep_char", undef, undef, |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
csv_tables => { |
104
|
|
|
|
|
|
|
$table => { |
105
|
4
|
|
|
|
|
56
|
col_names => $args{'column_names'}, |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} else { |
111
|
0
|
|
|
|
|
0
|
$dbh = DBI->connect("dbi:CSV:csv_sep_char=$sep_char"); |
112
|
|
|
|
|
|
|
} |
113
|
4
|
|
|
|
|
456476
|
$dbh->{'RaiseError'} = 1; |
114
|
|
|
|
|
|
|
|
115
|
4
|
100
|
|
|
|
68
|
if($self->{'logger'}) { |
116
|
2
|
|
|
|
|
22
|
$self->{'logger'}->debug("read in $table from CSV $slurp_file"); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
42
|
my %options = ( |
120
|
|
|
|
|
|
|
allow_loose_quotes => 1, |
121
|
|
|
|
|
|
|
blank_is_undef => 1, |
122
|
|
|
|
|
|
|
empty_is_undef => 1, |
123
|
|
|
|
|
|
|
binary => 1, |
124
|
|
|
|
|
|
|
f_file => $slurp_file, |
125
|
|
|
|
|
|
|
escape_char => '\\', |
126
|
|
|
|
|
|
|
sep_char => $sep_char, |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
|
129
|
4
|
|
|
|
|
39
|
$dbh->{csv_tables}->{$table} = \%options; |
130
|
|
|
|
|
|
|
# delete $options{f_file}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# require Text::CSV::Slurp; |
133
|
|
|
|
|
|
|
# Text::CSV::Slurp->import(); |
134
|
|
|
|
|
|
|
# $self->{'data'} = Text::CSV::Slurp->load(file => $slurp_file, %options); |
135
|
|
|
|
|
|
|
|
136
|
4
|
|
|
|
|
11009
|
if(0) { |
137
|
|
|
|
|
|
|
require Text::xSV::Slurp; |
138
|
|
|
|
|
|
|
Text::xSV::Slurp->import(); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
my @data = @{xsv_slurp( |
141
|
|
|
|
|
|
|
shape => 'aoh', |
142
|
|
|
|
|
|
|
text_csv => { |
143
|
|
|
|
|
|
|
sep_char => $sep_char, |
144
|
|
|
|
|
|
|
allow_loose_quotes => 1, |
145
|
|
|
|
|
|
|
blank_is_undef => 1, |
146
|
|
|
|
|
|
|
empty_is_undef => 1, |
147
|
|
|
|
|
|
|
binary => 1, |
148
|
|
|
|
|
|
|
escape_char => '\\', |
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
# string => \join('', grep(!/^\s*(#|$)/, )) |
151
|
|
|
|
|
|
|
file => $slurp_file |
152
|
|
|
|
|
|
|
)}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Don't use blank lines or comments |
155
|
|
|
|
|
|
|
@data = grep { $_->{'entry'} !~ /^#/ } grep { defined($_->{'entry'}) } @data; |
156
|
|
|
|
|
|
|
# $self->{'data'} = @data; |
157
|
|
|
|
|
|
|
my $i = 0; |
158
|
|
|
|
|
|
|
$self->{'data'} = (); |
159
|
|
|
|
|
|
|
foreach my $d(@data) { |
160
|
|
|
|
|
|
|
$self->{'data'}[$i++] = $d; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} else { |
164
|
0
|
|
|
|
|
0
|
$slurp_file = File::Spec->catfile($directory, "$table.xml"); |
165
|
0
|
0
|
|
|
|
0
|
if(-r $slurp_file) { |
166
|
|
|
|
|
|
|
# You'll need to install XML::Twig and |
167
|
|
|
|
|
|
|
# AnyData::Format::XML |
168
|
|
|
|
|
|
|
# The DBD::AnyData in CPAN doesn't work - grab a |
169
|
|
|
|
|
|
|
# patched version from https://github.com/nigelhorne/DBD-AnyData.git |
170
|
0
|
|
|
|
|
0
|
$dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); |
171
|
0
|
|
|
|
|
0
|
$dbh->{'RaiseError'} = 1; |
172
|
0
|
0
|
|
|
|
0
|
if($self->{'logger'}) { |
173
|
0
|
|
|
|
|
0
|
$self->{'logger'}->debug("read in $table from XML $slurp_file"); |
174
|
|
|
|
|
|
|
} |
175
|
0
|
|
|
|
|
0
|
$dbh->func($table, 'XML', $slurp_file, 'ad_import'); |
176
|
|
|
|
|
|
|
} else { |
177
|
0
|
|
|
|
|
0
|
throw Error::Simple("Can't open $directory/$table"); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
6
|
|
|
|
|
28
|
push @databases, $table; |
183
|
|
|
|
|
|
|
|
184
|
6
|
|
|
|
|
18
|
$self->{$table} = $dbh; |
185
|
6
|
|
|
|
|
118
|
my @statb = stat($slurp_file); |
186
|
6
|
|
|
|
|
35
|
$self->{'_updated'} = $statb[9]; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# Returns a reference to an array of hash references of all the data meeting |
190
|
|
|
|
|
|
|
# the given criteria |
191
|
|
|
|
|
|
|
sub selectall_hashref { |
192
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
193
|
1
|
50
|
|
|
|
5
|
my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
194
|
|
|
|
|
|
|
|
195
|
1
|
|
|
|
|
3
|
my $table = ref($self); |
196
|
1
|
|
|
|
|
6
|
$table =~ s/.*:://; |
197
|
|
|
|
|
|
|
|
198
|
1
|
50
|
|
|
|
10
|
$self->_open() if(!$self->{$table}); |
199
|
|
|
|
|
|
|
|
200
|
1
|
0
|
33
|
|
|
5
|
if((scalar(keys %params) == 0) && $self->{'data'}) { |
201
|
0
|
0
|
|
|
|
0
|
if($self->{'logger'}) { |
202
|
0
|
|
|
|
|
0
|
$self->{'logger'}->trace("$table: selectall_hashref fast track return"); |
203
|
|
|
|
|
|
|
} |
204
|
0
|
|
|
|
|
0
|
return $self->{'data'}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
1
|
|
|
|
|
3
|
my $query = "SELECT * FROM $table"; |
208
|
1
|
|
|
|
|
2
|
my @args; |
209
|
1
|
|
|
|
|
3
|
foreach my $c1(keys(%params)) { |
210
|
1
|
50
|
|
|
|
4
|
if(scalar(@args) == 0) { |
211
|
1
|
|
|
|
|
3
|
$query .= ' WHERE'; |
212
|
|
|
|
|
|
|
} else { |
213
|
0
|
|
|
|
|
0
|
$query .= ' AND'; |
214
|
|
|
|
|
|
|
} |
215
|
1
|
|
|
|
|
3
|
$query .= " $c1 = ?"; |
216
|
1
|
|
|
|
|
3
|
push @args, $params{$c1}; |
217
|
|
|
|
|
|
|
} |
218
|
1
|
50
|
|
|
|
3
|
if($self->{'logger'}) { |
219
|
0
|
|
|
|
|
0
|
$self->{'logger'}->debug("selectall_hashref $query: " . join(', ', @args)); |
220
|
|
|
|
|
|
|
} |
221
|
1
|
|
|
|
|
7
|
my $sth = $self->{$table}->prepare($query); |
222
|
1
|
50
|
|
|
|
4187
|
$sth->execute(@args) || throw Error::Simple("$query: @args"); |
223
|
1
|
|
|
|
|
3177754
|
my @rc; |
224
|
1
|
|
|
|
|
13
|
while (my $href = $sth->fetchrow_hashref()) { |
225
|
2
|
|
|
|
|
148
|
push @rc, $href; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
1
|
|
|
|
|
50
|
return \@rc; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# Returns a hash reference for one row in a table |
232
|
|
|
|
|
|
|
sub fetchrow_hashref { |
233
|
5
|
|
|
5
|
0
|
1429
|
my $self = shift; |
234
|
5
|
100
|
|
|
|
25
|
my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; |
|
4
|
|
|
|
|
19
|
|
235
|
|
|
|
|
|
|
|
236
|
5
|
|
|
|
|
13
|
my $table = ref($self); |
237
|
5
|
|
|
|
|
31
|
$table =~ s/.*:://; |
238
|
|
|
|
|
|
|
|
239
|
5
|
50
|
|
|
|
41
|
$self->_open() if(!$self->{table}); |
240
|
|
|
|
|
|
|
|
241
|
5
|
|
|
|
|
20
|
my $query = "SELECT * FROM $table"; |
242
|
5
|
|
|
|
|
11
|
my @args; |
243
|
5
|
|
|
|
|
21
|
foreach my $c1(keys(%params)) { |
244
|
6
|
100
|
|
|
|
25
|
if(scalar(@args) == 0) { |
245
|
5
|
|
|
|
|
15
|
$query .= ' WHERE'; |
246
|
|
|
|
|
|
|
} else { |
247
|
1
|
|
|
|
|
2
|
$query .= ' AND'; |
248
|
|
|
|
|
|
|
} |
249
|
6
|
|
|
|
|
19
|
$query .= " $c1 = ?"; |
250
|
6
|
|
|
|
|
19
|
push @args, $params{$c1}; |
251
|
|
|
|
|
|
|
} |
252
|
5
|
100
|
|
|
|
21
|
if($self->{'logger'}) { |
253
|
3
|
|
|
|
|
29
|
$self->{'logger'}->debug("fetchrow_hashref $query: " . join(', ', @args)); |
254
|
|
|
|
|
|
|
} |
255
|
5
|
|
|
|
|
88
|
my $sth = $self->{$table}->prepare($query); |
256
|
5
|
50
|
|
|
|
24840
|
$sth->execute(@args) || throw Error::Simple("$query: @args"); |
257
|
4
|
|
|
|
|
5300723
|
return $sth->fetchrow_hashref(); |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# Execute the given SQL on the data |
261
|
|
|
|
|
|
|
sub execute { |
262
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
263
|
0
|
0
|
|
|
|
0
|
my %args = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
0
|
my $table = ref($self); |
266
|
0
|
|
|
|
|
0
|
$table =~ s/.*:://; |
267
|
|
|
|
|
|
|
|
268
|
0
|
0
|
|
|
|
0
|
$self->_open() if(!$self->{table}); |
269
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
0
|
my $query = $args{'query'}; |
271
|
0
|
0
|
|
|
|
0
|
if($self->{'logger'}) { |
272
|
0
|
|
|
|
|
0
|
$self->{'logger'}->debug("fetchrow_hashref $query"); |
273
|
|
|
|
|
|
|
} |
274
|
0
|
|
|
|
|
0
|
my $sth = $self->{$table}->prepare($query); |
275
|
0
|
0
|
|
|
|
0
|
$sth->execute() || throw Error::Simple($query); |
276
|
0
|
|
|
|
|
0
|
my @rc; |
277
|
0
|
|
|
|
|
0
|
while (my $href = $sth->fetchrow_hashref()) { |
278
|
0
|
|
|
|
|
0
|
push @rc, $href; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
0
|
return \@rc; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
# Time that the database was last updated |
285
|
|
|
|
|
|
|
sub updated { |
286
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
287
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
0
|
return $self->{'_updated'}; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
# Return the contents of an arbiratary column in the database which match the given criteria |
292
|
|
|
|
|
|
|
# Returns an array of the matches, or just the first entry when called in scalar context |
293
|
|
|
|
|
|
|
sub AUTOLOAD { |
294
|
1
|
|
|
1
|
|
282
|
our $AUTOLOAD; |
295
|
1
|
|
|
|
|
2
|
my $column = $AUTOLOAD; |
296
|
|
|
|
|
|
|
|
297
|
1
|
|
|
|
|
7
|
$column =~ s/.*:://; |
298
|
|
|
|
|
|
|
|
299
|
1
|
50
|
|
|
|
5
|
return if($column eq 'DESTROY'); |
300
|
|
|
|
|
|
|
|
301
|
1
|
50
|
|
|
|
5
|
my $self = shift or return undef; |
302
|
|
|
|
|
|
|
|
303
|
1
|
|
|
|
|
3
|
my $table = ref($self); |
304
|
1
|
|
|
|
|
4
|
$table =~ s/.*:://; |
305
|
|
|
|
|
|
|
|
306
|
1
|
50
|
|
|
|
6
|
$self->_open() if(!$self->{$table}); |
307
|
|
|
|
|
|
|
|
308
|
1
|
50
|
|
|
|
7
|
my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
309
|
|
|
|
|
|
|
|
310
|
1
|
|
|
|
|
4
|
my $query = "SELECT DISTINCT $column FROM $table"; |
311
|
1
|
|
|
|
|
2
|
my @args; |
312
|
1
|
|
|
|
|
4
|
foreach my $c1(keys(%params)) { |
313
|
|
|
|
|
|
|
# $query .= " AND $c1 LIKE ?"; |
314
|
2
|
100
|
|
|
|
5
|
if(scalar(@args) == 0) { |
315
|
1
|
|
|
|
|
2
|
$query .= ' WHERE'; |
316
|
|
|
|
|
|
|
} else { |
317
|
1
|
|
|
|
|
2
|
$query .= ' AND'; |
318
|
|
|
|
|
|
|
} |
319
|
2
|
|
|
|
|
5
|
$query .= " $c1 = ?"; |
320
|
2
|
|
|
|
|
4
|
push @args, $params{$c1}; |
321
|
|
|
|
|
|
|
} |
322
|
1
|
|
|
|
|
4
|
$query .= " ORDER BY $column"; |
323
|
1
|
50
|
|
|
|
3
|
if($self->{'logger'}) { |
324
|
1
|
50
|
|
|
|
3
|
if(scalar(@args)) { |
325
|
1
|
|
|
|
|
9
|
$self->{'logger'}->debug("AUTOLOAD $query: " . join(', ', @args)); |
326
|
|
|
|
|
|
|
} else { |
327
|
0
|
|
|
|
|
0
|
$self->{'logger'}->debug("AUTOLOAD $query"); |
328
|
|
|
|
|
|
|
} |
329
|
|
|
|
|
|
|
} |
330
|
1
|
|
33
|
|
|
12
|
my $sth = $self->{$table}->prepare($query) || throw Error::Simple($query); |
331
|
0
|
0
|
|
|
|
0
|
$sth->execute(@args) || throw Error::Simple($query); |
332
|
|
|
|
|
|
|
|
333
|
0
|
0
|
|
|
|
0
|
if(wantarray()) { |
334
|
0
|
|
|
|
|
0
|
return map { $_->[0] } @{$sth->fetchall_arrayref()}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
335
|
|
|
|
|
|
|
} |
336
|
0
|
|
|
|
|
0
|
return $sth->fetchrow_array(); # Return the first match only |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
sub DESTROY { |
340
|
6
|
50
|
33
|
6
|
|
2089
|
if(defined($^V) && ($^V ge 'v5.14.0')) { |
341
|
6
|
50
|
|
|
|
24
|
return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; # >= 5.14.0 only |
342
|
|
|
|
|
|
|
} |
343
|
6
|
|
|
|
|
18
|
my $self = shift; |
344
|
|
|
|
|
|
|
|
345
|
6
|
50
|
|
|
|
302
|
if($self->{'temp'}) { |
346
|
0
|
|
|
|
|
|
unlink $self->{'temp'}; |
347
|
|
|
|
|
|
|
} |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
1; |