Bio::EnsEMBL::DBSQL
StatementHandle
Toolbar
Summary
Bio::EnsEMBL::DBSQL::StatementHandle
Package variables
Privates (from "my" definitions)
%total_time;
$grand_total;
@bind_args = ()
%max_time;
$dump = 0
%min_time;
%number_of_times;
%dbchash;
%first_time;
%dbc_sql_hash;
Included modules
DBD::mysql
DBI
Time::HiRes qw ( time )
Inherit
DBI::st
Synopsis
Do not use this class directly. It will automatically be used by the
Bio::EnsEMBL::DBSQL::DBConnection class.
Description
This class extends DBD::mysql::st so that the DESTROY method may be
overridden. If the DBConnection::disconnect_when_inactive flag is set
this statement handle will cause the database connection to be closed
when it goes out of scope and there are no other open statement handles.
Methods
DESTROY | No description | Code |
bind_param | No description | Code |
dbc | No description | Code |
execute | No description | Code |
sql | No description | Code |
sql_timing_print | No description | Code |
sql_timing_resume | No description | Code |
sql_timing_start | No description | Code |
Methods description
None available.
Methods code
sub DESTROY
{ my ($self) = @_;
my $dbc = $self->dbc;
$self->dbc(undef);
my $sql = $self->sql;
$self->sql(undef);
bless( $self, 'DBI::st' );
if ( $dbc
&& $dbc->disconnect_when_inactive()
&& $dbc->connected
&& ( $dbc->db_handle->{Kids} == 1 ) )
{
if ( $dbc->disconnect_if_idle() ) {
warn("Problem disconnect $self around sql = $sql\n");
}
}
}
1;
__END__
use Time::HiRes qw(time);
my @bind_args = ();
my $dump = 0;
my %total_time;
my %min_time;
my %max_time;
my %number_of_times;
my %first_time;
my $grand_total; } |
sub bind_param
{ my ( $self, @args ) = @_;
$bind_args[ $args[0] - 1 ] = $args[1];
$self->SUPER::bind_param(@args); } |
sub dbc
{ my $self = shift;
if (@_) {
my $dbc = shift;
if(!defined($dbc)) {
delete($dbchash{$self});
} else {
$dbchash{$self} = $dbc;
}
}
return $dbchash{$self}; } |
sub execute
{ my ( $self, @args ) = @_;
my $retval;
if ( !$dump ) {
{
local $self->{RaiseError};
$retval = $self->SUPER::execute(@args);
if (!defined($retval)) {
throw("Failed to execute SQL statement");
}
return $retval;
}
}
my $sql = $self->sql();
my @chrs = split( //, $sql );
my $j = 0;
for ( my $i = 0 ; $i < @chrs ; $i++ ) {
if ( $chrs[$i] eq '?' && defined( $bind_args[$j] ) ) {
$chrs[$i] = $bind_args[ $j++ ];
}
}
my $str = join( '', @chrs );
my $time = time();
{
local $self->{RaiseError};
$retval = $self->SUPER::execute(@args);
if (!defined($retval)) {
throw("Failed to execute SQL statement");
}
}
$time = time() - $time;
if ( defined( $total_time{$sql} ) ) {
$total_time{$sql} += $time;
$number_of_times{$sql}++;
if ( $min_time{$sql} > $time ) { $min_time{$sql} = $time }
if ( $max_time{$sql} < $time ) { $max_time{$sql} = $time }
} else {
$first_time{$sql} = $time;
$max_time{$sql} = $time;
$min_time{$sql} = $time;
$total_time{$sql} = $time;
$number_of_times{$sql} = 1;
}
return $retval;
}
1; } |
sub sql
{ my $self = shift;
if (@_) {
my $sql = shift;
if(!defined($sql)) {
delete($dbc_sql_hash{$self});
} else {
$dbc_sql_hash{$self} = $sql;
}
}
return $dbc_sql_hash{$self}; } |
sub sql_timing_print
{ my ( $self, $level, $fh ) = @_;
my $grand_total = 0;
if ( !defined($fh) ) {
$fh =\* STDERR;
}
print( ref($fh), "\n" );
foreach my $key ( keys %total_time ) {
$grand_total += $total_time{$key};
if ( !( defined($level) and $level ) ) { next }
print( $fh $key, "\n" );
print( $fh
"total\t\t num\tfirst\t\t avg\t\t [min ,max ]\n" );
printf( $fh "%6f\t%d\t%6f\t%6f\t[%6f, %6f]\n\n",
$total_time{$key},
$number_of_times{$key},
$first_time{$key},
( $total_time{$key}/$number_of_times{$key} ), $min_time{$key}, $max_time{$key} ); }
printf( $fh "\ntotal time %6f\n\n", $grand_total );
}
} |
sub sql_timing_resume
{ $dump = 1 } |
sql_timing_start | description | prev | next | Top |
sub sql_timing_start
{ %total_time = ();
%number_of_times = ();
%min_time = ();
%max_time = ();
%first_time = ();
$dump = 1; } |
General documentation
Copyright (c) 1999-2009 The European Bioinformatics Institute and
Genome Research Limited. All rights reserved.
This software is distributed under a modified Apache license.
For license details, please see
/info/about/code_licence.html