| 1 | package DBIO::DB2::Storage::Cursor; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Reads the character columns of a Db2 result as characters | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | our $VERSION = '0.900004'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use base 'DBIO::Storage::DBI::Cursor'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use List::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | 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 character column: SQL_CHAR, SQL_VARCHAR, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # SQL_LONGVARCHAR, the wide forms, and the CLI codes of CLOB and DBCLOB | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | my %CHARACTER_TYPE = map { $_ => 1 } (1, 12, -1, -8, -9, -10, -99, -350, 40); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | sub decode_rows { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_rows: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | my ($class, $storage, $sth, @rows) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | return unless $sth && $storage->_utf8_database; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sth and $storage->_utf8_database
MC/DC50%1/2
$sth and $storage->_utf8_database
$sth
$storage->_utf8_database
Truth table66%2/3
A and B
A= $sthB= $storage->_utf8_database
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | my $types = $sth->{TYPE} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sth->{'TYPE'} || []
MC/DC0%0/1
$sth->{'TYPE'} || []
$sth->{'TYPE'}
Truth table50%1/2
A
A= $sth->{'TYPE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | my @chars = grep { $CHARACTER_TYPE{ $types->[$_] // '' } } 0 .. $#$types; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$types->[$_] // ""
MC/DC0%0/1
$types->[$_] // ""
$types->[$_]
Truth table50%1/2
A
A= $types->[$_]
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | return unless @chars; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | for my $row (@rows) { | |||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | for my $i (@chars) { | |||||||||||||||||||||||||||||||||||||||||
| 30 | 9 | ▶ | utf8::decode($row->[$i]) if defined $row->[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | my @row = $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | return @row unless @row; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | $self->decode_rows($self->storage, $self->sth, \@row); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | return @row; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=9 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # with a software limit core's all goes through next | ||||||||||||||||||||||||||||||||||||||||||
| 50 | return $self->next::method(@_) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | if $self->{attrs}{software_limit} | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $sth; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | if ($sth = $self->sth) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 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")
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $self->sth(undef); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | (undef, $sth) = $self->storage->_select( @{$self->{args}} ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | my @rows = @{ $sth->fetchall_arrayref }; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | $self->decode_rows($self->storage, $sth, @rows); | |||||||||||||||||||||||||||||||||||||||||
| 64 | return (shuffle_unordered_resultsets and ! $self->{attrs}{order_by}) | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | : @rows; | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||||||||||||||||