DB2/Storage/Cursor.pm

filter: Statementstmt 96.1% 50 / 52 Branchbran 65.0% 13 / 20 Conditioncond 50.0% 12 / 24 MC/DCmcdc 35.7% 5 / 14 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 75.2% 91 / 121 CC 23 SCAR 25.8
CC
23
Cov
78%
all
21.1
decode_rows
14.1
next
2.0
CRAP 13.2
« DB2/Diff/View.pm ↑ Summary DB2/Introspect/Columns.pm »
1 package DBIO::DB2::Storage::Cursor;
2 # ABSTRACT: Reads the character columns of a Db2 result as characters and its decimals with a point
3  
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 our $VERSION = '0.900007';
8  
9 15 ▶use base 'DBIO::Storage::DBI::Cursor';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 15 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶use DBIO::Util qw(shuffle_unordered_resultsets);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 # the TYPE the DBD reports for a numeric column with a fraction: SQL_NUMERIC,
16 # SQL_DECIMAL, SQL_FLOAT, SQL_REAL, SQL_DOUBLE and the CLI code of DECFLOAT
17 15 my %FRACTIONAL_TYPE = map { $_ => 1 } (2, 3, 6, 7, 8, -360);
18  
19 # the TYPE the DBD reports for a character column: SQL_CHAR, SQL_VARCHAR,
20 # SQL_LONGVARCHAR, the wide forms, and the CLI codes of CLOB and DBCLOB
21 15 my %CHARACTER_TYPE = map { $_ => 1 } (1, 12, -1, -8, -9, -10, -99, -350, 40);
22  
23  
24 44 ▶sub decode_rows {
Subroutine decode_rows: called CC=14 SCAR=26.5
Pod documented
25 44 my ($class, $storage, $sth, @rows) = @_;
26 44 ▶ return unless $sth;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth 0 44 44
27  
28 44 ▶ my $types = $sth->{TYPE} || [];
Condition100%2/2
$sth->{'TYPE'} || []
l!l
368
MC/DC100%1/1
$sth->{'TYPE'} || []
$sth->{'TYPE'}
Truth table100%2/2
A
A= $sth->{'TYPE'}
Aresult
11
00
29 44 ▶ my @numbers = grep { $FRACTIONAL_TYPE{ $types->[$_] // '' } } 0 .. $#$types;
Condition50%1/2
$types->[$_] // ""
l!l
590
MC/DC0%0/1
$types->[$_] // ""
$types->[$_]
Truth table50%1/2
A
A= $types->[$_]
Aresult
11
00
30 my @chars = $storage->_utf8_database
31 44 ▶ ? grep { $CHARACTER_TYPE{ $types->[$_] // '' } } 0 .. $#$types
Branch: 1 branch
BranchTrueFalseTotal
$storage->_utf8_database ? : 21 23 44
Condition50%1/2
$types->[$_] // ""
l!l
350
MC/DC0%0/1
$types->[$_] // ""
$types->[$_]
Truth table50%1/2
A
A= $types->[$_]
Aresult
11
00
32 : ();
33 44 ▶ return unless @numbers || @chars;
Branch: 1 branch
BranchTrueFalseTotal
unless @numbers or @chars 11 33 44
Condition100%3/3
@numbers or @chars
l!l&&r!l&&!r
28511
MC/DC100%2/2
@numbers or @chars
@numbers @chars
Truth table100%3/3
A or B
A= @numbersB= @chars
ABresult
1X1
011
000
34  
35 33 for my $row (@rows) {
36 35 for my $i (@numbers) {
37 # exactly one comma, no grouping: the form the CLI writes under a
38 # locale with a decimal comma
39 33 ▶ $row->[$i] =~ tr/,/./
Branch: 1 branch
BranchTrueFalseTotal
if defined $row->[$i] and $row->[$i] =~ /\A[-+]?\d*,\d*(?:[Ee][-+]?\d+)?\z/ 27 6 33
Condition100%3/3
defined $row->[$i] and $row->[$i] =~ /\A[-+]?\d*,\d*(?:[Ee][-+]?\d+)?\z/
!ll&&!rl&&r
2427
MC/DC100%2/2
defined $row->[$i] and $row->[$i] =~ /\A[-+]?\d*,\d*(?:[Ee][-+]?\d+)?\z/
defined $row->[$i] $row->[$i] =~ /\A[-+]?\d*,\d*(?:[Ee][-+]?\d+)?\z/
Truth table100%3/3
A and B
A= defined $row->[$i]B= $row->[$i] =~ /\A[-+]?\d*,\d*(?:[Ee][-+]?\d+)?\z/
ABresult
0X0
100
111
40 if defined $row->[$i] && $row->[$i] =~ /\A[-+]?\d*,\d*(?:[Ee][-+]?\d+)?\z/;
41 }
42 35 for my $i (@chars) {
43 11 ▶ utf8::decode($row->[$i]) if defined $row->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if defined $row->[$i] 9 2 11
44 }
45 }
46 33 return;
47 }
48  
49  
50 3 ▶sub next {
Subroutine next: called CC=2 SCAR=7.0
Pod documented
51 3 my $self = shift;
52 3 my @row = $self->next::method(@_);
53 3 ▶ return @row unless @row;
Branch: 1 branch
BranchTrueFalseTotal
unless @row 0 3 3
54 3 $self->decode_rows($self->storage, $self->sth, \@row);
55 3 return @row;
56 }
57  
58  
59 2 ▶sub all {
Subroutine all: called CC=9 SCAR=30.5
Pod documented
60 2 my $self = shift;
61  
62 # with a software limit core's all goes through next
63 return $self->next::method(@_)
64 if $self->{attrs}{software_limit}
65 2 ▶ && ($self->{attrs}{offset} || $self->{attrs}{rows});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"attrs"}{"software_limit"} and $self->{"attrs"}{"offset"} || $self->{"attrs"}{"rows"} 0 2 2
Condition16%1/6
$self->{"attrs"}{"software_limit"} and $self->{"attrs"}{"offset"} || $self->{"attrs"}{"rows"}
!ll&&!rl&&r
200
$self->{"attrs"}{"offset"} or $self->{"attrs"}{"rows"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"attrs"}{"software_limit"} and $self->{"attrs"}{"offset"} || $self->{"attrs"}{"rows"}
$self->{"attrs"}{"software_limit"} $self->{"attrs"}{"offset"} $self->{"attrs"}{"rows"}
Truth table25%1/4
A and B or C
A= $self->{"attrs"}{"software_limit"}B= $self->{"attrs"}{"offset"}C= $self->{"attrs"}{"rows"}
ABCresult
0XX0
1000
11X1
1011
66  
67 2 my $sth;
68 2 ▶ if ($sth = $self->sth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth = $self->sth) 0 2 2
69 0 ▶ $sth->finish if ( ! $self->{_done} and $sth->FETCH('Active') );
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"_done"} and $sth->FETCH("Active") 0 0 0
Condition0%0/3
not $self->{"_done"} and $sth->FETCH("Active")
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"_done"} and $sth->FETCH("Active")
not $self->{"_done"} $sth->FETCH("Active")
Truth table0%0/3
not(A) and B
A= not $self->{"_done"}B= $sth->FETCH("Active")
ABresult
0X0
100
111
70 0 $self->sth(undef);
71 }
72  
73 2 (undef, $sth) = $self->storage->_select( @{$self->{args}} );
74  
75 2 my @rows = @{ $sth->fetchall_arrayref };
76 2 $self->decode_rows($self->storage, $sth, @rows);
77 return (shuffle_unordered_resultsets and ! $self->{attrs}{order_by})
78 2 ▶ ? List::Util::shuffle(@rows)
Branch: 1 branch
BranchTrueFalseTotal
&shuffle_unordered_resultsets() && !$self->{'attrs'}{'order_by'} ? : 0 2 2
Condition33%1/3
&shuffle_unordered_resultsets() and not $self->{"attrs"}{"order_by"}
!ll&&!rl&&r
200
MC/DC0%0/2
&shuffle_unordered_resultsets() and not $self->{"attrs"}{"order_by"}
&shuffle_unordered_resultsets() not $self->{"attrs"}{"order_by"}
Truth table33%1/3
A and not(B)
A= &shuffle_unordered_resultsets()B= not $self->{"attrs"}{"order_by"}
ABresult
0X0
100
111
79 : @rows;
80 }
81  
82 15 1;
83  
84 __END__
« DB2/Diff/View.pm ↑ Summary DB2/Introspect/Columns.pm »