Wizard/DB/Table.pm

filter: Statementstmt 53.0% 35 / 66 Branchbran 39.2% 11 / 28 Conditioncond 24.0% 6 / 25 MC/DCmcdc 15.3% 2 / 13 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 5 totaltotal 40.6% 59 / 145 CC 27 SCAR 41.1
CC
27
Cov
44%
time_columns_href
156.0
decimal_columns_href
20.0
desc
11.1
CRAP 61.0
↑ Summary Wizard/ResultSet.pm »
1 package DBIx::Wizard::DB::Table;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use DBIx::Wizard::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 my %h_desc;
7 my %h_auto_pk;
8 11 my %h_time_columns_href;
9 11 my %h_decimal_columns_href;
10  
11 9 ▶sub desc {
Subroutine desc: called CC=9 SCAR=24.0
Pod undocumented
12 9 my ($class, $db, $table) = @_;
13  
14 9 ▶ if (exists $h_desc{$db}{$table}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h_desc{$db}{$table}) 0 9 9
15 0 return $h_desc{$db}{$table};
16 }
17  
18 9 my $dbh = DBIx::Wizard::DB->dbh($db);
19 9 my $driver = $dbh->{Driver}->{Name};
20  
21 9 my ($sth, $ra_desc);
22  
23 9 ▶ if ($driver eq 'SQLite') {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver eq 'SQLite') { } 9 0 9
24 9 $sth = $dbh->prepare("PRAGMA table_info($table)");
25 9 $sth->execute();
26 9 my $ra_pragma = $sth->fetchall_arrayref({});
27 # Normalize to MySQL-like format: Field, Type, Null, Key, Default, Extra
28 9 $ra_desc = [ map {{
29 Field => $_->{name},
30 Type => lc($_->{type} || ''),
31 Null => $_->{notnull} ? 'NO' : 'YES',
32 Key => $_->{pk} ? 'PRI' : '',
33 Default => $_->{dflt_value},
34 36 ▶ Extra => ($_->{pk} && lc($_->{type} || '') eq 'integer') ? 'auto_increment' : '',
Branch: 3 branches
BranchTrueFalseTotal
$_->{'notnull'} ? : 0 36 36
$_->{'pk'} ? : 9 27 36
$_->{'pk'} && lc($_->{'type'} || '') eq 'integer' ? : 9 27 36
Condition57%4/7
$_->{'type'} || ''
l!l
360
$_->{"pk"} and lc($_->{"type"} || "") eq "integer"
!ll&&!rl&&r
2709
$_->{'type'} || ''
l!l
90
MC/DC50%1/2
$_->{"pk"} and lc($_->{"type"} || "") eq "integer"
$_->{"pk"} $_->{'type'}
Truth table66%2/3
A and B
A= $_->{"pk"}B= $_->{'type'}
ABresult
0X0
100
111
35 }} @$ra_pragma ];
36 } else {
37 0 $sth = $dbh->prepare("DESC " . $table);
38 0 $sth->execute();
39 0 $ra_desc = $sth->fetchall_arrayref({});
40 }
41  
42 9 $h_desc{$db}{$table} = $ra_desc;
43  
44 9 return $ra_desc;
45 }
46  
47 0 ▶sub column_names {
Subroutine column_names: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my ($class, $db, $table) = @_;
49  
50 0 my $ra_desc = $class->desc($db, $table);
51  
52 0 return map { $_->{Field} } @$ra_desc;
53 }
54  
55 27 ▶sub auto_pk {
Subroutine auto_pk: called CC=4 SCAR=13.9
Pod undocumented
56 27 my ($class, $db, $table) = @_;
57  
58 27 ▶ if (exists $h_auto_pk{$db}{$table}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h_auto_pk{$db}{$table}) 18 9 27
59 18 return $h_auto_pk{$db}{$table};
60 }
61  
62 9 my $ra_desc = $class->desc($db, $table);
63  
64 9 my $auto_pk;
65  
66 9 for my $rh_column_info (@$ra_desc) {
67 36 ▶ if (_is_auto_pk_column($rh_column_info)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_auto_pk_column($rh_column_info)) 9 27 36
68 9 $auto_pk = $rh_column_info->{Field};
69 }
70 }
71  
72 9 $h_auto_pk{$db}{$table} = $auto_pk;
73  
74 9 return $auto_pk;
75 }
76  
77 36 ▶sub _is_auto_pk_column {
Subroutine _is_auto_pk_column: called CC=2 SCAR=7.1
78 36 my $rh_column_info = shift;
79  
80 return exists $rh_column_info->{Extra} &&
81 36 ▶ $rh_column_info->{Extra} eq 'auto_increment';
Condition66%2/3
exists $rh_column_info->{'Extra'} && $rh_column_info->{'Extra'} eq 'auto_increment'
!ll&&!rl&&r
0279
MC/DC50%1/2
exists $rh_column_info->{'Extra'} && $rh_column_info->{'Extra'} eq 'auto_increment'
exists $rh_column_info->{'Extra'} $rh_column_info->{'Extra'} eq 'auto_increment'
Truth table66%2/3
A && B
A= exists $rh_column_info->{'Extra'}B= $rh_column_info->{'Extra'} eq 'auto_increment'
ABresult
0X0
100
111
82 }
83  
84 0 ▶sub time_columns_href {
Subroutine time_columns_href: not called CC=12 SCAR=50.5
Pod undocumented
85 0 my ($class, $db, $table) = @_;
86  
87 0 ▶ if (exists $h_time_columns_href{$db}{$table}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h_time_columns_href{$db}{$table}) 0 0 0
88 0 return $h_time_columns_href{$db}{$table};
89 }
90  
91 0 my $ra_desc = $class->desc($db, $table);
92  
93 0 my $rh_time_columns = {};
94  
95 0 for my $rh_column_info (@$ra_desc) {
96 0 ▶ if (exists $rh_column_info->{Type} && exists $rh_column_info->{Field}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $rh_column_info->{'Type'} and exists $rh_column_info->{'Field'}) { } 0 0 0
elsif (exists $rh_column_info->{'type'} and exists $rh_column_info->{'name'}) { } 0 0 0
Condition0%0/3
exists $rh_column_info->{"Type"} and exists $rh_column_info->{"Field"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rh_column_info->{"Type"} and exists $rh_column_info->{"Field"}
exists $rh_column_info->{"Type"} exists $rh_column_info->{"Field"}
Truth table0%0/3
A and B
A= exists $rh_column_info->{"Type"}B= exists $rh_column_info->{"Field"}
ABresult
0X0
100
111
97 0 ▶ if ($rh_column_info->{Type} eq 'datetime' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($rh_column_info->{"Type"} eq "datetime" or $rh_column_info->{"Type"} eq "date" or $rh_column_info->{"Type"} eq "timestamp") 0 0 0
Condition0%0/6
$rh_column_info->{"Type"} eq "datetime" or $rh_column_info->{"Type"} eq "date" or $rh_column_info->{"Type"} eq "timestamp"
l!l&&r!l&&!r
000
$rh_column_info->{"Type"} eq "datetime" or $rh_column_info->{"Type"} eq "date"
l!l&&r!l&&!r
000
MC/DC0%0/3
$rh_column_info->{"Type"} eq "datetime" or $rh_column_info->{"Type"} eq "date" or $rh_column_info->{"Type"} eq "timestamp"
$rh_column_info->{"Type"} eq "datetime" $rh_column_info->{"Type"} eq "date" $rh_column_info->{"Type"} eq "timestamp"
Truth table0%0/4
A or B or C
A= $rh_column_info->{"Type"} eq "datetime"B= $rh_column_info->{"Type"} eq "date"C= $rh_column_info->{"Type"} eq "timestamp"
ABCresult
1XX1
01X1
0011
0000
98 $rh_column_info->{Type} eq 'date' ||
99 $rh_column_info->{Type} eq 'timestamp') {
100 0 $rh_time_columns->{$rh_column_info->{Field}} = $rh_column_info->{Type};
101 }
102 ▶ } elsif (exists $rh_column_info->{type} && exists $rh_column_info->{name}) {
Condition0%0/3
exists $rh_column_info->{"type"} and exists $rh_column_info->{"name"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rh_column_info->{"type"} and exists $rh_column_info->{"name"}
exists $rh_column_info->{"type"} exists $rh_column_info->{"name"}
Truth table0%0/3
A and B
A= exists $rh_column_info->{"type"}B= exists $rh_column_info->{"name"}
ABresult
0X0
100
111
103 ## ClickHouse 22+ via MySQL interface
104 0 ▶ if ($rh_column_info->{type} eq 'DateTime' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($rh_column_info->{"type"} eq "DateTime" or $rh_column_info->{"type"} eq "Date") 0 0 0
Condition0%0/3
$rh_column_info->{"type"} eq "DateTime" or $rh_column_info->{"type"} eq "Date"
l!l&&r!l&&!r
000
MC/DC0%0/2
$rh_column_info->{"type"} eq "DateTime" or $rh_column_info->{"type"} eq "Date"
$rh_column_info->{"type"} eq "DateTime" $rh_column_info->{"type"} eq "Date"
Truth table0%0/3
A or B
A= $rh_column_info->{"type"} eq "DateTime"B= $rh_column_info->{"type"} eq "Date"
ABresult
1X1
011
000
105 $rh_column_info->{type} eq 'Date') {
106 0 $rh_time_columns->{$rh_column_info->{name}} = lc($rh_column_info->{type});
107 }
108 }
109 }
110  
111 0 $h_time_columns_href{$db}{$table} = $rh_time_columns;
112  
113 0 return $rh_time_columns;
114 }
115  
116 0 ▶sub decimal_columns_href {
Subroutine decimal_columns_href: not called CC=4 SCAR=30.0
Pod undocumented
117 0 my ($class, $db, $table) = @_;
118  
119 0 ▶ if (exists $h_decimal_columns_href{$db}{$table}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $h_decimal_columns_href{$db}{$table}) 0 0 0
120 0 return $h_decimal_columns_href{$db}{$table};
121 }
122  
123 0 my $ra_desc = $class->desc($db, $table);
124  
125 0 my $rh_decimal_columns = {};
126  
127 0 for my $rh_column_info (@$ra_desc) {
128 0 ▶ if ($rh_column_info->{Type} =~ m/decimal/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rh_column_info->{"Type"} =~ /decimal/i) 0 0 0
129 0 $rh_decimal_columns->{$rh_column_info->{Field}} = $rh_column_info->{Type};
130 }
131 }
132  
133 0 $h_decimal_columns_href{$db}{$table} = $rh_decimal_columns;
134  
135 0 return $rh_decimal_columns;
136 }
137  
138 11 1;
↑ Summary Wizard/ResultSet.pm »