line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MyLibrary::DB; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
46195
|
use DBI; |
|
13
|
|
|
|
|
321962
|
|
|
13
|
|
|
|
|
1145
|
|
4
|
13
|
|
|
13
|
|
16640
|
use MyLibrary::Config; |
|
13
|
|
|
|
|
34
|
|
|
13
|
|
|
|
|
564
|
|
5
|
13
|
|
|
13
|
|
80
|
use Carp qw(croak); |
|
13
|
|
|
|
|
90
|
|
|
13
|
|
|
|
|
970
|
|
6
|
13
|
|
|
13
|
|
126
|
use strict; |
|
13
|
|
|
|
|
37
|
|
|
13
|
|
|
|
|
2276
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $dbh; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
MyLibrary::DB |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use MyLibrary::DB; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $dbh = MyLibrary::DB->dbh(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This package connects to MyLibrary and returns the database handle. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 FUNCTIONS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 dbh() |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Returns database handle to MyLibrary. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 AUTHORS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Eric Lease Morgan |
33
|
|
|
|
|
|
|
Robert Fox |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub dbh { |
38
|
|
|
|
|
|
|
|
39
|
13
|
50
|
|
13
|
1
|
2321
|
if ($dbh) { |
40
|
0
|
|
|
|
|
0
|
return $dbh; |
41
|
|
|
|
|
|
|
} |
42
|
13
|
|
0
|
|
|
148
|
$dbh = DBI->connect($MyLibrary::Config::DATA_SOURCE, $MyLibrary::Config::USERNAME, $MyLibrary::Config::PASSWORD) || croak('Can\'t connect to database.'); |
43
|
0
|
|
|
|
|
|
return $dbh; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub nextID { |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my $dbh = dbh(); |
50
|
0
|
|
|
|
|
|
$dbh->do('UPDATE sequence SET id = id + 1'); |
51
|
0
|
|
|
|
|
|
my ($id) = $dbh->selectrow_array('SELECT id FROM sequence'); |
52
|
0
|
0
|
|
|
|
|
if ($id) { |
53
|
0
|
|
|
|
|
|
return $id; |
54
|
|
|
|
|
|
|
} else { # there was a problem |
55
|
0
|
|
|
|
|
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |