line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Header: /usr/local/CVS/perl-modules/DBIx-Wrapper-VerySimple/lib/DBIx/Wrapper/VerySimple.pm,v 1.5 2006/11/02 04:10:39 matisse Exp $ |
2
|
|
|
|
|
|
|
############################################################################### |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package DBIx::Wrapper::VerySimple; |
5
|
1
|
|
|
1
|
|
817
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
46
|
use Carp qw(cluck confess); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
69
|
|
8
|
1
|
|
|
1
|
|
6
|
use DBI; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
476
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.051; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# private instance variables |
12
|
|
|
|
|
|
|
my %DB_HANDLES = (); |
13
|
|
|
|
|
|
|
my %ARGS = (); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
7
|
|
|
7
|
1
|
514
|
my $class = shift; |
17
|
7
|
|
|
|
|
11
|
my $self = {}; |
18
|
7
|
|
|
|
|
16
|
bless $self, $class; |
19
|
7
|
|
|
|
|
21
|
$ARGS{$self} = \@_; # So we can use them to reconnect if needed |
20
|
7
|
|
33
|
|
|
29
|
$DB_HANDLES{$self} = DBI->connect(@_) |
21
|
|
|
|
|
|
|
|| confess("Could not connect using DSN: '@_'"); |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
100
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub dbh { |
27
|
1
|
|
|
1
|
1
|
5
|
my ($self) = @_; |
28
|
1
|
|
|
|
|
4
|
return $DB_HANDLES{$self}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_args { |
32
|
1
|
|
|
1
|
1
|
5
|
my ($self) = @_; |
33
|
1
|
|
|
|
|
6
|
return $ARGS{$self}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub FetchHash { ## no critic ProhibitMixedCaseVars |
37
|
3
|
|
|
3
|
1
|
1726
|
my ( $self, $sql, @bind_values ) = @_; |
38
|
3
|
100
|
|
|
|
13
|
my $sth = $DB_HANDLES{$self}->prepare_cached($sql) |
39
|
|
|
|
|
|
|
or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" ); |
40
|
2
|
100
|
|
|
|
27
|
$sth->execute(@bind_values) or confess("SQL: {$sql}"); |
41
|
1
|
|
|
|
|
12
|
my $row = $sth->fetchrow_hashref; |
42
|
1
|
|
|
|
|
9
|
$sth->finish; |
43
|
1
|
|
|
|
|
4
|
return $row; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub FetchAll { ## no critic ProhibitMixedCaseVars |
47
|
3
|
|
|
3
|
1
|
1712
|
my ( $self, $sql, @bind_values ) = @_; |
48
|
3
|
|
|
|
|
5
|
my @rows; |
49
|
3
|
100
|
|
|
|
12
|
my $sth = $DB_HANDLES{$self}->prepare_cached($sql) |
50
|
|
|
|
|
|
|
or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" ); |
51
|
2
|
100
|
|
|
|
24
|
$sth->execute(@bind_values) or confess("SQL: {$sql}"); |
52
|
1
|
|
|
|
|
13
|
while ( my $row = $sth->fetchrow_hashref ) { |
53
|
2
|
|
|
|
|
26
|
push @rows, $row; |
54
|
|
|
|
|
|
|
} |
55
|
1
|
|
|
|
|
9
|
$sth->finish; |
56
|
1
|
|
|
|
|
6
|
return \@rows; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
{ |
60
|
1
|
|
|
1
|
|
7
|
no warnings qw(once); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
746
|
|
61
|
|
|
|
|
|
|
*fetch_hash = \&FetchHash; |
62
|
|
|
|
|
|
|
*fetch_all = \&FetchAll; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub Do { ## no critic ProhibitMixedCaseVars |
66
|
3
|
|
|
3
|
1
|
1818
|
my ( $self, $sql, @bind_values ) = @_; |
67
|
3
|
100
|
|
|
|
13
|
my $sth = $DB_HANDLES{$self}->prepare_cached($sql) |
68
|
|
|
|
|
|
|
or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" ); |
69
|
2
|
100
|
|
|
|
34
|
my $result_code = $sth->execute(@bind_values) |
70
|
|
|
|
|
|
|
or confess( $DB_HANDLES{$self}->errstr, "SQL: {$sql}" ); |
71
|
1
|
|
|
|
|
15
|
$sth->finish; |
72
|
1
|
|
|
|
|
4
|
return $result_code; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub DESTROY { |
76
|
7
|
|
|
7
|
|
2745
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# warn ref $self, " executing DESTROY method. Disconnecting from database"; |
79
|
7
|
50
|
|
|
|
44
|
return $DB_HANDLES{$self}->disconnect if $DB_HANDLES{$self}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
########################################################################### |
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |