line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#$Id: DBI.pm,v 1.19 2009/09/30 07:37:09 dinosau2 Exp $ |
2
|
|
|
|
|
|
|
# /* vim:et: set ts=4 sw=4 sts=4 tw=78: */ |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package ACME::QuoteDB::DB::DBI; |
5
|
7
|
|
|
7
|
|
50
|
use base 'Class::DBI'; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
16470
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
647954
|
use 5.008005; # require perl 5.8.5 |
|
7
|
|
|
|
|
30
|
|
|
7
|
|
|
|
|
276
|
|
8
|
|
|
|
|
|
|
# DBD::SQLite Unicode is not supported before 5.8.5 |
9
|
7
|
|
|
7
|
|
446
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
200
|
|
10
|
7
|
|
|
7
|
|
40
|
use strict; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
319
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#use criticism 'brutal'; # use critic with a ~/.perlcriticrc |
13
|
|
|
|
|
|
|
|
14
|
7
|
|
|
7
|
|
40
|
use version; our $VERSION = qv('0.1.2'); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
53
|
|
15
|
|
|
|
|
|
|
|
16
|
7
|
|
|
7
|
|
8899
|
use Readonly; |
|
7
|
|
|
|
|
24641
|
|
|
7
|
|
|
|
|
461
|
|
17
|
7
|
|
|
7
|
|
60
|
use File::Basename qw/dirname/; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
457
|
|
18
|
7
|
|
|
7
|
|
42
|
use Carp qw/croak/; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
352
|
|
19
|
7
|
|
|
7
|
|
44
|
use Cwd 'abs_path'; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
302
|
|
20
|
7
|
|
|
7
|
|
41
|
use File::Spec; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
3112
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Readonly my $QUOTES_DATABASE => $ENV{ACME_QUOTEDB_PATH} |
23
|
|
|
|
|
|
|
|| File::Spec->catfile(_untaint_db_path(), |
24
|
|
|
|
|
|
|
q(quotedb), q(quotes.db) |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# set this to use a remote database |
28
|
|
|
|
|
|
|
# i.e. mysql |
29
|
|
|
|
|
|
|
Readonly my $REMOTE => $ENV{ACME_QUOTEDB_REMOTE}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# be more specific (or more general) this is mysql |
32
|
|
|
|
|
|
|
# and 'remote' can be localhost |
33
|
|
|
|
|
|
|
if ($REMOTE && $REMOTE ne 'mysql') { |
34
|
|
|
|
|
|
|
croak "mysql is the only remote database supported" |
35
|
|
|
|
|
|
|
." set ENV{ACME_QUOTEDB_REMOTE} = 'mysql'"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif ($REMOTE && $REMOTE eq 'mysql') { |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $database = $ENV{ACME_QUOTEDB_DB}; |
40
|
|
|
|
|
|
|
my $host = $ENV{ACME_QUOTEDB_HOST}; |
41
|
|
|
|
|
|
|
my $user = $ENV{ACME_QUOTEDB_USER}; |
42
|
|
|
|
|
|
|
my $pass = $ENV{ACME_QUOTEDB_PASS}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
ACME::QuoteDB::DB::DBI->connection( |
45
|
|
|
|
|
|
|
"DBI:mysql:database=$database;host=$host",$user,$pass, |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
RaiseError => 1, |
48
|
|
|
|
|
|
|
mysql_enable_utf8 => 1, |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
) |
52
|
|
|
|
|
|
|
|| croak "can not connect to: $database $!"; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
ACME::QuoteDB::DB::DBI->connection( |
57
|
|
|
|
|
|
|
'dbi:SQLite:dbname='.$QUOTES_DATABASE, '', '', |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
RaiseError => 1, |
60
|
|
|
|
|
|
|
unicode => 1, |
61
|
|
|
|
|
|
|
# func/pragma's may not work here,..(probably isnt' smart anyway) |
62
|
|
|
|
|
|
|
#count_changes => 0, |
63
|
|
|
|
|
|
|
#temp_store => 2, |
64
|
|
|
|
|
|
|
#synchronous => 'OFF', |
65
|
|
|
|
|
|
|
#busy_timeout => 3600000 |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
) |
68
|
|
|
|
|
|
|
|| croak "$QUOTES_DATABASE does not exist, or cant be created $!"; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# how to enable this function? |
71
|
|
|
|
|
|
|
#ACME::QuoteDB::DB::DBI->set_sql(func( 3600000, 'busy_timeout' ); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_current_db_path { |
76
|
12
|
|
|
12
|
1
|
334
|
return $QUOTES_DATABASE; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _untaint_db_path { |
80
|
6
|
|
|
6
|
|
1389
|
my $sane_path = abs_path(dirname(__FILE__)); |
81
|
|
|
|
|
|
|
# appease taint mode, what a dir path looks like,... (probably not) |
82
|
6
|
|
|
|
|
39
|
$sane_path =~ m{([a-zA-Z0-9-_\.:\/\\\s]+)}; #add '.', ':' for win32 |
83
|
6
|
|
33
|
|
|
328
|
return $1 || croak 'cannot untaint db path'; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |