1
# This program is copyright 2013 Percona Ireland Ltd.
2
# Feedback and improvements are welcome.
4
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
5
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
6
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
8
# This program is free software; you can redistribute it and/or modify it under
9
# the terms of the GNU General Public License as published by the Free Software
10
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
11
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16
# Place, Suite 330, Boston, MA 02111-1307 USA.
17
# ###########################################################################
18
# EventExecutor package
19
# ###########################################################################
21
package EventExecutor;
24
use warnings FATAL => 'all';
25
use English qw(-no_match_vars);
26
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
28
use Time::HiRes qw(time);
33
has 'default_database' => (
47
default => sub { return {} },
51
my ($self, %args) = @_;
52
my @required_args = qw(host event);
53
foreach my $arg ( @required_args ) {
54
die "I need a $arg argument" unless $args{$arg};
56
my $host = $args{host};
57
my $event = $args{event};
67
my $db = $event->{db} || $event->{Schema} || $self->default_database;
68
if ( $db && (!$host->{current_db} || $host->{current_db} ne $db) ) {
69
PTDEBUG && _d('New current db:', $db);
70
$host->dbh->do("USE `$db`");
71
$host->{current_db} = $db;
73
my $sth = $host->dbh->prepare($event->{arg});
77
$results->{query_time} = sprintf('%.6f', $t1);
78
$results->{sth} = $sth;
79
$results->{warnings} = $self->get_warnings(dbh => $host->dbh);
81
if ( my $e = $EVAL_ERROR ) {
84
$e =~ s/ at \S+ line \d+, \S+ line \d+\.$//;
85
$results->{error} = $e;
87
PTDEBUG && _d('Result on', $host->name, Dumper($results));
92
my ($self, %args) = @_;
93
my @required_args = qw(dbh);
94
foreach my $arg ( @required_args ) {
95
die "I need a $arg argument" unless $args{$arg};
98
my $warnings = $dbh->selectall_hashref('SHOW WARNINGS', 'code');
103
my ($package, undef, $line) = caller 0;
104
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
105
map { defined $_ ? $_ : 'undef' }
107
print STDERR "# $package:$line $PID ", join(' ', @_), "\n";
113
# ###########################################################################
114
# End EventExecutor package
115
# ###########################################################################