blib/lib/DBI/SQL/Nano.pm

filter: Statementstmt 87.7% 401 / 457 Branchbran 70.6% 188 / 266 Conditioncond 58.4% 73 / 125 MC/DCmcdc 33.7% 26 / 77 Subroutinesub 79.1% 38 / 48 Podpod n/a totaltotal 74.6% 726 / 973 CC 192 SCAR 29.3
CC
192
Cov
78%
is_matched
63.2
prepare
40.4
UPDATE
20.9
CRAP 18.6
« blib/lib/DBI/DBD/SqlEngine.pm ↑ Summary blib/lib/DBD/Gofer/Transport/stream.pm »
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
BranchTrueFalseTotal
if ($ENV{'DBI_SQL_NANO'} or not eval { do { require SQL::Statement; $SQL::Statement::VERSION ge '1.400' } }) { } 450 0 450
Condition66%2/3
$ENV{"DBI_SQL_NANO"} or not eval { do { require SQL::Statement; $SQL::Statement::VERSION ge "1.400" } }
l!l&&r!l&&!r
2222280
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" } }
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if (eval { do { require Clone } }) { } 450 0 450
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
BranchTrueFalseTotal
/^\s*CREATE\s+TABLE\s+(.*?)\s*\((.+)\)\s*$/is and do { $self->{"command"} = "CREATE"; $self->{"table_name"} = $1; defined $2 and $2 ne "" and $self->{"column_names"} = parse_coldef_list($2); $self->{"column_names"} or croak("Can't find columns") } 174 1236 1410
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
BranchTrueFalseTotal
defined $2 and $2 ne "" and $self->{"column_names"} = parse_coldef_list($2) 174 0 174
Condition33%1/3
defined $2 and $2 ne ""
!ll&&!rl&&r
00174
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 ""
ABresult
0X0
100
111
89 174 ▶ $self->{column_names} or croak "Can't find columns";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"column_names"} or croak("Can't find columns") 174 0 174
90 };
91 /^\s*DROP\s+TABLE\s+(IF\s+EXISTS\s+)?(.*?)\s*$/is
92 && do
93 1410 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
/^\s*DROP\s+TABLE\s+(IF\s+EXISTS\s+)?(.*?)\s*$/is and do { $self->{"command"} = "DROP"; $self->{"table_name"} = $2; defined $1 and $1 ne "" and $self->{"ignore_missing_table"} = 1 } 272 1138 1410
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
BranchTrueFalseTotal
defined $1 and $1 ne "" and $self->{"ignore_missing_table"} = 1 136 136 272
Condition66%2/3
defined $1 and $1 ne ""
!ll&&!rl&&r
1360136
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 ""
ABresult
0X0
100
111
98 };
99 /^\s*SELECT\s+(.*?)\s+FROM\s+(\S+)((.*))?/is
100 && do
101 1410 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
/^\s*SELECT\s+(.*?)\s+FROM\s+(\S+)((.*))?/is and do { $self->{"command"} = "SELECT"; defined $1 and $1 ne "" and $self->{"column_names"} = parse_comma_list($1); $self->{"column_names"} or croak("Can't find columns"); $self->{"table_name"} = $2; if (my $clauses = $4) { if ($clauses =~ /^(.*)\s+ORDER\s+BY\s+(.*)$/is) { $clauses = $1; $self->{"order_clause"} = $self->parse_order_clause($2); } ; $self->{"where_clause"} = $self->parse_where_clause($clauses) if $clauses; } } 352 1058 1410
102 352 $self->{command} = 'SELECT';
103 defined $1 and $1 ne "" and
104 352 ▶ $self->{column_names} = parse_comma_list($1);
Branch: 1 branch
BranchTrueFalseTotal
defined $1 and $1 ne "" and $self->{"column_names"} = parse_comma_list($1) 352 0 352
Condition33%1/3
defined $1 and $1 ne ""
!ll&&!rl&&r
00352
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 ""
ABresult
0X0
100
111
105 352 ▶ $self->{column_names} or croak "Can't find columns";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"column_names"} or croak("Can't find columns") 352 0 352
106 352 $self->{table_name} = $2;
107 352 ▶ if ( my $clauses = $4 )
Branch: 1 branch
BranchTrueFalseTotal
if (my $clauses = $4) 178 174 352
108 {
109 178 ▶ if ( $clauses =~ /^(.*)\s+ORDER\s+BY\s+(.*)$/is )
Branch: 1 branch
BranchTrueFalseTotal
if ($clauses =~ /^(.*)\s+ORDER\s+BY\s+(.*)$/is) 144 34 178
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
BranchTrueFalseTotal
if $clauses 58 120 178
115 }
116 };
117 /^\s*INSERT\s+(?:INTO\s+)?(\S+)\s*(\((.*?)\))?\s*VALUES\s*\((.+)\)/is
118 && do
119 1410 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
/^\s*INSERT\s+(?:INTO\s+)?(\S+)\s*(\((.*?)\))?\s*VALUES\s*\((.+)\)/is and do { $self->{"command"} = "INSERT"; $self->{"table_name"} = $1; defined $2 and $2 ne "" and $self->{"column_names"} = parse_comma_list($2); defined $4 and $4 ne "" and $self->{"values"} = $self->parse_values_list($4); $self->{"values"} or croak("Can't parse values") } 374 1036 1410
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
BranchTrueFalseTotal
defined $2 and $2 ne "" and $self->{"column_names"} = parse_comma_list($2) 32 342 374
Condition66%2/3
defined $2 and $2 ne ""
!ll&&!rl&&r
342032
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 ""
ABresult
0X0
100
111
124 defined $4 and $4 ne "" and
125 374 ▶ $self->{values} = $self->parse_values_list($4);
Branch: 1 branch
BranchTrueFalseTotal
defined $4 and $4 ne "" and $self->{"values"} = $self->parse_values_list($4) 374 0 374
Condition33%1/3
defined $4 and $4 ne ""
!ll&&!rl&&r
00374
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 ""
ABresult
0X0
100
111
126 374 ▶ $self->{values} or croak "Can't parse values";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"values"} or croak("Can't parse values") 374 0 374
127 };
128 /^\s*DELETE\s+FROM\s+(\S+)((.*))?/is
129 && do
130 1410 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
/^\s*DELETE\s+FROM\s+(\S+)((.*))?/is and do { $self->{"command"} = "DELETE"; $self->{"table_name"} = $1; defined $3 and $3 ne "" and $self->{"where_clause"} = $self->parse_where_clause($3) } 68 1342 1410
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
BranchTrueFalseTotal
defined $3 and $3 ne "" and $self->{"where_clause"} = $self->parse_where_clause($3) 34 34 68
Condition66%2/3
defined $3 and $3 ne ""
!ll&&!rl&&r
03434
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 ""
ABresult
0X0
100
111
135 };
136 /^\s*UPDATE\s+(\S+)\s+SET\s+(.+)(\s+WHERE\s+.+)/is
137 && do
138 1410 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
/^\s*UPDATE\s+(\S+)\s+SET\s+(.+)(\s+WHERE\s+.+)/is and do { $self->{"command"} = "UPDATE"; $self->{"table_name"} = $1; defined $2 and $2 ne "" and $self->parse_set_clause($2); defined $3 and $3 ne "" and $self->{"where_clause"} = $self->parse_where_clause($3) } 106 1304 1410
139 106 $self->{command} = 'UPDATE';
140 106 $self->{table_name} = $1;
141 106 ▶ defined $2 and $2 ne "" and
Branch: 1 branch
BranchTrueFalseTotal
defined $2 and $2 ne "" and $self->parse_set_clause($2) 106 0 106
Condition33%1/3
defined $2 and $2 ne ""
!ll&&!rl&&r
00106
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 ""
ABresult
0X0
100
111
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
BranchTrueFalseTotal
defined $3 and $3 ne "" and $self->{"where_clause"} = $self->parse_where_clause($3) 106 0 106
Condition33%1/3
defined $3 and $3 ne ""
!ll&&!rl&&r
00106
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 ""
ABresult
0X0
100
111
145 };
146 }
147 1410 ▶ croak "Couldn't parse" unless ( $self->{command} and $self->{table_name} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"command"} and $self->{"table_name"} 64 1346 1410
Condition66%2/3
$self->{"command"} and $self->{"table_name"}
!ll&&!rl&&r
6401346
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if @clause == 1 132 12 144
156 12 ▶ croak "Bad ORDER BY clause '$str'" if ( @clause > 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @clause > 2 0 12 12
157 12 ▶ $clause[1] ||= '';
Condition50%1/2
$clause[1] ||= ""
l!l
120
MC/DC0%0/1
$clause[1] ||= ""
$clause[1]
Truth table50%1/2
A
A= $clause[1]
Aresult
11
00
158 12 ▶ return { $clause[0] => uc $clause[1] }
Branch: 1 branch
BranchTrueFalseTotal
if $clause[1] =~ /^ASC$/i or $clause[1] =~ /^DESC$/i 12 0 12
Condition33%1/3
$clause[1] =~ /^ASC$/i or $clause[1] =~ /^DESC$/i
l!l&&r!l&&!r
0120
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($col =~ /^(\S+?)\s+.+/) { } 340 0 340
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
BranchTrueFalseTotal
unless $self->{"column_names"} and $self->{"values"} 0 106 106
Condition33%1/3
$self->{"column_names"} and $self->{"values"}
!ll&&!rl&&r
00106
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $str 0 1248 1248
213 1248 $str =~ s/\s+$//;
214 1248 $str =~ s/^\s+//;
215 1248 ▶ if ( $str =~ /^\?$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^\?$/) 420 828 1248
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
BranchTrueFalseTotal
if $str =~ /^NULL$/i 24 804 828
225 type => 'NULL'
226 } if ( $str =~ /^NULL$/i );
227 return {
228 804 ▶ value => $1,
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^'(.+)'$/s 328 476 804
229 type => 'string'
230 } if ( $str =~ /^'(.+)'$/s );
231 return {
232 476 ▶ value => $str,
Branch: 1 branch
BranchTrueFalseTotal
if DBI::looks_like_number($str) 258 218 476
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
BranchTrueFalseTotal
if ($str =~ /^\s*WHERE\s+(.*)/i) { } 198 0 198
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
BranchTrueFalseTotal
unless defined $val1 and defined $op and defined $val2 0 198 198
Condition33%2/6
defined $val1 and defined $op and defined $val2
!ll&&!rl&&r
00198
defined $val1 and defined $op
!ll&&!rl&&r
00198
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
ABCresult
0XX0
10X0
1100
1111
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
l!l
160890
MC/DC100%1/1
scalar @$params || 0
scalar @$params
Truth table100%2/2
A
A= scalar @$params
Aresult
11
00
273 1050 ▶ croak "Number of params '$num_params' does not match number of placeholders '$num_placeholders'"
Branch: 1 branch
BranchTrueFalseTotal
unless $num_placeholders == $num_params 0 1050 1050
274 unless ( $num_placeholders == $num_params );
275 1050 ▶ if ( scalar @$params )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$params) 160 890 1050
276 {
277 160 for my $i ( 0 .. $#{ $self->{values} } )
278 {
279 312 ▶ if ( $self->{values}->[$i]->{type} eq 'placeholder' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"values"}[$i]{"type"} eq "placeholder") 312 0 312
280 {
281 312 $self->{values}->[$i]->{value} = shift @$params;
282 }
283 }
284 160 ▶ if ( $self->{where_clause} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"where_clause"}) 0 160 160
285 {
286 0 ▶ if ( $self->{where_clause}->{arg1}->{type} eq 'placeholder' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"where_clause"}{"arg1"}{"type"} eq "placeholder") 0 0 0
287 {
288 0 $self->{where_clause}->{arg1}->{value} = shift @$params;
289 }
290 0 ▶ if ( $self->{where_clause}->{arg2}->{type} eq 'placeholder' )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"where_clause"}{"arg2"}{"type"} eq "placeholder") 0 0 0
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"}
l!l&&r!l&&!r
0878100
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"}
ABresult
1X1
011
000
299 978 ▶ return $self->{'NUM_OF_ROWS'} || '0E0';
Condition100%2/2
$self->{'NUM_OF_ROWS'} || '0E0'
l!l
844134
MC/DC100%1/1
$self->{'NUM_OF_ROWS'} || '0E0'
$self->{'NUM_OF_ROWS'}
Truth table100%2/2
A
A= $self->{'NUM_OF_ROWS'}
Aresult
11
00
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
BranchTrueFalseTotal
if ($self->{"ignore_missing_table"} and $@ || @err and grep {$_ =~ /$enoentrx/;} @err, $@) 100 164 264
Condition77%7/9
$self->{"ignore_missing_table"} and $@ || @err and grep {$_ =~ /$enoentrx/;} @err, $@
!ll&&!rl&&r
1640100
$self->{"ignore_missing_table"} and $@ || @err
!ll&&!rl&&r
13232100
$@ or @err
l!l&&r!l&&!r
100032
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, $@
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
316 {
317 100 $@ = '';
318 100 return ( -1, 0 );
319 }
320  
321 164 ▶ croak( $@ || $err[0] ) if ( $@ || @err );
Branch: 1 branch
BranchTrueFalseTotal
if $@ or @err 24 140 164
Condition50%3/6
$@ or @err
l!l&&r!l&&!r
240140
$@ || $err[0]
l!l&&r!l&&!r
2400
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
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $@B= $err[0]
ABresult
1X1
011
000
322 140 ▶ return ( -1, 0 ) unless $table;
Branch: 1 branch
BranchTrueFalseTotal
unless $table 0 140 140
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
BranchTrueFalseTotal
unless $table->can("insert_one_row") 262 0 262
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
BranchTrueFalseTotal
unless $self->{"column_names"} 0 262 262
346 262 ▶ my $cNum = scalar( @{ $self->{column_names} } ) if ( $self->{column_names} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"column_names"} 262 0 262
347 262 my $param_num = 0;
348  
349 262 ▶ $cNum or
Branch: 1 branch
BranchTrueFalseTotal
$cNum or croak("Bad col names in INSERT") 262 0 262
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
BranchTrueFalseTotal
if ($i < $cNum) 524 262 786
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
BranchTrueFalseTotal
$array->$#* < $maxCol and $array->[$maxCol] = undef 0 262 262
362  
363 262 ▶ $table->can('insert_new_row') ? $table->insert_new_row( $data, $array ) : $table->push_row( $data, $array );
Branch: 1 branch
BranchTrueFalseTotal
$table->can('insert_new_row') ? : 256 6 262
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
BranchTrueFalseTotal
if ($array = $table->fetch_row($data)) 102 20 122
377 {
378 102 ▶ if ( $self->eval_where( $table, $array ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eval_where($table, $array)) { } 60 42 102
379 {
380 60 ++$affected;
381 60 ▶ if ( $self->{fetched_from_key} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"fetched_from_key"}) 8 52 60
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
BranchTrueFalseTotal
if $can_dor 48 4 52
388 }
389 else
390 {
391 42 ▶ push( @rows, $array ) unless ($can_dor);
Branch: 1 branch
BranchTrueFalseTotal
unless $can_dor 2 40 42
392 }
393 }
394 20 ▶ if ($can_dor)
Branch: 1 branch
BranchTrueFalseTotal
if ($can_dor) { } 16 4 20
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
BranchTrueFalseTotal
if (not defined $a && defined $b) { } 0 144 144
elsif (DBI::looks_like_number($a) and DBI::looks_like_number($b)) { } 120 24 144
Condition33%1/3
defined $a && defined $b
!ll&&!rl&&r
00144
MC/DC0%0/2
defined $a && defined $b
defined $a defined $b
Truth table33%1/3
A && B
A= defined $aB= defined $b
ABresult
0X0
100
111
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)
!ll&&!rl&&r
240120
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)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$case_fold ? : 0 24 24
Condition0%0/3
lc $a cmp lc $b or $a cmp $b
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($array = $table->fetch_row($data)) 498 216 714
440 {
441 498 ▶ if ( $self->eval_where( $table, $array ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eval_where($table, $array)) 450 48 498
442 {
443 450 ▶ $array = $self->{fetched_value} if ( $self->{fetched_from_key} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fetched_from_key"} 8 442 450
444 450 ▶ unless ( keys %cols )
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %cols) 224 226 450
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
BranchTrueFalseTotal
if ($i < @{$self->{"column_names"};}) 866 450 1316
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
BranchTrueFalseTotal
if $self->{"fetched_from_key"} 8 442 450
464 }
465 }
466 216 ▶ if ( $self->{order_clause} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"order_clause"}) 96 120 216
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
BranchTrueFalseTotal
uc $desc eq 'DESC' ? : 8 88 96
471  
472 @rows = sort {
473 96 my ( $result, $colNum, $desc );
474 144 my $i = 0;
475 do
476 144 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
not $result and $i < @sortCols and do { do { $colNum = $sortCols[$i++]; $desc = $sortCols[$i++]; $result = &_anycmp($DBI::SQL::Nano::Statement_::a->[$colNum], $DBI::SQL::Nano::Statement_::b->[$colNum]); $result = -$result if $desc } } 0 144 144
Condition33%1/3
not $result and $i < @sortCols
!ll&&!rl&&r
14400
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $desc 40 104 144
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
BranchTrueFalseTotal
unless $table 0 94 94
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
l!l&&r!l&&!r
9202
MC/DC50%1/2
$can_usr || $can_uor
$can_usr $can_uor
Truth table66%2/3
A || B
A= $can_usrB= $can_uor
ABresult
1X1
011
000
498 94 my ( @rows, $array, $f_array, $val, $col, $i );
499  
500 94 ▶ while ( $array = $table->fetch_row($data) )
Branch: 1 branch
BranchTrueFalseTotal
if ($array = $table->fetch_row($data)) 168 74 242
501 {
502 168 ▶ if ( $self->eval_where( $table, $array ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->eval_where($table, $array)) { } 166 2 168
503 {
504 166 ▶ $array = $self->{fetched_value} if ( $self->{fetched_from_key} and $can_rwu );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fetched_from_key"} and $can_rwu 20 146 166
Condition66%2/3
$self->{"fetched_from_key"} and $can_rwu
!ll&&!rl&&r
146020
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
ABresult
0X0
100
111
505 166 ▶ my $orig_ary = clone($array) if ($can_usr);
Branch: 1 branch
BranchTrueFalseTotal
if $can_usr 164 2 166
506 166 ▶ for ( $i = 0; $i < @{ $self->{column_names} }; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$self->{"column_names"};}) 166 166 332
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
BranchTrueFalseTotal
if ($self->{"fetched_value"}) 20 146 166
513 {
514 20 ▶ if ($can_usr)
Branch: 2 branches
BranchTrueFalseTotal
if ($can_usr) { } 20 0 20
elsif ($can_uor) { } 0 0 0
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
BranchTrueFalseTotal
$can_usr ? : 144 2 146
525 }
526 else
527 {
528 2 ▶ push( @rows, $array ) unless ($can_rwu);
Branch: 1 branch
BranchTrueFalseTotal
unless $can_rwu 2 0 2
529 }
530 }
531 74 ▶ if ($can_rwu)
Branch: 1 branch
BranchTrueFalseTotal
if ($can_rwu) { } 72 2 74
532 {
533 72 foreach my $array (@rows)
534 {
535 144 ▶ if ($can_usr)
Branch: 2 branches
BranchTrueFalseTotal
if ($can_usr) { } 144 0 144
elsif ($can_uor) { } 0 0 0
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
BranchTrueFalseTotal
if ($self->{"where_clause"}) 146 462 608
563 {
564 146 ▶ if ( my $col = $self->{where_clause}->{arg1} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = $self->{"where_clause"}{"arg1"}) 146 0 146
565 {
566 146 ▶ push @cols, $col->{value} if $col->{type} eq 'column';
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"type"} eq "column" 146 0 146
567 }
568 146 ▶ if ( my $col = $self->{where_clause}->{arg2} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = $self->{"where_clause"}{"arg2"}) 146 0 146
569 {
570 146 ▶ push @cols, $col->{value} if $col->{type} eq 'column';
Branch: 1 branch
BranchTrueFalseTotal
if $col->{"type"} eq "column" 0 146 146
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
BranchTrueFalseTotal
if ($stmt_col_name and not $find_in_stmt) 1936 320 2256
Condition100%3/3
$stmt_col_name and not $find_in_stmt
!ll&&!rl&&r
224961936
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
ABresult
0X0
100
111
586 {
587 1936 ▶ while ( my ( $k, $v ) = each %dbd_nums )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %dbd_nums) 2908 0 2908
588 {
589 2908 ▶ return $v if uc $k eq uc $stmt_col_name;
Branch: 1 branch
BranchTrueFalseTotal
if uc $k eq uc $stmt_col_name 1936 972 2908
590 }
591 0 croak "No such column '$stmt_col_name'";
592 }
593 320 ▶ if ( $stmt_col_name and $find_in_stmt )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt_col_name and $find_in_stmt) 96 224 320
Condition66%2/3
$stmt_col_name and $find_in_stmt
!ll&&!rl&&r
224096
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if uc $stmt_col_name eq uc $self->{"column_names"}[$i] 96 8 104
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
BranchTrueFalseTotal
if uc $dbd_cols[$i] eq uc $stmt_col 426 414 840
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)
l!l
342426
MC/DC100%1/1
$self->{'where_clause'} || (return 1)
$self->{'where_clause'}
Truth table100%2/2
A
A= $self->{'where_clause'}
Aresult
11
00
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
BranchTrueFalseTotal
if ($val1->{'type'} eq 'column') { } 342 0 342
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
BranchTrueFalseTotal
if ($val2->{'type'} eq 'column') { } 0 342 342
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
BranchTrueFalseTotal
if ($op eq "=" and not $neg and $table->can("fetch_one_row")) 236 106 342
Condition83%5/6
$op eq "=" and not $neg and $table->can("fetch_one_row")
!ll&&!rl&&r
9610236
$op eq "=" and not $neg
!ll&&!rl&&r
960246
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")
ABCresult
0XX0
10X0
1100
1111
649 {
650 236 my $key_col = $table->fetch_one_row( 1, 1 );
651 236 ▶ if ( $pred->{arg1}->{value} =~ /^$key_col$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($pred->{"arg1"}{"value"} =~ /^$key_col$/i) 36 200 236
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
l!l
21492
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)
Aresult
11
00
659 0 ▶ if ($neg) { $match = $match ? 0 : 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($neg) 0 306 306
$match ? : 0 0 0
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
BranchTrueFalseTotal
if ($op eq "IS") 32 274 306
667 {
668 32 ▶ return 1 if ( !defined $val1 or $val1 eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $val1 or $val1 eq "" 8 24 32
Condition66%2/3
not defined $val1 or $val1 eq ""
l!l&&r!l&&!r
0824
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 ""
ABresult
1X1
011
000
669 24 return 0;
670 }
671 274 ▶ $val1 //= '';
Condition50%1/2
$val1 //= ""
l!l
2740
MC/DC0%0/1
$val1 //= ""
$val1
Truth table50%1/2
A
A= $val1
Aresult
11
00
672 274 ▶ $val2 //= '';
Condition50%1/2
$val2 //= ""
l!l
2740
MC/DC0%0/1
$val2 //= ""
$val2
Truth table50%1/2
A
A= $val2
Aresult
11
00
673 274 ▶ if ( $op =~ /LIKE|CLIKE/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /LIKE|CLIKE/i) 0 274 274
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
BranchTrueFalseTotal
if ($op eq "LIKE") 0 274 274
680 0 ▶ if ( $op eq 'CLIKE' ) { return $val1 =~ /^$val2$/si; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "CLIKE") 0 274 274
681 274 ▶ if ( DBI::looks_like_number($val1) && DBI::looks_like_number($val2) )
Branch: 1 branch
BranchTrueFalseTotal
if (DBI::looks_like_number($val1) and DBI::looks_like_number($val2)) { } 2 272 274
Condition66%2/3
DBI::looks_like_number($val1) and DBI::looks_like_number($val2)
!ll&&!rl&&r
27202
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)
ABresult
0X0
100
111
682 {
683 0 ▶ if ( $op eq '<' ) { return $val1 < $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<") 0 2 2
684 0 ▶ if ( $op eq '>' ) { return $val1 > $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq ">") 0 2 2
685 2 ▶ if ( $op eq '=' ) { return $val1 == $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "=") 2 0 2
686 0 ▶ if ( $op eq '<>' ) { return $val1 != $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<>") 0 0 0
687 0 ▶ if ( $op eq '<=' ) { return $val1 <= $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<=") 0 0 0
688 0 ▶ if ( $op eq '>=' ) { return $val1 >= $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq ">=") 0 0 0
689 }
690 else
691 {
692 0 ▶ if ( $op eq '<' ) { return $val1 lt $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<") 0 272 272
693 0 ▶ if ( $op eq '>' ) { return $val1 gt $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq ">") 0 272 272
694 272 ▶ if ( $op eq '=' ) { return $val1 eq $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "=") 208 64 272
695 0 ▶ if ( $op eq '<>' ) { return $val1 ne $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<>") 0 64 64
696 64 ▶ if ( $op eq '<=' ) { return $val1 le $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "<=") 32 32 64
697 32 ▶ if ( $op eq '>=' ) { return $val1 ge $val2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq ">=") 32 0 32
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
BranchTrueFalseTotal
unless ($self->{"params"}) 2910 536 3446
705 536 ▶ if ( defined $val_num )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val_num) 0 536 536
706 {
707 0 return $self->{"params"}->[$val_num];
708 }
709  
710 0 ▶ return wantarray ? @{ $self->{"params"} } : scalar @{ $self->{"params"} };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 536 536
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
BranchTrueFalseTotal
if ($@) 168 882 1050
720 {
721 168 chomp $@;
722 168 croak $@;
723 }
724 882 ▶ croak "Couldn't open table '$table_name'" unless $table;
Branch: 1 branch
BranchTrueFalseTotal
unless $table 0 882 882
725 882 ▶ if ( !$self->{column_names} or $self->{column_names}->[0] eq '*' )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"column_names"} or $self->{"column_names"}[0] eq "*") 480 402 882
Condition100%3/3
not $self->{"column_names"} or $self->{"column_names"}[0] eq "*"
l!l&&r!l&&!r
41070402
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 "*"
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless ($self->{"values"}) 0 690 690
736 690 ▶ if ( defined $val_num )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val_num) 690 0 690
737 {
738 690 return $self->{"values"}->[$val_num]->{value};
739 }
740 0 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
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
BranchTrueFalseTotal
if ($self->{"column_names"} and $self->{"column_names"}[0] ne "*") 982 1468 2450
Condition100%3/3
$self->{"column_names"} and $self->{"column_names"}[0] ne "*"
!ll&&!rl&&r
1194274982
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 "*"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
defined $self->{"col_names"} and "ARRAY" eq ref $self->{"col_names"} or croak("attribute 'col_names' must be defined as an array") 882 0 882
Condition33%1/3
defined $self->{"col_names"} and "ARRAY" eq ref $self->{"col_names"}
!ll&&!rl&&r
00882
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"}
ABresult
0X0
100
111
774 882 ▶ exists( $self->{col_nums} ) or $self->{col_nums} = _map_colnums( $self->{col_names} );
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"col_nums"} or $self->{"col_nums"} = _map_colnums($self->{"col_names"}) 0 882 882
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
BranchTrueFalseTotal
defined $self->{"col_nums"} and "HASH" eq ref $self->{"col_nums"} or croak("attribute 'col_nums' must be defined as a hash") 882 0 882
Condition33%1/3
defined $self->{"col_nums"} and "HASH" eq ref $self->{"col_nums"}
!ll&&!rl&&r
00882
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"}
ABresult
0X0
100
111
777  
778 882 ▶ bless( $self, ( ref($proto) || $proto ) );
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
08820
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $col_names->[$i] 0 1436 1436
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__
« blib/lib/DBI/DBD/SqlEngine.pm ↑ Summary blib/lib/DBD/Gofer/Transport/stream.pm »