EnsEMBL/DBSQL/StatementHandle.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 75 CC 7 SCAR 21.9
CC
7
Cov
0%
dbc
12.0
sql
12.0
DESTROY
12.0
CRAP 8.9
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::DBSQL::StatementHandle
34  
35 =head1 SYNOPSIS
36  
37 Do not use this class directly. It will automatically be used by the
38 Bio::EnsEMBL::DBSQL::DBConnection class.
39  
40 =head1 DESCRIPTION
41  
42 This class extends DBD::mysql::st so that the DESTROY method may be
43 overridden. If the DBConnection::disconnect_when_inactive flag is set
44 this statement handle will cause the database connection to be closed
45 when it goes out of scope and there are no other open statement handles.
46  
47 =head1 METHODS
48  
49 =cut
50  
51 package Bio::EnsEMBL::DBSQL::StatementHandle;
52 $Bio::EnsEMBL::DBSQL::StatementHandle::VERSION = '114.0.0';
53 use vars qw(@ISA);
54 use strict;
55  
56 use Bio::EnsEMBL::Utils::Exception qw(warning throw);
57  
58 use DBI;
59  
60 #use Time::HiRes qw(time);
61  
62 @ISA = qw(DBI::st);
63  
64  
65 # As DBD::mysql::st is a tied hash can't store things in it,
66 # so have to have parallel hash
67 my %dbchash;
68 my %dbc_sql_hash;
69  
70  
71 sub dbc {
72 my $self = shift;
73  
74 if (@_) {
75 my $dbc = shift;
76 if(!defined($dbc)) {
77 # without delete key space would grow indefinitely causing mem-leak
78 delete($dbchash{$self});
79 } else {
80 $dbchash{$self} = $dbc;
81 }
82 }
83  
84 return $dbchash{$self};
85 }
86  
87 sub sql {
88 my $self = shift;
89  
90 if (@_) {
91 my $sql = shift;
92 if(!defined($sql)) {
93 # without delete key space would grow indefinitely causing mem-leak
94 delete($dbc_sql_hash{$self});
95 } else {
96 $dbc_sql_hash{$self} = $sql;
97 }
98 }
99  
100 return $dbc_sql_hash{$self};
101 }
102  
103 sub DESTROY {
104 my ($self) = @_;
105  
106 my $dbc = $self->dbc;
107 $self->dbc(undef);
108 my $sql = $self->sql;
109 $self->sql(undef);
110  
111 # Re-bless into DBI::st so that superclass destroy method is called if
112 # it exists (it does not exist in all DBI versions).
113 bless( $self, 'DBI::st' );
114  
115 # The count for the number of kids is decremented only after this
116 # function is complete. Disconnect if there is 1 kid (this one)
117 # remaining.
118 if ( $dbc
119 && $dbc->disconnect_when_inactive()
120 && $dbc->connected
121 && ( $dbc->db_handle->{Kids} == 1 ) )
122 {
123 if ( $dbc->disconnect_if_idle() ) {
124 warn("Problem disconnect $self around sql = $sql\n");
125 }
126 }
127 } ## end sub DESTROY
128  
129 1;
130  
131 # Comment out this "__END__" for printing out handy debug information
132 # (every query if you want).
133  
134 __END__