| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBQuery; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: DBQuery.pm,v 1.0.0-0 2011/07/07 11:02:57 Cnangel Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5812
|
use DBI; |
|
|
1
|
|
|
|
|
34134
|
|
|
|
1
|
|
|
|
|
947
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$DBQuery::VERSION = "1.101"; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new |
|
10
|
|
|
|
|
|
|
{ |
|
11
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
12
|
0
|
|
|
|
|
|
my $DB = shift; |
|
13
|
0
|
|
|
|
|
|
my $self; |
|
14
|
0
|
0
|
|
|
|
|
if (defined $DB->{dsn}) |
|
15
|
|
|
|
|
|
|
{ |
|
16
|
0
|
0
|
|
|
|
|
$self = { |
|
17
|
|
|
|
|
|
|
'dsn' => $DB->{dsn}, |
|
18
|
|
|
|
|
|
|
'user' => $DB->{db_user}, |
|
19
|
|
|
|
|
|
|
'pass' => (defined $DB->{db_pass} ? $DB->{db_pass} : ''), |
|
20
|
|
|
|
|
|
|
'dbh' => undef, |
|
21
|
|
|
|
|
|
|
'sth' => undef, |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
else |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
0
|
0
|
|
|
|
|
$DB->{driver_name} = 'mysql' unless (defined $DB->{driver_name}); |
|
27
|
0
|
0
|
|
|
|
|
$DB->{driver_name} = ucfirst($DB->{driver_name}) if ($DB->{driver_name} eq "oracle"); |
|
28
|
0
|
0
|
0
|
|
|
|
$self = { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
'driver' => $DB->{driver_name}, |
|
30
|
|
|
|
|
|
|
'dsn' => $DB->{driver_name} eq 'mysql' |
|
31
|
|
|
|
|
|
|
? 'dbi:' . $DB->{driver_name} . ':database=' . $DB->{db_name} . |
|
32
|
|
|
|
|
|
|
(defined $DB->{db_host} ? ';host=' . $DB->{db_host} : '') . |
|
33
|
|
|
|
|
|
|
(defined $DB->{db_sock} ? ';mysql_socket=' . $DB->{db_sock} : ';mysql_socket=/var/lib/mysql/mysql.sock') . |
|
34
|
|
|
|
|
|
|
(defined $DB->{db_port} ? ';port=' . $DB->{db_port} : ';port=3306') |
|
35
|
|
|
|
|
|
|
: ($DB->{driver_name} eq 'pgsql' |
|
36
|
|
|
|
|
|
|
? 'dbi:' . $DB->{driver_name} . ':dbname=' . $DB->{db_name} . '' . |
|
37
|
|
|
|
|
|
|
(defined $DB->{db_host} ? ';host=' . $DB->{db_host} : '') . |
|
38
|
|
|
|
|
|
|
(defined $DB->{db_path} ? ';path=' . $DB->{db_path} : '') . |
|
39
|
|
|
|
|
|
|
(defined $DB->{db_port} ? ';port=' . $DB->{db_port} : ';port=5432') |
|
40
|
|
|
|
|
|
|
: ($DB->{driver_name} eq 'Oracle' |
|
41
|
|
|
|
|
|
|
? 'dbi:' . $DB->{driver_name} . |
|
42
|
|
|
|
|
|
|
(defined $DB->{db_host} ? ':host=' . $DB->{db_host} : ':host=localhost') . |
|
43
|
|
|
|
|
|
|
(defined $DB->{db_port} ? ';port=' . $DB->{db_port} : '') . |
|
44
|
|
|
|
|
|
|
(defined $DB->{db_sid} ? ';sid=' . $DB->{db_sid} : '') . |
|
45
|
|
|
|
|
|
|
(defined $DB->{db_name} && !defined $DB->{db_sid} ? ';sid=' . $DB->{db_name} : '') |
|
46
|
|
|
|
|
|
|
: 'dbi:' . $DB->{driver_name} . (defined $DB->{db_host} ? ':' . $DB->{db_host} : '') |
|
47
|
|
|
|
|
|
|
) |
|
48
|
|
|
|
|
|
|
), |
|
49
|
|
|
|
|
|
|
'user' => $DB->{db_user}, |
|
50
|
|
|
|
|
|
|
'pass' => (defined $DB->{db_pass} ? $DB->{db_pass} : ''), |
|
51
|
|
|
|
|
|
|
'pconnect' => $DB->{db_pconnect}, |
|
52
|
|
|
|
|
|
|
'utf8' => $DB->{db_enable_utf8}, |
|
53
|
|
|
|
|
|
|
'autocommit' => (defined $DB->{db_autocommit} ? $DB->{db_autocommit} : 1), |
|
54
|
|
|
|
|
|
|
'LongReadLen' => $DB->{db_longreadlen}, |
|
55
|
|
|
|
|
|
|
'LongTruncOk' => $DB->{db_longtruncok}, |
|
56
|
|
|
|
|
|
|
'dbh' => undef, |
|
57
|
|
|
|
|
|
|
'sth' => undef, |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
|
|
|
|
|
bless $self, $class; |
|
61
|
0
|
|
|
|
|
|
return $self; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub connect |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
67
|
0
|
0
|
0
|
|
|
|
if ($_[0] && $self->{driver} eq 'mysql') { |
|
68
|
0
|
|
|
|
|
|
$self->{dbh} = DBI->connect($self->{dsn}, $self->{user}, $self->{pass}, {'RaiseError' => 1, 'mysql_enable_utf8' => 1}); |
|
69
|
|
|
|
|
|
|
} else { |
|
70
|
0
|
|
|
|
|
|
$self->{dbh} = DBI->connect($self->{dsn}, $self->{user}, $self->{pass}, {'RaiseError' => 1}); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ($self->{driver} eq 'mysql') { |
|
|
|
0
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
$self->{dbh}->{mysql_auto_reconnect} = $self->{pconnect} ? 1 : 0; |
|
75
|
0
|
0
|
|
|
|
|
$self->{dbh}->{mysql_enable_utf8} = $self->{utf8} ? 1 : 0; |
|
76
|
0
|
0
|
|
|
|
|
$self->{dbh}->{mysql_no_autocommit_cmd} = $self->{autocommit} ? 0 : 1; |
|
77
|
|
|
|
|
|
|
} elsif ($self->{driver} eq 'Oracle') { |
|
78
|
0
|
|
|
|
|
|
$self->{dbh}->{LongReadLen} = $self->{LongReadLen}; |
|
79
|
0
|
|
|
|
|
|
$self->{dbh}->{LongTruncOk} = $self->{LongTruncOk}; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
0
|
|
|
|
|
|
return; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub query |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
87
|
0
|
|
|
|
|
|
$self->{sth} = $self->{dbh}->prepare($_[0]); |
|
88
|
0
|
|
|
|
|
|
$self->{sth}->execute(); |
|
89
|
0
|
|
|
|
|
|
return $self->{sth}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub quote |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
95
|
0
|
|
|
|
|
|
return $self->{dbh}->quote($_[0]); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub fetch_array |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
101
|
0
|
0
|
|
|
|
|
return ref($_[0]) eq 'DBI::st' ? $_[0]->fetchrow_array() : $self->{sth}->fetchrow_array(); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub fetch_arrayref |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
107
|
0
|
0
|
|
|
|
|
return ref($_[0]) eq 'DBI::st' ? $_[0]->fetchrow_arrayref() : $self->{sth}->fetchrow_arrayref(); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub fetch_hash |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
113
|
0
|
0
|
|
|
|
|
return ref($_[0]) eq 'DBI::st' ? $_[0]->fetchrow_hashref() : $self->{sth}->fetchrow_hashref(); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub close |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
119
|
0
|
0
|
|
|
|
|
$self->{sth}->finish() if (defined $self->{sth}); |
|
120
|
0
|
0
|
|
|
|
|
$self->{dbh}->disconnect if (defined $self->{dbh}); |
|
121
|
0
|
|
|
|
|
|
return; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |