| 1 | package Mojar::Mysql::Connector; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use DBI 1.4.3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Mojo::Base 'DBI'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # Register subclass structure | ||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | __PACKAGE__->init_rootclass; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = 2.161; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Spec::Functions 'catfile'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Mojar::ClassShare 'have'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=18 SCAR=40.9
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | my ($pkg, %param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 17 | # Helpers | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | $param{-connector} //= 1 if exists $param{-dbh} and $param{-dbh}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
exists $param{"-dbh"} and $param{"-dbh"}
$param{"-connector"} //= 1
MC/DC50%1/2
exists $param{"-dbh"} and $param{"-dbh"}
exists $param{"-dbh"}
$param{"-dbh"}
MC/DC0%0/1
$param{"-connector"} //= 1
$param{"-connector"}
Truth table66%2/3
A and B
A= exists $param{"-dbh"}B= $param{"-dbh"}
Truth table50%1/2
A
A= $param{"-connector"}
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | if (exists $param{-connector} and my $cname = delete $param{-connector}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $param{"-connector"} and my $cname = delete $param{"-connector"}
MC/DC50%1/2
exists $param{"-connector"} and my $cname = delete $param{"-connector"}
exists $param{"-connector"}
my $cname = delete $param{"-connector"}
Truth table66%2/3
A and B
A= exists $param{"-connector"}B= my $cname = delete $param{"-connector"}
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | $cname = 'connector' if "$cname" eq '1'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | *{"${caller}::$cname"} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $self->{$cname} = (@_ > 1) ? Mojar::Mysql::Connector->new(@_) : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | return $self->{$cname} //= Mojar::Mysql::Connector->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{$cname} //= "Mojar::Mysql::Connector"->new
MC/DC0%0/2
$self->{$cname} //= "Mojar::Mysql::Connector"->new
$self->{$cname}
"Mojar::Mysql::Connector"->new
Truth table33%1/3
A //= B
A= $self->{$cname}B= "Mojar::Mysql::Connector"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | if (exists $param{-dbh} and my $hname = delete $param{-dbh}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $param{"-dbh"} and my $hname = delete $param{"-dbh"}
MC/DC0%0/2
exists $param{"-dbh"} and my $hname = delete $param{"-dbh"}
exists $param{"-dbh"}
my $hname = delete $param{"-dbh"}
Truth table33%1/3
A and B
A= exists $param{"-dbh"}B= my $hname = delete $param{"-dbh"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | $hname = 'dbh' if "$hname" eq '1'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | *{"${caller}::$hname"} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=32.4
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | $self->{$hname} = (@_ > 1) ? $self->$cname->connect(@_) : shift; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | return $self->{$hname} | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if defined $self->{$hname} and $self->{$hname}->ping; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{$hname} and $self->{$hname}->ping
MC/DC0%0/2
defined $self->{$hname} and $self->{$hname}->ping
defined $self->{$hname}
$self->{$hname}->ping
Truth table0%0/3
A and B
A= defined $self->{$hname}B= $self->{$hname}->ping
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return $self->{$hname} = $self->$cname->connect; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # Global defaults | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | if (%param and %{$pkg->Defaults}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
%param and %{$pkg->Defaults;}
MC/DC0%0/2
%param and %{$pkg->Defaults;}
%param
%{$pkg->Defaults;}
Truth table66%2/3
A and B
A= %paramB= %{$pkg->Defaults;}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | # Already have defaults => check unchanged | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # Not interested in defaults of Defaults => use hash not methods | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $ps = join ':', map +($_ .':'. ($param{$_} // 'undef')), | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$param{$_} // "undef"
MC/DC0%0/1
$param{$_} // "undef"
$param{$_}
Truth table0%0/2
A
A= $param{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | sort keys %param; | ||||||||||||||||||||||||||||||||||||||||||
| 50 | my $ds = join ':', map +($_ .':'. ($pkg->Defaults->{$_} // 'undef')), | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sort keys %{$pkg->Defaults}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$pkg->Defaults->{$_} // "undef"
MC/DC0%0/1
$pkg->Defaults->{$_} // "undef"
$pkg->Defaults->{$_}
Truth table0%0/2
A
A= $pkg->Defaults->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | die "Redefining class defaults for $pkg" unless $ps eq $ds; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | @{$pkg->Defaults}{keys %param} = values %param if %param; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | # Debugging | ||||||||||||||||||||||||||||||||||||||||||
| 56 | $pkg->trace($param{TraceLevel}) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | if exists $param{TraceLevel} and defined $param{TraceLevel}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $param{"TraceLevel"} and defined $param{"TraceLevel"}
MC/DC0%0/2
exists $param{"TraceLevel"} and defined $param{"TraceLevel"}
exists $param{"TraceLevel"}
defined $param{"TraceLevel"}
Truth table33%1/3
A and B
A= exists $param{"TraceLevel"}B= defined $param{"TraceLevel"}
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # Class attribute | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # Use a singleton object for holding use-time class defaults | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | have Defaults => sub { bless {} => ref $_[0] || $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Attributes | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | has quiesce_timeout => 500; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | my @DbdFields = qw(RaiseError PrintError PrintWarn AutoCommit TraceLevel | |||||||||||||||||||||||||||||||||||||||||
| 70 | mysql_auto_reconnect mysql_enable_utf8); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | has RaiseError => 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | has PrintError => 0; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | has PrintWarn => 0; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | has AutoCommit => 1; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | has TraceLevel => 0; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | has mysql_auto_reconnect => 0; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | has mysql_enable_utf8 => 1; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | my @ConFields = qw(label cnfdir cnf cnfgroup); | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | has 'label'; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | has cnfdir => '.'; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | has 'cnf'; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | has 'cnfgroup'; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | my @DbiFields = qw(driver host port schema user password); | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | has driver => 'mysql'; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | has 'host'; # eg 'localhost' | |||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | has 'port'; # eg 3306 | |||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | has 'schema'; # eg 'test'; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 3 | has 'user'; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | has 'password'; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # Public methods | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 5 | my ($proto, %param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 100 | # $proto may contain defaults to be cloned | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # %param may contain defaults for overriding | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | my %defaults = ref $proto ? ( %{ ref($proto)->Defaults }, %$proto ) | |||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | ▶ | : %{$proto->Defaults}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | ▶ | delete $defaults{$_} for grep { ref $proto and /^dbh\./ } keys %defaults; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $proto && /^dbh\./u
MC/DC0%0/2
ref $proto && /^dbh\./u
ref $proto
/^dbh\./u
Truth table66%2/3
A && B
A= ref $protoB= /^dbh\./u
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | return Mojo::Base::new($proto, %defaults, %param); | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my ($proto, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | @args = $proto->dsn(@args) unless @args and $args[0] =~ /^DBI:/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@args and $args[0] =~ /^DBI:/iu
MC/DC0%0/2
@args and $args[0] =~ /^DBI:/iu
@args
$args[0] =~ /^DBI:/iu
Truth table0%0/3
A and B
A= @argsB= $args[0] =~ /^DBI:/iu
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $dbh; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | eval { $dbh = $class->SUPER::connect(@args) } | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $e = $@; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | croak sprintf "Connection error\n%s\n%s", $proto->dsn_to_dump(@args), $e; | |||||||||||||||||||||||||||||||||||||||||
| 117 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return $dbh; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub connection { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connection: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my ($self, $tag) = @_; $tag //= 'connection'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$tag //= "connection"
MC/DC0%0/1
$tag //= "connection"
$tag
Truth table0%0/2
A
A= $tag
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return $self->{"dbh.$tag"} if ($self->{"dbh.$tag"} //= $self->connect)->ping; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$$self{"dbh.$tag"} //= $self->connect
MC/DC0%0/2
$$self{"dbh.$tag"} //= $self->connect
$$self{"dbh.$tag"}
$self->connect
Truth table0%0/3
A //= B
A= $$self{"dbh.$tag"}B= $self->connect
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $self->{"dbh.$tag"} = $self->connect; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | sub dsn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dsn: called CC=16 SCAR=43.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | my ($proto, %param) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | my $param = $proto->new(%param); | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | my $cnf_txt = ''; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | if (my $cnf = $param->cnf) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | # MySQL .cnf file | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | $cnf .= '.cnf' unless $cnf =~ /\.cnf$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $cnf = catfile $param->cnfdir, $cnf if ! -r $cnf and defined $param->cnfdir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not -r $cnf and defined $param->cnfdir
MC/DC0%0/2
not -r $cnf and defined $param->cnfdir
not -r $cnf
defined $param->cnfdir
Truth table0%0/3
not(A) and B
A= not -r $cnfB= defined $param->cnfdir
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | croak "Failed to find/read .cnf file ($cnf)" unless -f $cnf and -r $cnf; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $cnf and -r $cnf
MC/DC0%0/2
-f $cnf and -r $cnf
-f $cnf
-r $cnf
Truth table0%0/3
A and B
A= -f $cnfB= -r $cnf
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $cnf_txt = ';mysql_read_default_file='. $cnf; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $cnf_txt .= ';mysql_read_default_group='. $param->cnfgroup | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | if defined $param->cnfgroup; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # DBD params | ||||||||||||||||||||||||||||||||||||||||||
| 144 | # Only set private_config if it would have useful values | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | my %custom; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | defined($param->$_) and $custom{$_} = $param->$_ for qw(label cnf cnfgroup); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | my $dbd_param = %custom ? { private_config => {%custom} } : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | $dbd_param->{$_} = $param->{$_} for grep /^mysql_/, keys %$param; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | @$dbd_param{@DbdFields} = map $param->$_, @DbdFields; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 'DBI:'. $param->driver .q{:} | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | . ($param->schema // $param->{db} // '') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition40%2/5
($param->schema // $param->{"db"}) // ""
$param->schema // $param->{"db"}
MC/DC0%0/2
($param->schema // $param->{"db"}) // ""
$param->schema
$param->{"db"}
Truth table33%1/3
A // B
A= $param->schemaB= $param->{"db"}
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | . (defined $param->host ? q{;host=}. $param->host : '') | ||||||||||||||||||||||||||||||||||||||||||
| 155 | . (defined $param->port ? q{;port=}. $param->port : '') | ||||||||||||||||||||||||||||||||||||||||||
| 156 | . $cnf_txt, | ||||||||||||||||||||||||||||||||||||||||||
| 157 | $param->user, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | $param->password, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | $dbd_param | ||||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub dsn_to_dump { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dsn_to_dump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my ($proto, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | @args = $proto->dsn unless @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | # Occlude password | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ($args[2] and $_ = length $args[2] and $_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$args[2] and $_ = length $args[2] and $_ > 1
$args[2] and $_ = length $args[2]
MC/DC0%0/3
$args[2] and $_ = length $args[2] and $_ > 1
$args[2]
$_ = length $args[2]
$_ > 1
Truth table0%0/4
A and B and C
A= $args[2]B= $_ = length $args[2]C= $_ > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | --$_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $blanks = '*' x $_; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $args[2] = substr($args[2], 0, 1). $blanks; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | require Mojar::Util; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | return Mojar::Util::dumper(@args); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # ============ | ||||||||||||||||||||||||||||||||||||||||||
| 177 | package Mojar::Mysql::Connector::db; | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | @Mojar::Mysql::Connector::db::ISA = 'DBI::db'; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | ▶ | use Mojar::Util 'lc_keys'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | ▶ | use Scalar::Util 'looks_like_number'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | our $_as_hash = { Slice => {} }; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub as_hash { $_as_hash } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # Public methods | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub dsn { shift->get_info(2) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dsn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | # 2 : SQL_DATA_SOURCE_NAME | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | sub mysqld_version { shift->get_info(18) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mysqld_version: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | # 18 : SQL_DBMS_VER | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub identifier_quote { shift->get_info(29) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
identifier_quote: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | # 29 : SQL_IDENTIFIER_QUOTE_CHAR | ||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub identifier_separator { shift->get_info(41) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
identifier_separator: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | # 41 : SQL_QUALIFIER_NAME_SEPARATOR | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub async_mode { shift->get_info(10021) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
async_mode: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | # 10021 : SQL_ASYNC_MODE | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub async_max_statements { shift->get_info(10022) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
async_max_statements: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | # 10022 : SQL_MAX_ASYNC_CONCURRENT_STATEMENTS | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub thread_id { shift->{mysql_thread_id} // 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
thread_id: not called CC=2 SCAR=17.9
Condition0%0/2
+(shift())->{"mysql_thread_id"} // 0
MC/DC0%0/1
+(shift())->{"mysql_thread_id"} // 0
+(shift())->{"mysql_thread_id"}
Truth table0%0/2
A
A= +(shift())->{"mysql_thread_id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub current_schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_schema: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my ($schema) = $self->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||
| 212 | q{SELECT DATABASE()} | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return $schema; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub session_var { shift->_var('SESSION', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
session_var: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub global_var { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
global_var: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | return $self->_var(GLOBAL => @_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@_ >= 2 or @_ == 1 and $_[0] ne "have_innodb"
@_ == 1 and $_[0] ne "have_innodb"
MC/DC0%0/3
@_ >= 2 or @_ == 1 and $_[0] ne "have_innodb"
@_ >= 2
@_ == 1
$_[0] ne "have_innodb"
Truth table0%0/4
A or B and C
A= @_ >= 2B= @_ == 1C= $_[0] ne "have_innodb"
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | if @_ >= 2 or @_ == 1 and $_[0] ne 'have_innodb'; | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $variables = $self->_var('GLOBAL'); | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # Workaround for MySQL bug #59393 wrt ignore-builtin-innodb | ||||||||||||||||||||||||||||||||||||||||||
| 227 | $variables->{have_innodb} = 'NO' | ||||||||||||||||||||||||||||||||||||||||||
| 228 | if exists $variables->{ignore_builtin_innodb} | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | and ($variables->{ignore_builtin_innodb} // '') eq 'ON'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
exists $variables->{"ignore_builtin_innodb"} and ($variables->{"ignore_builtin_innodb"} // "") eq "ON"
$variables->{"ignore_builtin_innodb"} // ""
MC/DC0%0/2
exists $variables->{"ignore_builtin_innodb"} and ($variables->{"ignore_builtin_innodb"} // "") eq "ON"
exists $variables->{"ignore_builtin_innodb"}
$variables->{"ignore_builtin_innodb"}
Truth table0%0/3
A and B
A= exists $variables->{"ignore_builtin_innodb"}B= $variables->{"ignore_builtin_innodb"}
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | return $variables->{have_innodb} if @_ == 1 and $_[0] eq 'have_innodb'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and $_[0] eq "have_innodb"
MC/DC0%0/2
@_ == 1 and $_[0] eq "have_innodb"
@_ == 1
$_[0] eq "have_innodb"
Truth table0%0/3
A and B
A= @_ == 1B= $_[0] eq "have_innodb"
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return $variables; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub disable_quotes { shift->session_var(sql_quote_show_create => 0) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_quotes: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub enable_quotes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable_quotes: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | $value //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$value //= 1
MC/DC0%0/1
$value //= 1
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->session_var(sql_quote_show_create => $value) | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub disable_fk_checks { shift->session_var(foreign_key_checks => 0) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disable_fk_checks: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub enable_fk_checks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enable_fk_checks: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $value //= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$value //= 1
MC/DC0%0/1
$value //= 1
$value
Truth table0%0/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $self->session_var(foreign_key_checks => $value) | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub schemata { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schemata: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 253 | # args[0] : schema pattern | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $schemata; | |||||||||||||||||||||||||||||||||||||||||
| 255 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $sql = q{SHOW DATABASES}; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | $sql .= sprintf q{ LIKE '%s'}, $args[0] if defined $args[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $schemata = $self->selectcol_arrayref($sql, $args[1]) or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | @$schemata = grep !/^(?:\#|lost\+found)/, @$schemata; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | my $e = $@ // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ // ""
MC/DC0%0/1
$@ // ""
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | croak "Failed to list schemata\n$e"; | |||||||||||||||||||||||||||||||||||||||||
| 265 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | return $schemata; | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub tables_and_views { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables_and_views: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 271 | # args[0] : schema | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # args[1] : table pattern | ||||||||||||||||||||||||||||||||||||||||||
| 273 | # args[2] : type | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # args[3] : attr | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | $args[2] //= 'TABLE,VIEW'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args[2] //= "TABLE,VIEW"
MC/DC0%0/1
$args[2] //= "TABLE,VIEW"
$args[2]
Truth table0%0/2
A
A= $args[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $tables; | |||||||||||||||||||||||||||||||||||||||||
| 277 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | my $sth = $self->table_info('', @args); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | @$tables = map $_->[2], @{$sth->fetchall_arrayref}; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my $e = $@ // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ // ""
MC/DC0%0/1
$@ // ""
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | croak "Failed to list tables\n$e"; | |||||||||||||||||||||||||||||||||||||||||
| 285 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return $tables; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub real_tables { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
real_tables: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 291 | # args[0] : schema | ||||||||||||||||||||||||||||||||||||||||||
| 292 | # args[1] : table pattern | ||||||||||||||||||||||||||||||||||||||||||
| 293 | # args[2] : attr | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return $self->tables_and_views(@args[0,1], 'TABLE', $args[2]); | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub views { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
views: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 299 | # args[0] : schema | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # args[1] : table pattern | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # args[2] : attr | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return $self->tables_and_views(@args[0,1], 'VIEW', $args[2]); | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | sub selectall_arrayref_hashrefs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectall_arrayref_hashrefs: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my ($self, $sql, $opts, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if (defined $opts) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $opts->{Slice} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | $opts = $_as_hash; | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | return $self->selectall_arrayref($sql, $opts, @args); | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | sub selectall_lookup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
selectall_lookup: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | my $rs = $self->selectall_arrayref(@_); # ($sql, $opts, @args) | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | return undef if @$rs >= 1 and @{$$rs[0]} != 2; # wrong qty cols | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$rs >= 1 and @{$rs->[0];} != 2
MC/DC0%0/2
@$rs >= 1 and @{$rs->[0];} != 2
@$rs >= 1
@{$rs->[0];} != 2
Truth table0%0/3
A and B
A= @$rs >= 1B= @{$rs->[0];} != 2
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | return {map @$_, @$rs}; # flatten | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub threads { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
threads: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $p = shift->selectall_arrayref_hashrefs(q{SHOW FULL PROCESSLIST}); | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | @$p = map lc_keys($_), @$p; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return $p; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | sub engines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
engines: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my $engines = {}; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | my $e = $self->selectall_arrayref(q{SHOW ENGINES}); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | for (@$e) { | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ($_->[1] eq 'DEFAULT') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $engines->{default} = lc $_->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $engines->{lc $_->[0]} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $engines->{lc $_->[0]} = $_->[1] eq 'YES' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | return $engines; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub statistics { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
statistics: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | # Arbitrary query to ensure results | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ($_) = $self->selectrow_array(q{SELECT VERSION()}); | |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my $s = $self->selectall_arrayref(q{SHOW /*!50000 GLOBAL */ STATUS}); | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return lc_keys { map @$_, @$s }; | |||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub engine { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
engine: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my ($self, $schema, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $engine; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ($self->mysqld_version =~ /^(\d+)\./ and $1 >= 5) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->mysqld_version =~ /^(\d+)\./u and $1 >= 5
MC/DC0%0/2
$self->mysqld_version =~ /^(\d+)\./u and $1 >= 5
$self->mysqld_version =~ /^(\d+)\./u
$1 >= 5
Truth table0%0/3
A and B
A= $self->mysqld_version =~ /^(\d+)\./uB= $1 >= 5
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ($engine) = $self->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||
| 361 | q{SELECT ENGINE | ||||||||||||||||||||||||||||||||||||||||||
| 362 | FROM information_schema.TABLES | ||||||||||||||||||||||||||||||||||||||||||
| 363 | WHERE | ||||||||||||||||||||||||||||||||||||||||||
| 364 | TABLE_SCHEMA = ? | ||||||||||||||||||||||||||||||||||||||||||
| 365 | AND TABLE_NAME = ?}, | ||||||||||||||||||||||||||||||||||||||||||
| 366 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 367 | $schema, | ||||||||||||||||||||||||||||||||||||||||||
| 368 | $table | ||||||||||||||||||||||||||||||||||||||||||
| 369 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return $engine; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub indices { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
indices: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | my ($self, $schema, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | croak 'Missing required schema name' unless defined $schema and length $schema; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $schema and length $schema
MC/DC0%0/2
defined $schema and length $schema
defined $schema
length $schema
Truth table0%0/3
A and B
A= defined $schemaB= length $schema
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | croak 'Missing required table name' unless defined $table and length $table; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $table and length $table
MC/DC0%0/2
defined $table and length $table
defined $table
length $table
Truth table0%0/3
A and B
A= defined $tableB= length $table
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $i = $self->selectall_arrayref(sprintf( | |||||||||||||||||||||||||||||||||||||||||
| 379 | q{SHOW INDEXES FROM %s IN %s}, $table, $schema | ||||||||||||||||||||||||||||||||||||||||||
| 380 | ), $_as_hash | ||||||||||||||||||||||||||||||||||||||||||
| 381 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 382 | # $i is arrayref of hashrefs | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | lc_keys $_ for @$i; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return $i; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub table_status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_status: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ($self, $schema, $table_pattern) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | croak 'Missing required schema name' unless defined $schema and length $schema; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $schema and length $schema
MC/DC0%0/2
defined $schema and length $schema
defined $schema
length $schema
Truth table0%0/3
A and B
A= defined $schemaB= length $schema
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $sql = sprintf | |||||||||||||||||||||||||||||||||||||||||
| 391 | q{SHOW TABLE STATUS FROM %s}, $schema; | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $sql .= sprintf(q{ LIKE '%s'}, $table_pattern) if defined $table_pattern; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $s = $self->selectall_arrayref($sql, $_as_hash); | |||||||||||||||||||||||||||||||||||||||||
| 394 | # $s is arrayref of hashrefs | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | lc_keys $_ for @$s; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub engine_status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
engine_status: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my ($self, $engine) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | $engine //= 'InnoDB'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$engine //= "InnoDB"
MC/DC0%0/1
$engine //= "InnoDB"
$engine
Truth table0%0/2
A
A= $engine
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | Carp::croak "Bad engine ($engine)" unless $engine =~ /^\w+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my ($major, $minor) = ($self->mysqld_version =~ /^(\d+)\.(\d+)\./); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | my $i = $major > 5 ? 2 : $major == 5 && $minor >= 1 ? 2 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$major == 5 and $minor >= 1
MC/DC0%0/2
$major == 5 and $minor >= 1
$major == 5
$minor >= 1
Truth table0%0/3
A and B
A= $major == 5B= $minor >= 1
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | my $raw = ($self->selectrow_array( | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
($self->selectrow_array("SHOW /*!50500 ENGINE */ $engine STATUS"))[$i] // die("Failed to get engine ($engine) status\n")
MC/DC0%0/1
($self->selectrow_array("SHOW /*!50500 ENGINE */ $engine STATUS"))[$i] // die("Failed to get engine ($engine) status\n")
($self->selectrow_array("SHOW /*!50500 ENGINE */ $engine STATUS"))[$i]
Truth table0%0/2
A
A= ($self->selectrow_array("SHOW /*!50500 ENGINE */ $engine STATUS"))[$i]
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | qq{SHOW /*!50500 ENGINE */ $engine STATUS}))[$i] | ||||||||||||||||||||||||||||||||||||||||||
| 408 | // die "Failed to get engine ($engine) status\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $raw =~ s/\t/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my ($title, $buffer, $status) = ('', '', {}); | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | while ($raw =~ /^(.*)$/mg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $line = $1; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if ($line =~ /^-+$/ and length $buffer) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$line =~ /^-+$/u and length $buffer
MC/DC0%0/2
$line =~ /^-+$/u and length $buffer
$line =~ /^-+$/u
length $buffer
Truth table0%0/3
A and B
A= $line =~ /^-+$/uB= length $buffer
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | # Finish previous record | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $status->{$title} = $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $title = $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | elsif ($line =~ /^-+$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 420 | # Start new record | ||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | elsif (not length $title) { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $title = lc $line; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $title =~ s/\s+/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $title =~ s/\W//g; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | elsif ($line =~ /^=+$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $buffer .= $line . $/; | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | # Ignore final record | ||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | return $status; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | sub table_space { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table_space: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my ($self, $schema, $table) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $space; | |||||||||||||||||||||||||||||||||||||||||
| 442 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ($space) = $self->selectrow_array( | |||||||||||||||||||||||||||||||||||||||||
| 444 | q{SELECT CONCAT(TRUNCATE(DATA_FREE / 1024, 0), ' kB') | ||||||||||||||||||||||||||||||||||||||||||
| 445 | FROM information_schema.TABLES | ||||||||||||||||||||||||||||||||||||||||||
| 446 | WHERE | ||||||||||||||||||||||||||||||||||||||||||
| 447 | TABLE_SCHEMA = ? | ||||||||||||||||||||||||||||||||||||||||||
| 448 | AND TABLE_NAME = ?}, | ||||||||||||||||||||||||||||||||||||||||||
| 449 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 450 | $schema, $table | ||||||||||||||||||||||||||||||||||||||||||
| 451 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $space ne '0 kB'; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | or eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $comment = $self->table_status($schema, $table)->[0]{comment}; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | $space = $1 if $comment =~ /InnoDB free: (\d+ \w+)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | return $space; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | sub date_from_today { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date_from_today: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | my ($self, $days, $format) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | $days //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$days //= 0
MC/DC0%0/1
$days //= 0
$days
Truth table0%0/2
A
A= $days
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | $format //= '%Y-%m-%d'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$format //= "%Y-%m-%d"
MC/DC0%0/1
$format //= "%Y-%m-%d"
$format
Truth table0%0/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my ($date) = $self->selectrow_array(sprintf | |||||||||||||||||||||||||||||||||||||||||
| 466 | q{SELECT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL %s DAY), '%s')}, | ||||||||||||||||||||||||||||||||||||||||||
| 467 | $days, $format | ||||||||||||||||||||||||||||||||||||||||||
| 468 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | return $date; | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | sub quiesce { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quiesce: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | # Record existing state | ||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | my $pct = $self->global_var('innodb_max_dirty_pages_pct') | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->global_var("innodb_max_dirty_pages_pct") // die("Failed to get dirty_pages info\n")
MC/DC0%0/1
$self->global_var("innodb_max_dirty_pages_pct") // die("Failed to get dirty_pages info\n")
$self->global_var("innodb_max_dirty_pages_pct")
Truth table0%0/2
A
A= $self->global_var("innodb_max_dirty_pages_pct")
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | // die "Failed to get dirty_pages info\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | my $repl = $self->selectrow_hashref('SHOW SLAVE STATUS') // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->selectrow_hashref("SHOW SLAVE STATUS") // {}
MC/DC0%0/1
$self->selectrow_hashref("SHOW SLAVE STATUS") // {}
$self->selectrow_hashref("SHOW SLAVE STATUS")
Truth table0%0/2
A
A= $self->selectrow_hashref("SHOW SLAVE STATUS")
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | Carp::croak "Cannot quiesce while replicating" | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | if ($repl->{Slave_SQL_Running} // '') =~ /^Yes/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$repl->{"Slave_SQL_Running"} // ""
MC/DC0%0/1
$repl->{"Slave_SQL_Running"} // ""
$repl->{"Slave_SQL_Running"}
Truth table0%0/2
A
A= $repl->{"Slave_SQL_Running"}
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | # Prepare callback to un-quiesce db | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | my $cb = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | eval { $self->do('UNLOCK TABLES') }; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | $self->global_var(innodb_max_dirty_pages_pct => shift // $pct); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
shift() // $pct
MC/DC0%0/2
shift() // $pct
shift()
$pct
Truth table0%0/3
A // B
A= shift()B= $pct
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | # Quiesce | ||||||||||||||||||||||||||||||||||||||||||
| 489 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | $self->global_var(innodb_max_dirty_pages_pct => 0); | |||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $self->do('FLUSH TABLES WITH READ LOCK'); | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my ($quiesced, $count) = (0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | while (++$count < $self->quiesce_timeout) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my $state = $self->engine_status('InnoDB')->{buffer_pool_and_memory}; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if ($state =~ /^Modified db pages\s+(\d+)$/m) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | ++$quiesced, last if $1 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | die "Failed to check dirty pages\n"; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $quiesced; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | my $e = $@ // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ // ""
MC/DC0%0/1
$@ // ""
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | eval { $cb->(); }; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | die "Failed to quiesce database: $e\n"; | |||||||||||||||||||||||||||||||||||||||||
| 508 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | return $cb; | |||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | # Private method | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | sub _var { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_var: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | my ($self, $scope) = (shift, shift); | |||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | $scope //= 'SESSION'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$scope //= "SESSION"
MC/DC0%0/1
$scope //= "SESSION"
$scope
Truth table0%0/2
A
A= $scope
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | unless (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | # All vars | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | my $v = $self->selectall_arrayref(qq{SHOW $scope VARIABLES}); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | return { map @$_, @$v }; | |||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my $var = shift; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | unless (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | # Getter | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my ($value) = $self->selectrow_array(sprintf | |||||||||||||||||||||||||||||||||||||||||
| 528 | q{SELECT @@%s.%s}, $scope, $var); | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | # Setter | ||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my ($old, $new); | |||||||||||||||||||||||||||||||||||||||||
| 535 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ($old) = $self->selectrow_array(sprintf | |||||||||||||||||||||||||||||||||||||||||
| 537 | q{SELECT @@%s.%s}, $scope, $var); | ||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | $value = "'$value'" unless looks_like_number $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $self->do(qq{SET $scope $var = $value}); | |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ($new) = $self->selectrow_array(sprintf | |||||||||||||||||||||||||||||||||||||||||
| 541 | q{SELECT @@%s.%s}, $scope, $var); | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | my $e = $@ // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ // ""
MC/DC0%0/1
$@ // ""
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | croak "Failed to set var ($var)\n$e"; | |||||||||||||||||||||||||||||||||||||||||
| 547 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | return wantarray ? ($old, $new) : $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | #TODO: clean up this ancient code | ||||||||||||||||||||||||||||||||||||||||||
| 552 | #sub insert_hash { | ||||||||||||||||||||||||||||||||||||||||||
| 553 | # my ($self, $schema, $table, $field_map) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 554 | # my @fields = keys %$field_map; | ||||||||||||||||||||||||||||||||||||||||||
| 555 | # my @values = values %$field_map; | ||||||||||||||||||||||||||||||||||||||||||
| 556 | # $self->do(sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 557 | #q{INSERT INTO %s.%s (%s) VALUES (%s)}, | ||||||||||||||||||||||||||||||||||||||||||
| 558 | # $schema, | ||||||||||||||||||||||||||||||||||||||||||
| 559 | # $table, | ||||||||||||||||||||||||||||||||||||||||||
| 560 | # join(q{,}, @fields), | ||||||||||||||||||||||||||||||||||||||||||
| 561 | # join(q{,}, '?' x @fields)), | ||||||||||||||||||||||||||||||||||||||||||
| 562 | # undef, | ||||||||||||||||||||||||||||||||||||||||||
| 563 | # @values | ||||||||||||||||||||||||||||||||||||||||||
| 564 | # ); | ||||||||||||||||||||||||||||||||||||||||||
| 565 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | #TODO: clean up this ancient code | ||||||||||||||||||||||||||||||||||||||||||
| 568 | #sub search_hash { | ||||||||||||||||||||||||||||||||||||||||||
| 569 | # my ($self, $schema, $table, $field_map, @columns) = @_; | ||||||||||||||||||||||||||||||||||||||||||
| 570 | # my @fields = keys %$field_map; | ||||||||||||||||||||||||||||||||||||||||||
| 571 | # my @values = values %$field_map; | ||||||||||||||||||||||||||||||||||||||||||
| 572 | # my $wanted = scalar(@columns) ? join q{, }, @columns : q{*}; | ||||||||||||||||||||||||||||||||||||||||||
| 573 | # my $where = ''; | ||||||||||||||||||||||||||||||||||||||||||
| 574 | # $where = q{WHERE }. join q{ AND }, map '$_ = ?', @fields if @fields; | ||||||||||||||||||||||||||||||||||||||||||
| 575 | # $self->selectall_arrayref(sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 576 | #q{SELECT %s FROM %s.%s %s}, | ||||||||||||||||||||||||||||||||||||||||||
| 577 | # $wanted, $schema, $table, $where), | ||||||||||||||||||||||||||||||||||||||||||
| 578 | # undef, | ||||||||||||||||||||||||||||||||||||||||||
| 579 | # @values | ||||||||||||||||||||||||||||||||||||||||||
| 580 | # ); | ||||||||||||||||||||||||||||||||||||||||||
| 581 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | # ============ | ||||||||||||||||||||||||||||||||||||||||||
| 584 | package Mojar::Mysql::Connector::st; | ||||||||||||||||||||||||||||||||||||||||||
| 585 | 3 | @Mojar::Mysql::Connector::st::ISA = 'DBI::st'; | |||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 588 | __END__ | ||||||||||||||||||||||||||||||||||||||||||