| 1 | ####################################################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # DBI::SQL::Nano - a very tiny SQL engine | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2010 by Jens Rehsack < rehsack AT googlemail.com > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Copyright (c) 2004 by Jeff Zucker < jzucker AT cpan.org > | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # All rights reserved. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # You may freely distribute and/or modify this module under the terms | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # of either the GNU General Public License (GPL) or the Artistic License, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # as specified in the Perl README file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # See the pod at the bottom of this file for help information | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ####################################################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ####################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | package DBI::SQL::Nano; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ####################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 450 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 450 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 450 | our ( $VERSION, $versions ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 450 | ▶ | use Carp qw(croak); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 450 | require DBI; # for looks_like_number() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | BEGIN | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 450 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=12.7
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 450 | $VERSION = "1.015544"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 450 | $versions->{nano_version} = $VERSION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( $ENV{DBI_SQL_NANO} || !eval { require SQL::Statement; $SQL::Statement::VERSION ge '1.400' } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ENV{"DBI_SQL_NANO"} or not eval {
do {
require SQL::Statement;
$SQL::Statement::VERSION ge "1.400"
}
}
MC/DC0%0/2
$ENV{"DBI_SQL_NANO"} or not eval {
do {
require SQL::Statement;
$SQL::Statement::VERSION ge "1.400"
}
}
$ENV{"DBI_SQL_NANO"}
not eval {
do {
require SQL::Statement;
$SQL::Statement::VERSION ge "1.400"
}
}
Truth table66%2/3
A or not(B)
A= $ENV{"DBI_SQL_NANO"}B= not eval {
do {
require SQL::Statement;
$SQL::Statement::VERSION ge "1.400"
}
}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 450 | @DBI::SQL::Nano::Statement::ISA = qw(DBI::SQL::Nano::Statement_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 450 | @DBI::SQL::Nano::Table::ISA = qw(DBI::SQL::Nano::Table_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | @DBI::SQL::Nano::Statement::ISA = qw( SQL::Statement ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | @DBI::SQL::Nano::Table::ISA = qw( SQL::Eval::Table); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $versions->{statement_version} = $SQL::Statement::VERSION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | package DBI::SQL::Nano::Statement_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 450 | ▶ | use Carp qw(croak); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 450 | ▶ | use Errno; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 450 | ▶ | if ( eval { require Clone; } ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 450 | Clone->import("clone"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | require Storable; # in CORE since 5.7.3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | *clone = \&Storable::dclone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub new | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1410 | my ( $class, $sql ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1410 | my $self = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1410 | bless $self, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1410 | return $self->prepare($sql); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ##################################################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # PREPARE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ##################################################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | sub prepare | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=32 SCAR=37.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1410 | my ( $self, $sql ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1410 | $sql =~ s/\s+$//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1410 | $sql =~ s/\s*;$//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1410 | for ($sql) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | /^\s*CREATE\s+TABLE\s+(.*?)\s*\((.+)\)\s*$/is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | && do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 174 | $self->{command} = 'CREATE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 174 | $self->{table_name} = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | defined $2 and $2 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 174 | ▶ | $self->{column_names} = parse_coldef_list($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $2 and $2 ne ""
MC/DC0%0/2
defined $2 and $2 ne ""
defined $2
$2 ne ""
Truth table33%1/3
A and B
A= defined $2B= $2 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 174 | ▶ | $self->{column_names} or croak "Can't find columns"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | /^\s*DROP\s+TABLE\s+(IF\s+EXISTS\s+)?(.*?)\s*$/is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | && do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 272 | $self->{command} = 'DROP'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 272 | $self->{table_name} = $2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | defined $1 and $1 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 272 | ▶ | $self->{ignore_missing_table} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $1 and $1 ne ""
MC/DC50%1/2
defined $1 and $1 ne ""
defined $1
$1 ne ""
Truth table66%2/3
A and B
A= defined $1B= $1 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | /^\s*SELECT\s+(.*?)\s+FROM\s+(\S+)((.*))?/is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | && do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 352 | $self->{command} = 'SELECT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | defined $1 and $1 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 352 | ▶ | $self->{column_names} = parse_comma_list($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $1 and $1 ne ""
MC/DC0%0/2
defined $1 and $1 ne ""
defined $1
$1 ne ""
Truth table33%1/3
A and B
A= defined $1B= $1 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 352 | ▶ | $self->{column_names} or croak "Can't find columns"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 352 | $self->{table_name} = $2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 352 | ▶ | if ( my $clauses = $4 ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 178 | ▶ | if ( $clauses =~ /^(.*)\s+ORDER\s+BY\s+(.*)$/is ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 144 | $clauses = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 144 | $self->{order_clause} = $self->parse_order_clause($2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 178 | ▶ | $self->{where_clause} = $self->parse_where_clause($clauses) if ($clauses); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | /^\s*INSERT\s+(?:INTO\s+)?(\S+)\s*(\((.*?)\))?\s*VALUES\s*\((.+)\)/is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | && do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 374 | $self->{command} = 'INSERT'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 374 | $self->{table_name} = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | defined $2 and $2 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 374 | ▶ | $self->{column_names} = parse_comma_list($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $2 and $2 ne ""
MC/DC50%1/2
defined $2 and $2 ne ""
defined $2
$2 ne ""
Truth table66%2/3
A and B
A= defined $2B= $2 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | defined $4 and $4 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 374 | ▶ | $self->{values} = $self->parse_values_list($4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $4 and $4 ne ""
MC/DC0%0/2
defined $4 and $4 ne ""
defined $4
$4 ne ""
Truth table33%1/3
A and B
A= defined $4B= $4 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 374 | ▶ | $self->{values} or croak "Can't parse values"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | /^\s*DELETE\s+FROM\s+(\S+)((.*))?/is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | && do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 68 | $self->{command} = 'DELETE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 68 | $self->{table_name} = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | defined $3 and $3 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 68 | ▶ | $self->{where_clause} = $self->parse_where_clause($3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $3 and $3 ne ""
MC/DC50%1/2
defined $3 and $3 ne ""
defined $3
$3 ne ""
Truth table66%2/3
A and B
A= defined $3B= $3 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | /^\s*UPDATE\s+(\S+)\s+SET\s+(.+)(\s+WHERE\s+.+)/is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | && do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1410 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 106 | $self->{command} = 'UPDATE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 106 | $self->{table_name} = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 106 | ▶ | defined $2 and $2 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $2 and $2 ne ""
MC/DC0%0/2
defined $2 and $2 ne ""
defined $2
$2 ne ""
Truth table33%1/3
A and B
A= defined $2B= $2 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | $self->parse_set_clause($2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | defined $3 and $3 ne "" and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 106 | ▶ | $self->{where_clause} = $self->parse_where_clause($3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $3 and $3 ne ""
MC/DC0%0/2
defined $3 and $3 ne ""
defined $3
$3 ne ""
Truth table33%1/3
A and B
A= defined $3B= $3 ne ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1410 | ▶ | croak "Couldn't parse" unless ( $self->{command} and $self->{table_name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"command"} and $self->{"table_name"}
MC/DC50%1/2
$self->{"command"} and $self->{"table_name"}
$self->{"command"}
$self->{"table_name"}
Truth table66%2/3
A and B
A= $self->{"command"}B= $self->{"table_name"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1346 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | sub parse_order_clause | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 144 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_order_clause: called CC=6 SCAR=19.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 144 | my ( $self, $str ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 144 | my @clause = split /\s+/, $str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 144 | ▶ | return { $clause[0] => 'ASC' } if ( @clause == 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 12 | ▶ | croak "Bad ORDER BY clause '$str'" if ( @clause > 2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 12 | ▶ | $clause[1] ||= ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$clause[1] ||= ""
MC/DC0%0/1
$clause[1] ||= ""
$clause[1]
Truth table50%1/2
A
A= $clause[1]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 12 | ▶ | return { $clause[0] => uc $clause[1] } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$clause[1] =~ /^ASC$/i or $clause[1] =~ /^DESC$/i
MC/DC0%0/2
$clause[1] =~ /^ASC$/i or $clause[1] =~ /^DESC$/i
$clause[1] =~ /^ASC$/i
$clause[1] =~ /^DESC$/i
Truth table33%1/3
A or B
A= $clause[1] =~ /^ASC$/iB= $clause[1] =~ /^DESC$/i
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | if $clause[1] =~ /^ASC$/i | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | or $clause[1] =~ /^DESC$/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | croak "Bad ORDER BY clause '$clause[1]'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | sub parse_coldef_list | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 174 | ▶ | { # check column definitions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_coldef_list: called CC=3 SCAR=11.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 174 | my @col_defs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 174 | for ( split ',', shift ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 340 | my $col = clean_parse_str($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 340 | ▶ | if ( $col =~ /^(\S+?)\s+.+/ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | { # doesn't check what it is | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 340 | $col = $1; # just checks if it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | croak "No column definition for '$_'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 340 | push @col_defs, $col; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 174 | return \@col_defs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub parse_comma_list | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 384 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_comma_list: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 384 | [ map { clean_parse_str($_) } split( ',', shift ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1706 | ▶ | sub clean_parse_str { local $_ = shift; s/\(//; s/\)//; s/^\s+//; s/\s+$//; $_; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_parse_str: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | sub parse_values_list | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 374 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_values_list: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 374 | my ( $self, $str ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 374 | [ map { $self->parse_value( clean_parse_str($_) ) } split( ',', $str ) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub parse_set_clause | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 106 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_set_clause: called CC=4 SCAR=14.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 106 | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 106 | my @cols = split /,/, shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 106 | my $set_clause; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 106 | for my $col (@cols) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 106 | my ( $col_name, $value ) = $col =~ /^\s*(.+?)\s*=\s*(.+?)\s*$/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 106 | push @{ $self->{column_names} }, $col_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 106 | push @{ $self->{values} }, $self->parse_value($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 106 | ▶ | croak "Can't parse set clause" unless ( $self->{column_names} and $self->{values} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"column_names"} and $self->{"values"}
MC/DC0%0/2
$self->{"column_names"} and $self->{"values"}
$self->{"column_names"}
$self->{"values"}
Truth table33%1/3
A and B
A= $self->{"column_names"}B= $self->{"values"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | sub parse_value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1248 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_value: called CC=6 SCAR=17.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1248 | my ( $self, $str ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1248 | ▶ | return unless ( defined $str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1248 | $str =~ s/\s+$//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1248 | $str =~ s/^\s+//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1248 | ▶ | if ( $str =~ /^\?$/ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 420 | push @{ $self->{params} }, '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | return { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 420 | value => '?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | type => 'placeholder' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | return { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 828 | ▶ | value => undef, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | type => 'NULL' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } if ( $str =~ /^NULL$/i ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | return { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 804 | ▶ | value => $1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | type => 'string' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } if ( $str =~ /^'(.+)'$/s ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | return { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 476 | ▶ | value => $str, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | type => 'number' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } if ( DBI::looks_like_number($str) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | return { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 218 | value => $str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | type => 'column' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | sub parse_where_clause | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 198 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_where_clause: called CC=5 SCAR=18.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 198 | my ( $self, $str ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 198 | $str =~ s/\s+$//; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 198 | ▶ | if ( $str =~ /^\s*WHERE\s+(.*)/i ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 198 | $str = $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | croak "Couldn't find WHERE clause in '$str'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 198 | my ($neg) = $str =~ s/^\s*(NOT)\s+//is; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 198 | my $opexp = '=|<>|<=|>=|<|>|LIKE|CLIKE|IS'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 198 | my ( $val1, $op, $val2 ) = $str =~ /^(.+?)\s*($opexp)\s*(.+)\s*$/iso; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 198 | ▶ | croak "Couldn't parse WHERE expression '$str'" unless ( defined $val1 and defined $op and defined $val2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $val1 and defined $op and defined $val2
defined $val1 and defined $op
MC/DC0%0/3
defined $val1 and defined $op and defined $val2
defined $val1
defined $op
defined $val2
Truth table25%1/4
A and B and C
A= defined $val1B= defined $opC= defined $val2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | return { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 198 | arg1 => $self->parse_value($val1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | arg2 => $self->parse_value($val2), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | op => $op, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | neg => $neg, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | ##################################################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # EXECUTE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | ##################################################################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | sub execute | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1050 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=11 SCAR=27.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1050 | my ( $self, $data, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1050 | my $num_placeholders = $self->params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1050 | ▶ | my $num_params = scalar @$params || 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
scalar @$params || 0
MC/DC100%1/1
scalar @$params || 0
scalar @$params
Truth table100%2/2
A
A= scalar @$params
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1050 | ▶ | croak "Number of params '$num_params' does not match number of placeholders '$num_placeholders'" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | unless ( $num_placeholders == $num_params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1050 | ▶ | if ( scalar @$params ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 160 | for my $i ( 0 .. $#{ $self->{values} } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 312 | ▶ | if ( $self->{values}->[$i]->{type} eq 'placeholder' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 312 | $self->{values}->[$i]->{value} = shift @$params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 160 | ▶ | if ( $self->{where_clause} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if ( $self->{where_clause}->{arg1}->{type} eq 'placeholder' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $self->{where_clause}->{arg1}->{value} = shift @$params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ( $self->{where_clause}->{arg2}->{type} eq 'placeholder' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $self->{where_clause}->{arg2}->{value} = shift @$params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 1050 | my $command = $self->{command}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1050 | ( $self->{'NUM_OF_ROWS'}, $self->{'NUM_OF_FIELDS'}, $self->{'data'}, ) = $self->$command( $data, $params ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 978 | ▶ | $self->{NAME} ||= $self->{column_names}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"NAME"} ||= $self->{"column_names"}
MC/DC50%1/2
$self->{"NAME"} ||= $self->{"column_names"}
$self->{"NAME"}
$self->{"column_names"}
Truth table66%2/3
A ||= B
A= $self->{"NAME"}B= $self->{"column_names"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 978 | ▶ | return $self->{'NUM_OF_ROWS'} || '0E0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'NUM_OF_ROWS'} || '0E0'
MC/DC100%1/1
$self->{'NUM_OF_ROWS'} || '0E0'
$self->{'NUM_OF_ROWS'}
Truth table100%2/2
A
A= $self->{'NUM_OF_ROWS'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 450 | my $enoentstr = "Cannot open .*\(" . Errno::ENOENT . "\)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 450 | my $enoentrx = qr/$enoentstr/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | sub DROP ($$$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 264 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DROP: called CC=9 SCAR=22.7
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 264 | my ( $self, $data, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 264 | my $table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | my @err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 264 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | local $SIG{__WARN__} = sub { push @err, @_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 264 | ($table) = $self->open_tables( $data, 0, 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 264 | ▶ | if ( $self->{ignore_missing_table} and ( $@ or @err ) and grep { $_ =~ $enoentrx } ( @err, $@ ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$self->{"ignore_missing_table"} and $@ || @err and grep {$_ =~ /$enoentrx/;} @err, $@
$self->{"ignore_missing_table"} and $@ || @err
$@ or @err
MC/DC50%2/4
$self->{"ignore_missing_table"} and $@ || @err and grep {$_ =~ /$enoentrx/;} @err, $@
$self->{"ignore_missing_table"}
$@
@err
grep {$_ =~ /$enoentrx/;} @err, $@
Truth table50%3/6
A and B or C and D
A= $self->{"ignore_missing_table"}B= $@C= @errD= grep {$_ =~ /$enoentrx/;} @err, $@
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 100 | $@ = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 100 | return ( -1, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 164 | ▶ | croak( $@ || $err[0] ) if ( $@ || @err ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$@ or @err
$@ || $err[0]
MC/DC50%1/2
$@ or @err
$@
@err
MC/DC0%0/2
$@ || $err[0]
$@
$err[0]
Truth table66%2/3
A or B
A= $@B= @err
Truth table33%1/3
A || B
A= $@B= $err[0]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 140 | ▶ | return ( -1, 0 ) unless $table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 140 | $table->drop($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 140 | ( -1, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | sub CREATE ($$$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 154 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CREATE: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 154 | my ( $self, $data, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 154 | my $table = $self->open_tables( $data, 1, 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 134 | $table->push_names( $data, $self->{column_names} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 134 | ( 0, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | sub INSERT ($$$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 270 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
INSERT: called CC=8 SCAR=21.1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 270 | my ( $self, $data, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 270 | my $table = $self->open_tables( $data, 0, 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 262 | $self->verify_columns($table); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 262 | my $all_columns = $table->{col_names}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 262 | ▶ | $table->seek( $data, 0, 2 ) unless ( $table->can('insert_one_row') ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 262 | my ($array) = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 262 | my ( $val, $col, $i ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 262 | ▶ | $self->{column_names} = $table->col_names() unless ( $self->{column_names} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 262 | ▶ | my $cNum = scalar( @{ $self->{column_names} } ) if ( $self->{column_names} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 262 | my $param_num = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 262 | ▶ | $cNum or | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | croak "Bad col names in INSERT"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 262 | my $maxCol = $#$all_columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 262 | ▶ | for ( $i = 0; $i < $cNum; $i++ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 524 | $col = $self->{column_names}->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 524 | $array->[ $self->column_nums( $table, $col ) ] = $self->row_values($i); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | # Extend row to put values in ALL fields | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 262 | ▶ | $#$array < $maxCol and $array->[$maxCol] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 262 | ▶ | $table->can('insert_new_row') ? $table->insert_new_row( $data, $array ) : $table->push_row( $data, $array ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 262 | return ( 1, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | sub DELETE ($$$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 36 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=9 SCAR=22.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 36 | my ( $self, $data, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 36 | my $table = $self->open_tables( $data, 0, 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 28 | $self->verify_columns($table); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 28 | my ($affected) = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 28 | my ( @rows, $array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 28 | my $can_dor = $table->can('delete_one_row'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 28 | ▶ | while ( $array = $table->fetch_row($data) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 102 | ▶ | if ( $self->eval_where( $table, $array ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 60 | ++$affected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 60 | ▶ | if ( $self->{fetched_from_key} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 8 | $array = $self->{fetched_value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 8 | $table->delete_one_row( $data, $array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 8 | return ( $affected, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 52 | ▶ | push( @rows, $array ) if ($can_dor); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 42 | ▶ | push( @rows, $array ) unless ($can_dor); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 20 | ▶ | if ($can_dor) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 16 | foreach $array (@rows) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 48 | $table->delete_one_row( $data, $array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 4 | $table->seek( $data, 0, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 4 | foreach $array (@rows) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | $table->push_row( $data, $array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 4 | $table->truncate($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 20 | return ( $affected, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | sub _anycmp($$;$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 144 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_anycmp: called CC=7 SCAR=24.4
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 144 | my ( $a, $b, $case_fold ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 144 | ▶ | if ( !defined($a) || !defined($b) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $a && defined $b
MC/DC0%0/2
defined $a && defined $b
defined $a
defined $b
Truth table33%1/3
A && B
A= defined $aB= defined $b
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | return defined($a) - defined($b); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | ▶ | elsif ( DBI::looks_like_number($a) && DBI::looks_like_number($b) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
DBI::looks_like_number($a) and DBI::looks_like_number($b)
MC/DC50%1/2
DBI::looks_like_number($a) and DBI::looks_like_number($b)
DBI::looks_like_number($a)
DBI::looks_like_number($b)
Truth table66%2/3
A and B
A= DBI::looks_like_number($a)B= DBI::looks_like_number($b)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 120 | return $a <=> $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 24 | ▶ | return $case_fold ? lc($a) cmp lc($b) || $a cmp $b : $a cmp $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
lc $a cmp lc $b or $a cmp $b
MC/DC0%0/2
lc $a cmp lc $b or $a cmp $b
lc $a cmp lc $b
$a cmp $b
Truth table0%0/3
A or B
A= lc $a cmp lc $bB= $a cmp $b
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | sub SELECT ($$$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 232 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SELECT: called CC=13 SCAR=25.7
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 232 | my ( $self, $data, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 232 | my $table = $self->open_tables( $data, 0, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 224 | $self->verify_columns($table); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 224 | my $tname = $self->{table_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 224 | my ($affected) = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 224 | my ( @rows, %cols, $array, $val, $col, $i ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 224 | ▶ | while ( $array = $table->fetch_row($data) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 498 | ▶ | if ( $self->eval_where( $table, $array ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 450 | ▶ | $array = $self->{fetched_value} if ( $self->{fetched_from_key} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 450 | ▶ | unless ( keys %cols ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 224 | my $col_nums = $self->column_nums($table); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 224 | %cols = reverse %{$col_nums}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 450 | my $rowhash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 450 | for ( sort keys %cols ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 866 | $rowhash->{ $cols{$_} } = $array->[$_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 450 | my @newarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 450 | ▶ | for ( $i = 0; $i < @{ $self->{column_names} }; $i++ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 866 | $col = $self->{column_names}->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 866 | push @newarray, $rowhash->{$col}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 450 | push( @rows, \@newarray ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 8 | return ( scalar(@rows), scalar @{ $self->{column_names} }, \@rows ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 450 | ▶ | if ( $self->{fetched_from_key} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 216 | ▶ | if ( $self->{order_clause} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 96 | my ( $sort_col, $desc ) = each %{ $self->{order_clause} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 96 | my @sortCols = ( $self->column_nums( $table, $sort_col, 1 ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 96 | ▶ | $sortCols[1] = uc $desc eq 'DESC' ? 1 : 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | @rows = sort { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 96 | my ( $result, $colNum, $desc ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 144 | my $i = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 144 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $result and $i < @sortCols
MC/DC0%0/2
not $result and $i < @sortCols
not $result
$i < @sortCols
Truth table33%1/3
not(A) and B
A= not $resultB= $i < @sortCols
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 144 | $colNum = $sortCols[ $i++ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 144 | $desc = $sortCols[ $i++ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 144 | $result = _anycmp( $a->[$colNum], $b->[$colNum] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 144 | ▶ | $result = -$result if ($desc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } while ( !$result && $i < @sortCols ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 216 | ( scalar(@rows), scalar @{ $self->{column_names} }, \@rows ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | sub UPDATE ($$$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 94 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
UPDATE: called CC=19 SCAR=30.4
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 94 | my ( $self, $data, $params ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 94 | my $table = $self->open_tables( $data, 0, 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 94 | $self->verify_columns($table); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 94 | ▶ | return undef unless $table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 94 | my $affected = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 94 | my $can_usr = $table->can('update_specific_row'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 94 | my $can_uor = $table->can('update_one_row'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 94 | ▶ | my $can_rwu = $can_usr || $can_uor; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$can_usr || $can_uor
MC/DC50%1/2
$can_usr || $can_uor
$can_usr
$can_uor
Truth table66%2/3
A || B
A= $can_usrB= $can_uor
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 94 | my ( @rows, $array, $f_array, $val, $col, $i ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 94 | ▶ | while ( $array = $table->fetch_row($data) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 168 | ▶ | if ( $self->eval_where( $table, $array ) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 166 | ▶ | $array = $self->{fetched_value} if ( $self->{fetched_from_key} and $can_rwu ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"fetched_from_key"} and $can_rwu
MC/DC50%1/2
$self->{"fetched_from_key"} and $can_rwu
$self->{"fetched_from_key"}
$can_rwu
Truth table66%2/3
A and B
A= $self->{"fetched_from_key"}B= $can_rwu
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 166 | ▶ | my $orig_ary = clone($array) if ($can_usr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 166 | ▶ | for ( $i = 0; $i < @{ $self->{column_names} }; $i++ ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 166 | $col = $self->{column_names}->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 166 | $array->[ $self->column_nums( $table, $col ) ] = $self->row_values($i); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 166 | $affected++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 166 | ▶ | if ( $self->{fetched_value} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 20 | ▶ | if ($can_usr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 20 | $table->update_specific_row( $data, $array, $orig_ary ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | elsif ($can_uor) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $table->update_one_row( $data, $array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 16 | return ( $affected, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 146 | ▶ | push( @rows, $can_usr ? [ $array, $orig_ary ] : $array ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 2 | ▶ | push( @rows, $array ) unless ($can_rwu); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 74 | ▶ | if ($can_rwu) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 72 | foreach my $array (@rows) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 144 | ▶ | if ($can_usr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 144 | $table->update_specific_row( $data, @$array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | elsif ($can_uor) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $table->update_one_row( $data, $array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 2 | $table->seek( $data, 0, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 2 | foreach my $array (@rows) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 4 | $table->push_row( $data, $array ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 2 | $table->truncate($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 74 | return ( $affected, 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | sub verify_columns | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 608 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_columns: called CC=7 SCAR=20.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 608 | my ( $self, $table ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 608 | my @cols = @{ $self->{column_names} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 608 | ▶ | if ( $self->{where_clause} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 146 | ▶ | if ( my $col = $self->{where_clause}->{arg1} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 146 | ▶ | push @cols, $col->{value} if $col->{type} eq 'column'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 146 | ▶ | if ( my $col = $self->{where_clause}->{arg2} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 146 | ▶ | push @cols, $col->{value} if $col->{type} eq 'column'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 608 | for (@cols) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 1246 | $self->column_nums( $table, $_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | sub column_nums | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 2256 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_nums: called CC=12 SCAR=25.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 2256 | my ( $self, $table, $stmt_col_name, $find_in_stmt ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 2256 | my %dbd_nums = %{ $table->col_nums() }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 2256 | my @dbd_cols = @{ $table->col_names() }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 2256 | my %stmt_nums; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 2256 | ▶ | if ( $stmt_col_name and !$find_in_stmt ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$stmt_col_name and not $find_in_stmt
MC/DC100%2/2
$stmt_col_name and not $find_in_stmt
$stmt_col_name
not $find_in_stmt
Truth table100%3/3
A and not(B)
A= $stmt_col_nameB= not $find_in_stmt
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1936 | ▶ | while ( my ( $k, $v ) = each %dbd_nums ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 2908 | ▶ | return $v if uc $k eq uc $stmt_col_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | croak "No such column '$stmt_col_name'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 320 | ▶ | if ( $stmt_col_name and $find_in_stmt ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$stmt_col_name and $find_in_stmt
MC/DC50%1/2
$stmt_col_name and $find_in_stmt
$stmt_col_name
$find_in_stmt
Truth table66%2/3
A and B
A= $stmt_col_nameB= $find_in_stmt
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 96 | for my $i ( 0 .. @{ $self->{column_names} } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 104 | ▶ | return $i if uc $stmt_col_name eq uc $self->{column_names}->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | croak "No such column '$stmt_col_name'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 224 | for my $i ( 0 .. $#dbd_cols ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 436 | for my $stmt_col ( @{ $self->{column_names} } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 840 | ▶ | $stmt_nums{$stmt_col} = $i if uc $dbd_cols[$i] eq uc $stmt_col; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 224 | return \%stmt_nums; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | sub eval_where | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 768 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eval_where: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 768 | my ( $self, $table, $rowary ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 768 | ▶ | my $where = $self->{"where_clause"} || return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'where_clause'} || (return 1)
MC/DC100%1/1
$self->{'where_clause'} || (return 1)
$self->{'where_clause'}
Truth table100%2/2
A
A= $self->{'where_clause'}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 342 | my $col_nums = $table->col_nums(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 342 | my %cols = reverse %{$col_nums}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 342 | my $rowhash; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 342 | for ( sort keys %cols ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 684 | $rowhash->{ uc $cols{$_} } = $rowary->[$_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 342 | return $self->process_predicate( $where, $table, $rowhash ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | sub process_predicate | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 342 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_predicate: called CC=10 SCAR=24.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 342 | my ( $self, $pred, $table, $rowhash ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 342 | my $val1 = $pred->{arg1}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 342 | ▶ | if ( $val1->{type} eq 'column' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 342 | $val1 = $rowhash->{ uc $val1->{value} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | $val1 = $val1->{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 342 | my $val2 = $pred->{arg2}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 342 | ▶ | if ( $val2->{type} eq 'column' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | $val2 = $rowhash->{ uc $val2->{value} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 342 | $val2 = $val2->{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 342 | my $op = $pred->{op}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 342 | my $neg = $pred->{neg}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 342 | ▶ | if ( $op eq '=' and !$neg and $table->can('fetch_one_row') ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$op eq "=" and not $neg and $table->can("fetch_one_row")
$op eq "=" and not $neg
MC/DC66%2/3
$op eq "=" and not $neg and $table->can("fetch_one_row")
$op eq "="
not $neg
$table->can("fetch_one_row")
Truth table75%3/4
A and not(B) and C
A= $op eq "="B= not $negC= $table->can("fetch_one_row")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 236 | my $key_col = $table->fetch_one_row( 1, 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 236 | ▶ | if ( $pred->{arg1}->{value} =~ /^$key_col$/i ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 36 | $self->{fetched_from_key} = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 36 | $self->{fetched_value} = $table->fetch_one_row( 0, $pred->{arg2}->{value} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 36 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 306 | ▶ | my $match = $self->is_matched( $val1, $op, $val2 ) || 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->is_matched($val1, $op, $val2) || 0
MC/DC100%1/1
$self->is_matched($val1, $op, $val2) || 0
$self->is_matched($val1, $op, $val2)
Truth table100%2/2
A
A= $self->is_matched($val1, $op, $val2)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | ▶ | if ($neg) { $match = $match ? 0 : 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 306 | return $match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | sub is_matched | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 306 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_matched: called CC=23 SCAR=41.5
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 306 | my ( $self, $val1, $op, $val2 ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 306 | ▶ | if ( $op eq 'IS' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 32 | ▶ | return 1 if ( !defined $val1 or $val1 eq '' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $val1 or $val1 eq ""
MC/DC50%1/2
not defined $val1 or $val1 eq ""
not defined $val1
$val1 eq ""
Truth table66%2/3
not(A) or B
A= not defined $val1B= $val1 eq ""
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 24 | return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 274 | ▶ | $val1 //= ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$val1 //= ""
MC/DC0%0/1
$val1 //= ""
$val1
Truth table50%1/2
A
A= $val1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 274 | ▶ | $val2 //= ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$val2 //= ""
MC/DC0%0/1
$val2 //= ""
$val2
Truth table50%1/2
A
A= $val2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 274 | ▶ | if ( $op =~ /LIKE|CLIKE/i ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | $val2 = quotemeta($val2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | $val2 =~ s/\\%/.*/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | $val2 =~ s/_/./g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | if ( $op eq 'LIKE' ) { return $val1 =~ /^$val2$/s; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | if ( $op eq 'CLIKE' ) { return $val1 =~ /^$val2$/si; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 274 | ▶ | if ( DBI::looks_like_number($val1) && DBI::looks_like_number($val2) ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
DBI::looks_like_number($val1) and DBI::looks_like_number($val2)
MC/DC50%1/2
DBI::looks_like_number($val1) and DBI::looks_like_number($val2)
DBI::looks_like_number($val1)
DBI::looks_like_number($val2)
Truth table66%2/3
A and B
A= DBI::looks_like_number($val1)B= DBI::looks_like_number($val2)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | if ( $op eq '<' ) { return $val1 < $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | if ( $op eq '>' ) { return $val1 > $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 2 | ▶ | if ( $op eq '=' ) { return $val1 == $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | if ( $op eq '<>' ) { return $val1 != $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | if ( $op eq '<=' ) { return $val1 <= $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | if ( $op eq '>=' ) { return $val1 >= $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | if ( $op eq '<' ) { return $val1 lt $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | ▶ | if ( $op eq '>' ) { return $val1 gt $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 272 | ▶ | if ( $op eq '=' ) { return $val1 eq $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | if ( $op eq '<>' ) { return $val1 ne $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 64 | ▶ | if ( $op eq '<=' ) { return $val1 le $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 32 | ▶ | if ( $op eq '>=' ) { return $val1 ge $val2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | sub params | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 3446 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: called CC=4 SCAR=14.8
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 3446 | my ( $self, $val_num ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 3446 | ▶ | if ( !$self->{"params"} ) { return 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 536 | ▶ | if ( defined $val_num ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | return $self->{"params"}->[$val_num]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | return wantarray ? @{ $self->{"params"} } : scalar @{ $self->{"params"} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | sub open_tables | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 1050 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_tables: called CC=5 SCAR=16.1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 1050 | my ( $self, $data, $createMode, $lockMode ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 1050 | my $table_name = $self->{table_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 1050 | my $table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 1050 | eval { $table = $self->open_table( $data, $table_name, $createMode, $lockMode ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 1050 | ▶ | if ($@) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 168 | chomp $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 168 | croak $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 882 | ▶ | croak "Couldn't open table '$table_name'" unless $table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 882 | ▶ | if ( !$self->{column_names} or $self->{column_names}->[0] eq '*' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->{"column_names"} or $self->{"column_names"}[0] eq "*"
MC/DC100%2/2
not $self->{"column_names"} or $self->{"column_names"}[0] eq "*"
not $self->{"column_names"}
$self->{"column_names"}[0] eq "*"
Truth table100%3/3
not(A) or B
A= not $self->{"column_names"}B= $self->{"column_names"}[0] eq "*"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 480 | $self->{column_names} = $table->col_names(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 882 | return $table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | sub row_values | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 690 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
row_values: called CC=4 SCAR=21.2
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 690 | my ( $self, $val_num ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if ( !$self->{"values"} ) { return 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 690 | ▶ | if ( defined $val_num ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 690 | return $self->{"values"}->[$val_num]->{value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | ▶ | if (wantarray) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | return map { $_->{"value"} } @{ $self->{"values"} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | else | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | return scalar @{ $self->{"values"} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | sub column_names | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 2450 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_names: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 2450 | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 2450 | my @col_names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 2450 | ▶ | if ( $self->{column_names} and $self->{column_names}->[0] ne '*' ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"column_names"} and $self->{"column_names"}[0] ne "*"
MC/DC100%2/2
$self->{"column_names"} and $self->{"column_names"}[0] ne "*"
$self->{"column_names"}
$self->{"column_names"}[0] ne "*"
Truth table100%3/3
A and B
A= $self->{"column_names"}B= $self->{"column_names"}[0] ne "*"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 982 | @col_names = @{ $self->{column_names} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 2450 | return @col_names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | ############################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | package DBI::SQL::Nano::Table_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | ############################### | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 450 | ▶ | use Carp qw(croak); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | sub new ($$) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 882 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=23.4
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 882 | my ( $proto, $attr ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 882 | my ($self) = {%$attr}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | defined( $self->{col_names} ) and "ARRAY" eq ref( $self->{col_names} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 882 | ▶ | or croak("attribute 'col_names' must be defined as an array"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"col_names"} and "ARRAY" eq ref $self->{"col_names"}
MC/DC0%0/2
defined $self->{"col_names"} and "ARRAY" eq ref $self->{"col_names"}
defined $self->{"col_names"}
"ARRAY" eq ref $self->{"col_names"}
Truth table33%1/3
A and B
A= defined $self->{"col_names"}B= "ARRAY" eq ref $self->{"col_names"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 882 | ▶ | exists( $self->{col_nums} ) or $self->{col_nums} = _map_colnums( $self->{col_names} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | defined( $self->{col_nums} ) and "HASH" eq ref( $self->{col_nums} ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 882 | ▶ | or croak("attribute 'col_nums' must be defined as a hash"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"col_nums"} and "HASH" eq ref $self->{"col_nums"}
MC/DC0%0/2
defined $self->{"col_nums"} and "HASH" eq ref $self->{"col_nums"}
defined $self->{"col_nums"}
"HASH" eq ref $self->{"col_nums"}
Truth table33%1/3
A and B
A= defined $self->{"col_nums"}B= "HASH" eq ref $self->{"col_nums"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 882 | ▶ | bless( $self, ( ref($proto) || $proto ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 882 | return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | sub _map_colnums | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 882 | ▶ | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_map_colnums: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 882 | my $col_names = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 882 | my %col_nums; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 882 | for my $i ( 0 .. $#$col_names ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 1436 | ▶ | next unless $col_names->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 1436 | $col_nums{ $col_names->[$i] } = $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 882 | return \%col_nums; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | sub row() { return $_[0]->{row}; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
row: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | sub column($) { return $_[0]->{row}->[ $_[0]->column_num( $_[1] ) ]; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | sub column_num($) { $_[0]->{col_nums}->{ $_[1] }; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_num: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 2598 | ▶ | sub col_nums() { $_[0]->{col_nums} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
col_nums: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 2736 | ▶ | sub col_names() { $_[0]->{col_names}; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
col_names: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | ▶ | sub drop ($$) { croak "Abstract method " . ref( $_[0] ) . "::drop called" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | ▶ | sub fetch_row ($$$) { croak "Abstract method " . ref( $_[0] ) . "::fetch_row called" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_row: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | sub push_row ($$$) { croak "Abstract method " . ref( $_[0] ) . "::push_row called" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push_row: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | sub push_names ($$$) { croak "Abstract method " . ref( $_[0] ) . "::push_names called" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push_names: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | sub truncate ($$) { croak "Abstract method " . ref( $_[0] ) . "::truncate called" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
truncate: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | ▶ | sub seek ($$$$) { croak "Abstract method " . ref( $_[0] ) . "::seek called" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seek: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 450 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||