line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Index.pm 82 2020-05-30 06:14:27Z stro $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package CPAN::SQLite::DBI::Index; |
4
|
4
|
|
|
4
|
|
29
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
126
|
|
5
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
300
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
4
|
|
|
4
|
|
12
|
our $VERSION = '0.218'; |
9
|
4
|
|
|
|
|
7
|
$CPAN::SQLite::DBI::Index::info::VERSION = $VERSION; |
10
|
4
|
|
|
|
|
7
|
$CPAN::SQLite::DBI::Index::mods::VERSION = $VERSION; |
11
|
4
|
|
|
|
|
7
|
$CPAN::SQLite::DBI::Index::dists::VERSION = $VERSION; |
12
|
4
|
|
|
|
|
87
|
$CPAN::SQLite::DBI::Index::auths::VERSION = $VERSION; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
24
|
use CPAN::SQLite::DBI qw($dbh); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
326
|
|
16
|
4
|
|
|
4
|
|
33
|
use parent 'CPAN::SQLite::DBI'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
22
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package CPAN::SQLite::DBI::Index::info; |
19
|
4
|
|
|
4
|
|
273
|
use parent 'CPAN::SQLite::DBI::Index'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
15
|
|
20
|
4
|
|
|
4
|
|
235
|
use CPAN::SQLite::DBI qw($dbh); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
342
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package CPAN::SQLite::DBI::Index::mods; |
23
|
4
|
|
|
4
|
|
28
|
use parent 'CPAN::SQLite::DBI::Index'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
17
|
|
24
|
4
|
|
|
4
|
|
267
|
use CPAN::SQLite::DBI qw($dbh); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
365
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package CPAN::SQLite::DBI::Index::dists; |
27
|
4
|
|
|
4
|
|
37
|
use parent 'CPAN::SQLite::DBI::Index'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
25
|
|
28
|
4
|
|
|
4
|
|
244
|
use CPAN::SQLite::DBI qw($dbh); |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
999
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub fetch_ids { |
31
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
32
|
0
|
|
|
|
|
0
|
my $sql = sprintf(qq{SELECT %s,%s,%s FROM %s}, $self->{id}, $self->{name}, 'dist_vers', $self->{table}); |
33
|
0
|
0
|
|
|
|
0
|
my $sth = $dbh->prepare($sql) or do { |
34
|
0
|
|
|
|
|
0
|
$self->db_error(); |
35
|
0
|
|
|
|
|
0
|
return; |
36
|
|
|
|
|
|
|
}; |
37
|
0
|
0
|
|
|
|
0
|
$sth->execute() or do { |
38
|
0
|
|
|
|
|
0
|
$self->db_error($sth); |
39
|
0
|
|
|
|
|
0
|
return; |
40
|
|
|
|
|
|
|
}; |
41
|
0
|
|
|
|
|
0
|
my ($ids, $versions); |
42
|
0
|
|
|
|
|
0
|
while (my ($id, $key, $vers) = $sth->fetchrow_array()) { |
43
|
0
|
|
|
|
|
0
|
$ids->{$key} = $id; |
44
|
0
|
|
|
|
|
0
|
$versions->{$key} = $vers; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
0
|
$sth->finish; |
47
|
0
|
|
|
|
|
0
|
undef $sth; |
48
|
0
|
|
|
|
|
0
|
return ($ids, $versions); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
package CPAN::SQLite::DBI::Index::auths; |
52
|
4
|
|
|
4
|
|
41
|
use parent 'CPAN::SQLite::DBI::Index'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
17
|
|
53
|
4
|
|
|
4
|
|
248
|
use CPAN::SQLite::DBI qw($dbh); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
374
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
package CPAN::SQLite::DBI::Index; |
56
|
4
|
|
|
4
|
|
30
|
use CPAN::SQLite::DBI qw($tables); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
291
|
|
57
|
4
|
|
|
4
|
|
36
|
use CPAN::SQLite::DBI qw($dbh); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4919
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub fetch_ids { |
60
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
61
|
0
|
|
|
|
|
0
|
my $sql = sprintf(qq{SELECT %s,%s from %s}, $self->{id}, $self->{name}, $self->{table}); |
62
|
0
|
0
|
|
|
|
0
|
my $sth = $dbh->prepare($sql) or do { |
63
|
0
|
|
|
|
|
0
|
$self->db_error(); |
64
|
0
|
|
|
|
|
0
|
return; |
65
|
|
|
|
|
|
|
}; |
66
|
0
|
0
|
|
|
|
0
|
$sth->execute() or do { |
67
|
0
|
|
|
|
|
0
|
$self->db_error($sth); |
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
}; |
70
|
0
|
|
|
|
|
0
|
my $ids; |
71
|
0
|
|
|
|
|
0
|
while (my ($id, $key) = $sth->fetchrow_array()) { |
72
|
0
|
|
|
|
|
0
|
$ids->{$key} = $id; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
0
|
$sth->finish; |
75
|
0
|
|
|
|
|
0
|
undef $sth; |
76
|
0
|
|
|
|
|
0
|
return $ids; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub schema { |
80
|
4
|
|
|
4
|
0
|
10
|
my ($self, $data) = @_; |
81
|
4
|
|
|
|
|
9
|
my $schema = ''; |
82
|
4
|
|
|
|
|
8
|
foreach my $type (qw(primary other)) { |
83
|
8
|
|
|
|
|
14
|
foreach my $column (keys %{ $data->{$type} }) { |
|
8
|
|
|
|
|
22
|
|
84
|
16
|
|
|
|
|
50
|
$schema .= $column . ' ' . $data->{$type}->{$column} . ", "; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
4
|
|
|
|
|
25
|
$schema =~ s{, $}{}; |
88
|
4
|
|
|
|
|
15
|
return $schema; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub create_index { |
92
|
4
|
|
|
4
|
0
|
11
|
my ($self, $data) = @_; |
93
|
4
|
|
|
|
|
25
|
my $key = $data->{key}; |
94
|
4
|
|
|
|
|
10
|
my $table = $self->{table}; |
95
|
4
|
50
|
33
|
|
|
23
|
return 1 unless (defined $key and ref($key) eq 'ARRAY'); |
96
|
4
|
|
|
|
|
20
|
foreach my $index (@$key) { |
97
|
5
|
|
|
|
|
16
|
my $id_name = 'ix_' . $table . '_' . $index; |
98
|
5
|
|
|
|
|
14
|
$id_name =~ s/\(\s*\d+\s*\)//; |
99
|
5
|
|
|
|
|
15
|
my $sql = 'CREATE INDEX ' . $id_name . ' ON ' . $table . '( ' . $index . ' )'; |
100
|
5
|
|
|
|
|
30
|
my $sth = $dbh->prepare($sql); |
101
|
5
|
50
|
|
|
|
737
|
$sth->execute() or do { |
102
|
0
|
|
|
|
|
0
|
$self->db_error($sth); |
103
|
0
|
|
|
|
|
0
|
return; |
104
|
|
|
|
|
|
|
}; |
105
|
5
|
|
|
|
|
32
|
$sth->finish; |
106
|
5
|
|
|
|
|
60
|
undef $sth; |
107
|
|
|
|
|
|
|
} |
108
|
4
|
|
|
|
|
21
|
return 1; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub drop_table { |
112
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
113
|
4
|
|
|
|
|
23
|
my $table = $self->{table}; |
114
|
4
|
|
|
|
|
9
|
my $sql = qq{SELECT name FROM sqlite_master } . qq{ WHERE type='table' AND name=?}; |
115
|
4
|
|
|
|
|
23
|
my $sth = $dbh->prepare($sql); |
116
|
4
|
|
|
|
|
585
|
$sth->execute($table); |
117
|
4
|
50
|
|
|
|
27
|
if (defined $sth->fetchrow_array) { |
118
|
0
|
0
|
|
|
|
0
|
$dbh->do(qq{drop table $table}) or do { |
119
|
0
|
|
|
|
|
0
|
$self->db_error($sth); |
120
|
0
|
|
|
|
|
0
|
return; |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
} |
123
|
4
|
|
|
|
|
14
|
$sth->finish; |
124
|
4
|
|
|
|
|
48
|
undef $sth; |
125
|
4
|
|
|
|
|
15
|
return 1; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub create_table { |
129
|
4
|
|
|
4
|
0
|
12
|
my ($self, $schema) = @_; |
130
|
4
|
50
|
|
|
|
21
|
return unless $schema; |
131
|
4
|
|
|
|
|
22
|
my $sql = sprintf(qq{CREATE TABLE %s (%s)}, $self->{table}, $schema); |
132
|
4
|
|
|
|
|
20
|
my $sth = $dbh->prepare($sql); |
133
|
4
|
50
|
|
|
|
846
|
$sth->execute() or do { |
134
|
0
|
|
|
|
|
0
|
$self->db_error($sth); |
135
|
0
|
|
|
|
|
0
|
return; |
136
|
|
|
|
|
|
|
}; |
137
|
4
|
|
|
|
|
29
|
$sth->finish; |
138
|
4
|
|
|
|
|
41
|
undef $sth; |
139
|
4
|
|
|
|
|
26
|
return 1; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub create_tables { |
143
|
1
|
|
|
1
|
1
|
5
|
my ($self, %args) = @_; |
144
|
1
|
50
|
|
|
|
6
|
return unless $args{setup}; |
145
|
1
|
|
|
|
|
7
|
my $objs = $self->{objs}; |
146
|
1
|
|
|
|
|
4
|
foreach my $table (keys %$objs) { |
147
|
4
|
50
|
|
|
|
15
|
next unless my $schema = $self->schema($tables->{$table}); |
148
|
4
|
|
|
|
|
9
|
my $obj = $objs->{$table}; |
149
|
4
|
50
|
|
|
|
33
|
$obj->drop_table or return; |
150
|
4
|
50
|
|
|
|
30
|
$obj->create_table($schema) or return; |
151
|
4
|
50
|
|
|
|
33
|
$obj->create_index($tables->{$table}) or return; |
152
|
|
|
|
|
|
|
} |
153
|
1
|
|
|
|
|
8
|
return 1; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub sth_insert { |
157
|
4
|
|
|
4
|
1
|
22
|
my ($self, $fields) = @_; |
158
|
4
|
|
|
|
|
11
|
my $flds = join ',', @{$fields}; |
|
4
|
|
|
|
|
23
|
|
159
|
4
|
|
|
|
|
14
|
my $vals = join ',', map { '?' } @{$fields}; |
|
13
|
|
|
|
|
45
|
|
|
4
|
|
|
|
|
14
|
|
160
|
4
|
|
|
|
|
41
|
my $sql = sprintf(qq{INSERT INTO %s (%s) VALUES (%s)}, $self->{table}, $flds, $vals); |
161
|
|
|
|
|
|
|
|
162
|
4
|
50
|
|
|
|
49
|
my $sth = $dbh->prepare($sql) or do { |
163
|
0
|
|
|
|
|
0
|
$self->db_error(); |
164
|
0
|
|
|
|
|
0
|
return; |
165
|
|
|
|
|
|
|
}; |
166
|
4
|
|
|
|
|
512
|
return $sth; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub sth_update { |
170
|
0
|
|
|
0
|
1
|
0
|
my ($self, $fields, $id, $rep_id) = @_; |
171
|
0
|
|
|
|
|
0
|
my $set = join ',', map { "$_=?" } @{$fields}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
172
|
0
|
|
|
|
|
0
|
my $sql = sprintf(qq{UPDATE %s SET %s WHERE %s = %s}, $self->{table}, $set, $self->{id}, $id); |
173
|
0
|
0
|
|
|
|
0
|
$sql .= qq { AND rep_id = $rep_id } if ($rep_id); |
174
|
0
|
0
|
|
|
|
0
|
my $sth = $dbh->prepare($sql) or do { |
175
|
0
|
|
|
|
|
0
|
$self->db_error(); |
176
|
0
|
|
|
|
|
0
|
return; |
177
|
|
|
|
|
|
|
}; |
178
|
0
|
|
|
|
|
0
|
return $sth; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub sth_delete { |
182
|
1
|
|
|
1
|
1
|
6
|
my ($self, $table_id, $rep_id) = @_; |
183
|
1
|
|
|
|
|
6
|
my $sql = sprintf(qq{DELETE FROM %s where %s = ?}, $self->{table}, $table_id); |
184
|
1
|
50
|
|
|
|
4
|
$sql .= qq { AND rep_id = $rep_id } if ($rep_id); |
185
|
1
|
50
|
|
|
|
8
|
my $sth = $dbh->prepare($sql) or do { |
186
|
0
|
|
|
|
|
0
|
$self->db_error(); |
187
|
0
|
|
|
|
|
0
|
return; |
188
|
|
|
|
|
|
|
}; |
189
|
1
|
|
|
|
|
85
|
return $sth; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 NAME |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
CPAN::SQLite::DBI::Index - DBI information for indexing the CPAN::SQLite database |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 VERSION |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
version 0.218 |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 DESCRIPTION |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This module provides various methods for L in |
205
|
|
|
|
|
|
|
indexing and populating the database from the index files. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=over |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item C |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
This creates the database tables. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item C |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
This drops a table. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item C |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
This returns an C<$sth> statement handle for inserting |
220
|
|
|
|
|
|
|
values into a table. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item C |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
This returns an C<$sth> statement handle for updating |
225
|
|
|
|
|
|
|
values into a table. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item C |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
This returns an C<$sth> statement handle for deleting |
230
|
|
|
|
|
|
|
values from a table. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=back |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 SEE ALSO |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |