line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: DBI.pm 85 2022-10-29 05:44:36Z stro $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package CPAN::SQLite::DBI; |
4
|
8
|
|
|
8
|
|
3236
|
use strict; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
235
|
|
5
|
8
|
|
|
8
|
|
38
|
use warnings; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
368
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.220'; |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
51
|
use English qw/-no_match_vars/; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
71
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require File::Spec; |
12
|
8
|
|
|
8
|
|
12297
|
use DBI; |
|
8
|
|
|
|
|
106579
|
|
|
8
|
|
|
|
|
593
|
|
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
66
|
use parent 'Exporter'; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
81
|
|
15
|
|
|
|
|
|
|
our ($dbh, $tables, @EXPORT_OK); |
16
|
|
|
|
|
|
|
@EXPORT_OK = qw($dbh $tables); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$tables = { |
19
|
|
|
|
|
|
|
'info' => { |
20
|
|
|
|
|
|
|
'primary' => { |
21
|
|
|
|
|
|
|
'status' => q!INTEGER NOT NULL PRIMARY KEY!, |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
'other' => {}, |
24
|
|
|
|
|
|
|
'key' => [], |
25
|
|
|
|
|
|
|
'name' => 'status', |
26
|
|
|
|
|
|
|
'id' => 'status', |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
mods => { |
29
|
|
|
|
|
|
|
primary => { mod_id => q{INTEGER NOT NULL PRIMARY KEY} }, |
30
|
|
|
|
|
|
|
other => { |
31
|
|
|
|
|
|
|
mod_name => q{VARCHAR(100) NOT NULL}, |
32
|
|
|
|
|
|
|
dist_id => q{INTEGER NOT NULL}, |
33
|
|
|
|
|
|
|
mod_abs => q{TEXT}, |
34
|
|
|
|
|
|
|
mod_vers => q{VARCHAR(10)}, |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
key => [qw/dist_id mod_name/], |
37
|
|
|
|
|
|
|
name => 'mod_name', |
38
|
|
|
|
|
|
|
id => 'mod_id', |
39
|
|
|
|
|
|
|
has_a => { dists => 'dist_id' }, |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
dists => { |
42
|
|
|
|
|
|
|
primary => { dist_id => q{INTEGER NOT NULL PRIMARY KEY} }, |
43
|
|
|
|
|
|
|
other => { |
44
|
|
|
|
|
|
|
dist_name => q{VARCHAR(90) NOT NULL}, |
45
|
|
|
|
|
|
|
auth_id => q{INTEGER NOT NULL}, |
46
|
|
|
|
|
|
|
dist_file => q{VARCHAR(110) NOT NULL}, |
47
|
|
|
|
|
|
|
dist_vers => q{VARCHAR(20)}, |
48
|
|
|
|
|
|
|
dist_abs => q{TEXT}, |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
key => [qw/auth_id dist_name/], |
51
|
|
|
|
|
|
|
name => 'dist_name', |
52
|
|
|
|
|
|
|
id => 'dist_id', |
53
|
|
|
|
|
|
|
has_a => { auths => 'auth_id' }, |
54
|
|
|
|
|
|
|
has_many => { mods => 'dist_id', }, |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
auths => { |
57
|
|
|
|
|
|
|
primary => { auth_id => q{INTEGER NOT NULL PRIMARY KEY} }, |
58
|
|
|
|
|
|
|
other => { |
59
|
|
|
|
|
|
|
cpanid => q{VARCHAR(20) NOT NULL}, |
60
|
|
|
|
|
|
|
fullname => q{VARCHAR(40) NOT NULL}, |
61
|
|
|
|
|
|
|
email => q{TEXT}, |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
key => [qw/cpanid/], |
64
|
|
|
|
|
|
|
has_many => { dists => 'dist_id' }, |
65
|
|
|
|
|
|
|
name => 'cpanid', |
66
|
|
|
|
|
|
|
id => 'auth_id', |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
953
|
|
|
953
|
0
|
1244816
|
my ($class, %args) = @_; |
72
|
953
|
|
33
|
|
|
2527
|
my $db_dir = $args{db_dir} || $args{CPAN}; |
73
|
953
|
|
|
|
|
9536
|
my $db = File::Spec->catfile($db_dir, $args{db_name}); |
74
|
953
|
|
66
|
|
|
3149
|
$dbh ||= DBI->connect( |
75
|
|
|
|
|
|
|
"DBI:SQLite:$db", |
76
|
|
|
|
|
|
|
'', '', |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
RaiseError => 1, |
79
|
|
|
|
|
|
|
AutoCommit => 0, |
80
|
|
|
|
|
|
|
sqlite_use_immediate_transaction => 0, |
81
|
|
|
|
|
|
|
}); |
82
|
953
|
50
|
|
|
|
81389
|
die "Cannot connect to $db" unless $dbh; |
83
|
953
|
|
|
|
|
7148
|
$dbh->{AutoCommit} = 0; |
84
|
|
|
|
|
|
|
|
85
|
953
|
|
|
|
|
2187
|
my $objs; |
86
|
953
|
|
|
|
|
3012
|
foreach my $table (keys %$tables) { |
87
|
3812
|
|
|
|
|
7078
|
my $cl = $class . '::' . $table; |
88
|
3812
|
|
|
|
|
8439
|
$objs->{$table} = $cl->make(table => $table); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
953
|
|
|
|
|
2581
|
for my $table (keys %$tables) { |
92
|
3812
|
|
|
|
|
5555
|
foreach my $type (qw(primary other)) { |
93
|
7624
|
|
|
|
|
9180
|
foreach my $column (keys %{ $tables->{$table}->{$type} }) { |
|
7624
|
|
|
|
|
16531
|
|
94
|
15248
|
|
|
|
|
18441
|
push @{ $tables->{$table}->{columns} }, $column; |
|
15248
|
|
|
|
|
30242
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
953
|
|
|
|
|
8052
|
return bless { objs => $objs }, $class; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub make { |
103
|
3812
|
|
|
3812
|
0
|
8294
|
my ($class, %args) = @_; |
104
|
3812
|
|
|
|
|
5463
|
my $table = $args{table}; |
105
|
3812
|
50
|
|
|
|
6555
|
die qq{No table exists corresponding to '$class'} unless $table; |
106
|
3812
|
|
|
|
|
5148
|
my $info = $tables->{$table}; |
107
|
3812
|
50
|
|
|
|
6613
|
die qq{No information available for table '$table'} unless $info; |
108
|
|
|
|
|
|
|
my $self = { |
109
|
|
|
|
|
|
|
table => $table, |
110
|
|
|
|
|
|
|
columns => $info->{columns}, |
111
|
|
|
|
|
|
|
id => $info->{id}, |
112
|
|
|
|
|
|
|
name => $info->{name}, |
113
|
3812
|
|
|
|
|
11419
|
}; |
114
|
3812
|
|
|
|
|
6339
|
foreach (qw(name has_a has_many)) { |
115
|
11436
|
100
|
|
|
|
21177
|
next unless defined $info->{$_}; |
116
|
7624
|
|
|
|
|
12707
|
$self->{$_} = $info->{$_}; |
117
|
|
|
|
|
|
|
} |
118
|
3812
|
|
|
|
|
10591
|
return bless $self, $class; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub db_error { |
122
|
0
|
|
|
0
|
0
|
|
my ($obj, $sth) = @_; |
123
|
0
|
0
|
|
|
|
|
return unless $dbh; |
124
|
0
|
0
|
|
|
|
|
if ($sth) { |
125
|
0
|
|
|
|
|
|
$sth->finish; |
126
|
0
|
|
|
|
|
|
undef $sth; |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
|
return $obj->{error_msg} = q{Database error: } . $dbh->errstr; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
CPAN::SQLite::DBI - DBI information for the CPAN::SQLite database |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 VERSION |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
version 0.220 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 DESCRIPTION |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This module is used by L and |
144
|
|
|
|
|
|
|
L to set up some basic database |
145
|
|
|
|
|
|
|
information. It exports two variables: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=over 3 |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item C<$tables> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This is a hash reference whose keys are the table names, with |
152
|
|
|
|
|
|
|
corresponding values being hash references whose keys are the |
153
|
|
|
|
|
|
|
columns of the table and values being the associated data types. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item C<$dbh> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This is a L database handle used to connect to the |
158
|
|
|
|
|
|
|
database. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The main method of this module is C, which is used |
163
|
|
|
|
|
|
|
to make the tables of the database. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SEE ALSO |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L and L |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |