| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 44 | ▶ | my $types = $sth->{TYPE} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$sth->{'TYPE'} || []
MC/DC100%1/1
$sth->{'TYPE'} || []
$sth->{'TYPE'}
Truth table100%2/2
A
A= $sth->{'TYPE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 44 | ▶ | my @numbers = grep { $FRACTIONAL_TYPE{ $types->[$_] // '' } } 0 .. $#$types; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$types->[$_] // ""
MC/DC0%0/1
$types->[$_] // ""
$types->[$_]
Truth table50%1/2
A
A= $types->[$_]
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | my @chars = $storage->_utf8_database | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 44 | ▶ | ? grep { $CHARACTER_TYPE{ $types->[$_] // '' } } 0 .. $#$types | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$types->[$_] // ""
MC/DC0%0/1
$types->[$_] // ""
$types->[$_]
Truth table50%1/2
A
A= $types->[$_]
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | : (); | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 44 | ▶ | return unless @numbers || @chars; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@numbers or @chars
MC/DC100%2/2
@numbers or @chars
@numbers
@chars
Truth table100%3/3
A or B
A= @numbersB= @chars
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $row->[$i] and $row->[$i] =~ /\A[-+]?\d*,\d*(?:[Ee][-+]?\d+)?\z/
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/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition16%1/6
$self->{"attrs"}{"software_limit"} and $self->{"attrs"}{"offset"} || $self->{"attrs"}{"rows"}
$self->{"attrs"}{"offset"} or $self->{"attrs"}{"rows"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my $sth; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | if ($sth = $self->sth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $sth->finish if ( ! $self->{_done} and $sth->FETCH('Active') ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $self->{"_done"} and $sth->FETCH("Active")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
&shuffle_unordered_resultsets() and not $self->{"attrs"}{"order_by"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | : @rows; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||||||||||||||||