EnsEMBL/DBSQL/StatementHandle.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 72 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_50'; # TRIAL
53 $Bio::EnsEMBL::DBSQL::StatementHandle::VERSION = '114.0.050';
54 use vars qw(@ISA);
55 use strict;
56  
57 use Bio::EnsEMBL::Utils::Exception qw(warning throw);
58  
59 use DBI;
60  
61 #use Time::HiRes qw(time);
62  
63 @ISA = qw(DBI::st);
64  
65  
66 # As DBD::mysql::st is a tied hash can't store things in it,
67 # so have to have parallel hash
68 my %dbchash;
69 my %dbc_sql_hash;
70  
71  
72 sub dbc {
73 my $self = shift;
74  
75 if (@_) {
76 my $dbc = shift;
77 if(!defined($dbc)) {
78 # without delete key space would grow indefinitely causing mem-leak
79 delete($dbchash{$self});
80 } else {
81 $dbchash{$self} = $dbc;
82 }
83 }
84  
85 return $dbchash{$self};
86 }
87  
88 sub sql {
89 my $self = shift;
90  
91 if (@_) {
92 my $sql = shift;
93 if(!defined($sql)) {
94 # without delete key space would grow indefinitely causing mem-leak
95 delete($dbc_sql_hash{$self});
96 } else {
97 $dbc_sql_hash{$self} = $sql;
98 }
99 }
100  
101 return $dbc_sql_hash{$self};
102 }
103  
104 sub DESTROY {
105 my ($self) = @_;
106  
107 my $dbc = $self->dbc;
108 $self->dbc(undef);
109 my $sql = $self->sql;
110 $self->sql(undef);
111  
112 # Re-bless into DBI::st so that superclass destroy method is called if
113 # it exists (it does not exist in all DBI versions).
114 bless( $self, 'DBI::st' );
115  
116 # The count for the number of kids is decremented only after this
117 # function is complete. Disconnect if there is 1 kid (this one)
118 # remaining.
119 if ( $dbc
120 && $dbc->disconnect_when_inactive()
121 && $dbc->connected
122 && ( $dbc->db_handle->{Kids} == 1 ) )
123 {
124 if ( $dbc->disconnect_if_idle() ) {
125 warn("Problem disconnect $self around sql = $sql\n");
126 }
127 }
128 } ## end sub DESTROY
129  
130 1;
131  
132 # Comment out this "__END__" for printing out handy debug information
133 # (every query if you want).
134  
135 __END__