line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: DBI.pm 84 2020-05-31 06:29:34Z stro $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package CPAN::SQLite::DBI; |
4
|
8
|
|
|
8
|
|
3440
|
use strict; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
243
|
|
5
|
8
|
|
|
8
|
|
50
|
use warnings; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
378
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.219'; |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
51
|
use English qw/-no_match_vars/; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
43
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require File::Spec; |
12
|
8
|
|
|
8
|
|
12570
|
use DBI; |
|
8
|
|
|
|
|
104622
|
|
|
8
|
|
|
|
|
605
|
|
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
67
|
use parent 'Exporter'; |
|
8
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
78
|
|
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
|
1233248
|
my ($class, %args) = @_; |
72
|
953
|
|
33
|
|
|
2399
|
my $db_dir = $args{db_dir} || $args{CPAN}; |
73
|
953
|
|
|
|
|
9838
|
my $db = File::Spec->catfile($db_dir, $args{db_name}); |
74
|
953
|
|
66
|
|
|
3387
|
$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
|
|
|
|
83468
|
die "Cannot connect to $db" unless $dbh; |
83
|
953
|
|
|
|
|
7015
|
$dbh->{AutoCommit} = 0; |
84
|
|
|
|
|
|
|
|
85
|
953
|
|
|
|
|
2260
|
my $objs; |
86
|
953
|
|
|
|
|
3010
|
foreach my $table (keys %$tables) { |
87
|
3812
|
|
|
|
|
7130
|
my $cl = $class . '::' . $table; |
88
|
3812
|
|
|
|
|
8552
|
$objs->{$table} = $cl->make(table => $table); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
953
|
|
|
|
|
2452
|
for my $table (keys %$tables) { |
92
|
3812
|
|
|
|
|
5195
|
foreach my $type (qw(primary other)) { |
93
|
7624
|
|
|
|
|
8938
|
foreach my $column (keys %{ $tables->{$table}->{$type} }) { |
|
7624
|
|
|
|
|
15980
|
|
94
|
15248
|
|
|
|
|
18363
|
push @{ $tables->{$table}->{columns} }, $column; |
|
15248
|
|
|
|
|
29900
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
953
|
|
|
|
|
8132
|
return bless { objs => $objs }, $class; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub make { |
103
|
3812
|
|
|
3812
|
0
|
7828
|
my ($class, %args) = @_; |
104
|
3812
|
|
|
|
|
5405
|
my $table = $args{table}; |
105
|
3812
|
50
|
|
|
|
6513
|
die qq{No table exists corresponding to '$class'} unless $table; |
106
|
3812
|
|
|
|
|
5194
|
my $info = $tables->{$table}; |
107
|
3812
|
50
|
|
|
|
6154
|
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
|
|
|
|
|
11429
|
}; |
114
|
3812
|
|
|
|
|
6523
|
foreach (qw(name has_a has_many)) { |
115
|
11436
|
100
|
|
|
|
21209
|
next unless defined $info->{$_}; |
116
|
7624
|
|
|
|
|
13559
|
$self->{$_} = $info->{$_}; |
117
|
|
|
|
|
|
|
} |
118
|
3812
|
|
|
|
|
11164
|
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.219 |
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 |