blib/lib/DBIO/MySQL/Introspect/Tables.pm

filter: Statementstmt 37.9% 11 / 29 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 25.4% 15 / 59 CC 11 SCAR 46.4
CC
11
Cov
22%
fetch
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 103.9
« blib/lib/DBIO/MySQL/Test/Conformance.pm ↑ Summary xbin/dbio-mysql-k8s »
1 package DBIO::MySQL::Introspect::Tables;
2 # ABSTRACT: Introspect MySQL/MariaDB tables and views
3  
4 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 42 our $VERSION = '0.900007';
8  
9 42 ▶use DBIO::MySQL::Identifier qw(quote_ident);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12  
13 0 ▶sub fetch {
Subroutine fetch: not called CC=11 SCAR=48.8
Pod documented
14 0 my ($class, $dbh) = @_;
15  
16 0 my $sth = $dbh->prepare(q{
17 SELECT
18 table_name AS name,
19 table_type AS table_type,
20 engine AS engine,
21 table_collation AS table_collation,
22 row_format AS row_format,
23 table_comment AS comment
24 FROM information_schema.tables
25 WHERE table_schema = DATABASE()
26 ORDER BY table_name
27 });
28 0 $sth->execute;
29  
30 0 my %tables;
31 0 ▶ while (my $row = $sth->fetchrow_hashref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
32 0 ▶ my $kind = ($row->{table_type} // '') eq 'VIEW' ? 'view' : 'table';
Branch: 1 branch
BranchTrueFalseTotal
($row->{'table_type'} // '') eq 'VIEW' ? : 0 0 0
Condition0%0/2
$row->{"table_type"} // ""
l!l
00
MC/DC0%0/1
$row->{"table_type"} // ""
$row->{"table_type"}
Truth table0%0/2
A
A= $row->{"table_type"}
Aresult
11
00
33 $tables{ $row->{name} } = {
34 table_name => $row->{name},
35 kind => $kind,
36 engine => $row->{engine},
37 table_collation => $row->{table_collation},
38 row_format => $row->{row_format},
39 comment => $row->{comment},
40 0 };
41 }
42  
43 # The definition of every view, without the name of this database in front
44 # of the names the server qualified (see above).
45 0 ▶ if (grep { $_->{kind} eq 'view' } values %tables) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_->{"kind"} eq "view";} values %tables) 0 0 0
46 0 my ($database) = $dbh->selectrow_array('SELECT DATABASE()');
47 0 ▶ my $qualifier = defined $database ? quote_ident($database) . '.' : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $database ? : 0 0 0
48 0 my $views = $dbh->selectall_arrayref(
49 q{SELECT table_name, view_definition FROM information_schema.views
50 WHERE table_schema = DATABASE()});
51 0 for my $view (@$views) {
52 0 my ($name, $def) = @$view;
53 0 ▶ next unless $tables{$name} && $tables{$name}{kind} eq 'view';
Branch: 1 branch
BranchTrueFalseTotal
unless $tables{$name} and $tables{$name}{"kind"} eq "view" 0 0 0
Condition0%0/3
$tables{$name} and $tables{$name}{"kind"} eq "view"
!ll&&!rl&&r
000
MC/DC0%0/2
$tables{$name} and $tables{$name}{"kind"} eq "view"
$tables{$name} $tables{$name}{"kind"} eq "view"
Truth table0%0/3
A and B
A= $tables{$name}B= $tables{$name}{"kind"} eq "view"
ABresult
0X0
100
111
54 0 ▶ $def =~ s/\Q$qualifier\E//g if defined $def && length $qualifier;
Branch: 1 branch
BranchTrueFalseTotal
if defined $def and length $qualifier 0 0 0
Condition0%0/3
defined $def and length $qualifier
!ll&&!rl&&r
000
MC/DC0%0/2
defined $def and length $qualifier
defined $def length $qualifier
Truth table0%0/3
A and B
A= defined $defB= length $qualifier
ABresult
0X0
100
111
55 0 $tables{$name}{view_definition} = $def;
56 }
57 }
58 0 return \%tables;
59 }
60  
61 42 1;
62  
63 __END__
« blib/lib/DBIO/MySQL/Test/Conformance.pm ↑ Summary xbin/dbio-mysql-k8s »