Parser.pm

filter: Statementstmt 89.0% 1224 / 1375 Branchbran 73.4% 577 / 786 Conditioncond 70.8% 168 / 237 MC/DCmcdc 39.4% 54 / 137 Subroutinesub 92.7% 77 / 83 Podpod 44.7% 30 / 67 totaltotal 79.3% 2130 / 2685 SCAR 75.9
CC
506
Cov
82%
list
132.0
ROW_VALUE
66.9
CREATE
37.1
CRAP 1972.0
« Statement.pm ↑ Summary Statement/Functions.pm »
1 package SQL::Parser;
2  
3 ######################################################################
4 #
5 # This module is copyright (c), 2001,2005 by Jeff Zucker.
6 # This module is copyright (c), 2007-2017 by Jens Rehsack.
7 # All rights reserved.
8 #
9 # It may be freely distributed under the same terms as Perl itself.
10 # See below for help and copyright information (search for SYNOPSIS).
11 #
12 ######################################################################
13  
14 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use warnings FATAL => "all";
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶use constant FUNCTION_NAMES => join( '|', qw(TRIM SUBSTRING) );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 17 use constant BAREWORD_FUNCTIONS =>
19 17 ▶ join( '|', qw(TRIM SUBSTRING CURRENT_DATE CURDATE CURRENT_TIME CURTIME CURRENT_TIMESTAMP NOW UNIX_TIMESTAMP PI DBNAME) );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 17 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 17 ▶use Params::Util qw(_ARRAY0 _ARRAY _HASH);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 17 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 17 ▶use Text::Balanced qw(extract_bracketed);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 17 $VERSION = '1.412';
26  
27 BEGIN
28 {
29 17 ▶ if ( $ENV{SQL_USER_DEFS} ) { require SQL::UserDefs; }
Subroutine BEGIN: called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"SQL_USER_DEFS"}) 0 17 17
30 }
31  
32 #############################
33 # PUBLIC METHODS
34 #############################
35  
36 sub new
37 {
38 17 ▶ my $class = shift;
Subroutine new: called CC=8 SCAR=21.2
Pod documented
39 17 ▶ my $dialect = shift || 'ANSI';
Condition100%2/2
shift() || 'ANSI'
l!l
116
MC/DC100%1/1
shift() || 'ANSI'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
40 17 ▶ $dialect = 'ANSI' if ( uc $dialect eq 'ANSI' );
Branch: 1 branch
BranchTrueFalseTotal
if uc $dialect eq "ANSI" 17 0 17
41 17 ▶ $dialect = 'AnyData' if ( ( uc $dialect eq 'ANYDATA' ) or ( uc $dialect eq 'CSV' ) );
Branch: 1 branch
BranchTrueFalseTotal
if uc $dialect eq "ANYDATA" or uc $dialect eq "CSV" 0 17 17
Condition33%1/3
uc $dialect eq "ANYDATA" or uc $dialect eq "CSV"
l!l&&r!l&&!r
0017
MC/DC0%0/2
uc $dialect eq "ANYDATA" or uc $dialect eq "CSV"
uc $dialect eq "ANYDATA" uc $dialect eq "CSV"
Truth table33%1/3
A or B
A= uc $dialect eq "ANYDATA"B= uc $dialect eq "CSV"
ABresult
1X1
011
000
42 17 ▶ $dialect = 'AnyData' if ( $dialect eq 'SQL::Eval' );
Branch: 1 branch
BranchTrueFalseTotal
if $dialect eq "SQL::Eval" 0 17 17
43  
44 17 ▶ my $flags = shift || {};
Condition100%2/2
shift() || {}
l!l
116
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
45 17 $flags->{dialect} = $dialect;
46 17 ▶ $flags->{PrintError} = 1 unless ( defined( $flags->{PrintError} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flags->{"PrintError"} 6 11 17
47  
48 17 my $self = bless( $flags, $class );
49 17 $self->dialect( $self->{dialect} );
50 17 $self->set_feature_flags( $self->{select}, $self->{create} );
51  
52 17 $self->LOAD('LOAD SQL::Statement::Functions');
53  
54 17 return $self;
55 }
56  
57 sub parse
58 {
59 868 ▶ my ( $self, $sql ) = @_;
Subroutine parse: called CC=27 SCAR=34.1
Pod documented
60 868 ▶ $self->dialect( $self->{dialect} ) unless ( $self->{dialect_set} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dialect_set"} 0 868 868
61 868 $sql =~ s/^\s+//;
62 868 $sql =~ s/\s+$//;
63 868 $sql =~ s/\s*;$//;
64 868 $self->{struct} = { dialect => $self->{dialect} };
65 868 $self->{tmp} = {};
66 868 $self->{original_string} = $sql;
67 868 $self->{struct}->{original_string} = $sql;
68  
69 ################################################################
70 #
71 # COMMENTS
72  
73 # C-STYLE
74 #
75 868 ▶ my $comment_re = $self->{comment_re} || '(\/\*.*?\*\/)';
Condition100%2/2
$self->{'comment_re'} || '(\\/\\*.*?\\*\\/)'
l!l
85216
MC/DC100%1/1
$self->{'comment_re'} || '(\\/\\*.*?\\*\\/)'
$self->{'comment_re'}
Truth table100%2/2
A
A= $self->{'comment_re'}
Aresult
11
00
76 868 $self->{comment_re} = $comment_re;
77 868 my $starts_with_comment;
78 868 ▶ if ( $sql =~ /^\s*$comment_re(.*)$/s )
Branch: 1 branch
BranchTrueFalseTotal
if ($sql =~ /^\s*$comment_re(.*)$/s) 36 832 868
79 {
80 36 $self->{comment} = $1;
81 36 $sql = $2;
82 36 $starts_with_comment = 1;
83 }
84  
85 # SQL STYLE
86 #
87 # SQL-style comment can not begin inside quotes.
88 868 ▶ if ( $sql =~ s/^([^']*?(?:'[^']*'[^'])*?)(--.*)(\n|$)/$1$3/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($sql =~ s/^([^']*?(?:'[^']*'[^'])*?)(--.*)(\n|$)/$1$3/) 0 868 868
89 {
90 0 $self->{comment} = $2;
91 }
92 ################################################################
93  
94 868 $sql = $self->clean_sql($sql);
95 868 my ($com) = $sql =~ m/^\s*(\S+)\s+/s;
96 868 ▶ if ( !$com )
Branch: 1 branch
BranchTrueFalseTotal
unless ($com) 38 830 868
97 {
98 38 ▶ return 1 if ($starts_with_comment);
Branch: 1 branch
BranchTrueFalseTotal
if $starts_with_comment 36 2 38
99 2 return $self->do_err("Incomplete statement!");
100 }
101 830 $com = uc $com;
102 830 $self->{opts}->{valid_commands}->{CALL} = 1;
103 830 $self->{opts}->{valid_commands}->{LOAD} = 1;
104 830 ▶ if ( $self->{opts}->{valid_commands}->{$com} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'opts'}{'valid_commands'}{$com}) { } 830 0 830
105 {
106 830 my $rv = $self->$com($sql);
107 824 delete $self->{struct}->{literals};
108  
109 824 ▶ return $self->do_err("No command found!") unless ( $self->{struct}->{command} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"struct"}{"command"} 0 824 824
110  
111 824 $self->replace_quoted_ids();
112  
113 616 my @tables = @{ $self->{struct}->{table_names} }
114 824 ▶ if ( defined( _ARRAY0( $self->{struct}->{table_names} ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &_ARRAY0($self->{"struct"}{"table_names"}) 616 208 824
115 824 push( @{ $self->{struct}->{org_table_names} }, @tables );
116 # REMOVE schema.table info if present
117 824 ▶ @tables = map { s/^.*\.([^\.]+)$/$1/; ( -1 == index( $_, '"' ) ) ? lc $_ : $_ } @tables;
Branch: 1 branch
BranchTrueFalseTotal
(index($_, '"') == -1) ? : 689 13 702
118  
119 824 ▶ if ( exists( $self->{struct}->{join} ) && !defined( _HASH( $self->{struct}->{join} ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'struct'}{'join'} and not defined &_HASH($self->{'struct'}{'join'})) { } 464 360 824
Condition100%3/3
exists $self->{"struct"}{"join"} and not defined &_HASH($self->{"struct"}{"join"})
!ll&&!rl&&r
28476464
MC/DC100%2/2
exists $self->{"struct"}{"join"} and not defined &_HASH($self->{"struct"}{"join"})
exists $self->{"struct"}{"join"} not defined &_HASH($self->{"struct"}{"join"})
Truth table100%3/3
A and not(B)
A= exists $self->{"struct"}{"join"}B= not defined &_HASH($self->{"struct"}{"join"})
ABresult
0X0
100
111
120 {
121 464 delete $self->{struct}->{join};
122 }
123 else
124 {
125 $self->{struct}->{join}->{table_order} = $self->{struct}->{table_names}
126 if ( defined( $self->{struct}->{join}->{table_order} )
127 360 ▶ && !defined( _ARRAY0( $self->{struct}->{join}->{table_order} ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"struct"}{"join"}{"table_order"} and not defined &_ARRAY0($self->{"struct"}{"join"}{"table_order"}) 0 360 360
Condition66%2/3
defined $self->{"struct"}{"join"}{"table_order"} and not defined &_ARRAY0($self->{"struct"}{"join"}{"table_order"})
!ll&&!rl&&r
321390
MC/DC0%0/2
defined $self->{"struct"}{"join"}{"table_order"} and not defined &_ARRAY0($self->{"struct"}{"join"}{"table_order"})
defined $self->{"struct"}{"join"}{"table_order"} not defined &_ARRAY0($self->{"struct"}{"join"}{"table_order"})
Truth table66%2/3
A and not(B)
A= defined $self->{"struct"}{"join"}{"table_order"}B= not defined &_ARRAY0($self->{"struct"}{"join"}{"table_order"})
ABresult
0X0
100
111
128 58 @{ $self->{struct}->{join}->{keycols} } =
129 144 map { lc $_ } @{ $self->{struct}->{join}->{keycols} }
130 360 ▶ if ( $self->{struct}->{join}->{keycols} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"struct"}{"join"}{"keycols"} 58 302 360
131 0 @{ $self->{struct}->{join}->{shared_cols} } =
132 0 map { lc $_ } @{ $self->{struct}->{join}->{shared_cols} }
133 360 ▶ if ( $self->{struct}->{join}->{shared_cols} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"struct"}{"join"}{"shared_cols"} 0 360 360
134 }
135  
136 824 ▶ if ( defined( $self->{struct}->{column_defs} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"struct"}{"column_defs"} and defined &_ARRAY($self->{"struct"}{"column_defs"})) 787 37 824
Condition66%2/3
defined $self->{"struct"}{"column_defs"} and defined &_ARRAY($self->{"struct"}{"column_defs"})
!ll&&!rl&&r
370787
MC/DC50%1/2
defined $self->{"struct"}{"column_defs"} and defined &_ARRAY($self->{"struct"}{"column_defs"})
defined $self->{"struct"}{"column_defs"} defined &_ARRAY($self->{"struct"}{"column_defs"})
Truth table66%2/3
A and B
A= defined $self->{"struct"}{"column_defs"}B= defined &_ARRAY($self->{"struct"}{"column_defs"})
ABresult
0X0
100
111
137 && defined( _ARRAY( $self->{struct}->{column_defs} ) ) )
138 {
139 787 my $colname;
140 # FIXME SUBSTR('*')
141 my @fine_defs =
142 787 ▶ grep { defined( $_->{fullorg} ) && ( -1 == index( $_->{fullorg}, '*' ) ) } @{ $self->{struct}->{column_defs} };
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{"fullorg"} and (index($_->{"fullorg"}, "*") == -1) 595 408 1003
143 787 foreach my $col (@fine_defs)
144 {
145 586 my $colname = $col->{fullorg};
146 #$cn = lc $cn unless ( $cn =~ m/^(?:\w+\.)?"/ );
147 586 ▶ push( @{ $self->{struct}->{org_col_names} }, $self->{struct}->{ORG_NAME}->{$colname} || $colname );
Condition66%2/3
$self->{'struct'}{'ORG_NAME'}{$colname} || $colname
l!l&&r!l&&!r
2273590
MC/DC0%0/2
$self->{'struct'}{'ORG_NAME'}{$colname} || $colname
$self->{'struct'}{'ORG_NAME'}{$colname} $colname
Truth table66%2/3
A || B
A= $self->{'struct'}{'ORG_NAME'}{$colname}B= $colname
ABresult
1X1
011
000
148 }
149  
150 787 ▶ unless ( $com eq 'CREATE' )
Branch: 1 branch
BranchTrueFalseTotal
unless ($com eq "CREATE") 728 59 787
151 {
152 728 $self->{struct}->{table_names} = \@tables;
153 # For RR aliases, added quoted id protection from upper casing
154 728 foreach my $col (@fine_defs)
155 {
156 # defined( $col->{fullorg} ) && ( -1 == index( $col->{fullorg}, '*' ) ) or next;
157 455 my $orgname = $colname = $col->{fullorg};
158 455 ▶ $colname =~ m/^(?:\p{Word}+\.)?"/ or $colname = lc $colname;
Branch: 1 branch
BranchTrueFalseTotal
$colname =~ /^(?:\p{Word}+\.)?"/ or $colname = lc $colname 455 0 455
159 455 ▶ defined( $self->{struct}->{ORG_NAME}->{$colname} ) and next;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"struct"}{"ORG_NAME"}{$colname} and next 11 444 455
160 $self->{struct}->{ORG_NAME}->{$colname} =
161 444 $self->{struct}->{ORG_NAME}->{$orgname};
162 }
163 #my @uCols = map { ( $_ =~ /^(\w+\.)?"/ ) ? $_ : lc $_ } @{ $self->{struct}->{column_names} };
164 #$self->{struct}->{column_names} = \@uCols;
165 }
166 }
167  
168 824 return $rv;
169 }
170 else
171 {
172 0 $self->{struct} = {};
173 0 ▶ if ( $ENV{SQL_USER_DEFS} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"SQL_USER_DEFS"}) 0 0 0
174 {
175 0 return SQL::UserDefs::user_parse( $self, $sql );
176 }
177 0 return $self->do_err("Command '$com' not recognized or not supported!");
178 }
179 }
180  
181 sub replace_quoted_commas
182 {
183 9 ▶ my ( $self, $id ) = @_;
Subroutine replace_quoted_commas: called CC=1 SCAR=0.0
Pod documented
184 9 $id =~ s/\?COMMA\?/,/gs;
185 9 return $id;
186 }
187  
188 sub replace_quoted_ids
189 {
190 1877 ▶ my ( $self, $id ) = @_;
Subroutine replace_quoted_ids: called CC=10 SCAR=23.2
Pod documented
191 1877 ▶ $self->{struct}->{quoted_ids} or $self->{struct}->{literals} or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"struct"}{"quoted_ids"} or $self->{"struct"}{"literals"} or return 796 1081 1877
Condition100%3/3
$self->{"struct"}{"quoted_ids"} or $self->{"struct"}{"literals"}
l!l&&r!l&&!r
104977796
MC/DC100%2/2
$self->{"struct"}{"quoted_ids"} or $self->{"struct"}{"literals"}
$self->{"struct"}{"quoted_ids"} $self->{"struct"}{"literals"}
Truth table100%3/3
A or B
A= $self->{"struct"}{"quoted_ids"}B= $self->{"struct"}{"literals"}
ABresult
1X1
011
000
192 1081 ▶ if ($id)
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 1053 28 1081
193 {
194 1053 ▶ if ( $id =~ /^\?QI(\d+)\?$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($id =~ /^\?QI(\d+)\?$/) { } 44 1009 1053
elsif ($id =~ /^\?(\d+)\?$/) { } 0 1009 1009
195 {
196 44 return '"' . $self->{struct}->{quoted_ids}->[$1] . '"';
197 }
198 elsif ( $id =~ /^\?(\d+)\?$/ )
199 {
200 0 return $self->{struct}->{literals}->[$1];
201 }
202 else
203 {
204 1009 return $id;
205 }
206 }
207 28 ▶ return unless defined $self->{struct}->{table_names};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"struct"}{"table_names"} 2 26 28
208 26 my @tables = @{ $self->{struct}->{table_names} };
209 26 for my $t (@tables)
210 {
211 28 ▶ if ( $t =~ /^\?QI(.+)\?$/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($t =~ /^\?QI(.+)\?$/) { } 6 22 28
elsif ($t =~ /^\?(\d+)\?$/) { } 0 22 22
212 {
213 6 $t = '"' . $self->{struct}->{quoted_ids}->[$1] . '"';
214 }
215 elsif( $t =~ /^\?(\d+)\?$/ )
216 {
217 0 $t = $self->{struct}->{literals}->[$1];
218 }
219 }
220 26 $self->{struct}->{table_names} = \@tables;
221 26 delete $self->{struct}->{quoted_ids};
222 }
223  
224 31 ▶sub structure { $_[0]->{struct} }
Subroutine structure: called CC=1 SCAR=0.0
Pod documented
225 1 ▶sub command { my $x = $_[0]->{struct}->{command} || '' }
Subroutine command: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$_[0]{'struct'}{'command'} || ''
l!l
10
MC/DC0%0/1
$_[0]{'struct'}{'command'} || ''
$_[0]{'struct'}{'command'}
Truth table50%1/2
A
A= $_[0]{'struct'}{'command'}
Aresult
11
00
226  
227 sub feature
228 {
229 9 ▶ my ( $self, $opt_class, $opt_name, $opt_value ) = @_;
Subroutine feature: called CC=4 SCAR=17.2
Pod documented
230 9 ▶ if ( defined $opt_value )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt_value) { } 9 0 9
231 {
232 9 ▶ if ( $opt_class eq 'select' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opt_class eq 'select') { } 0 9 9
elsif ($opt_class eq 'create') { } 0 9 9
233 {
234 0 $self->set_feature_flags( { "join" => $opt_value } );
235 }
236 elsif ( $opt_class eq 'create' )
237 {
238 0 $self->set_feature_flags( undef, { $opt_name => $opt_value } );
239 }
240 else
241 {
242  
243 # patch from chromatic
244 9 $self->{opts}->{$opt_class}->{$opt_name} = $opt_value;
245  
246 # $self->{$opt_class}->{$opt_name} = $opt_value;
247 }
248 }
249 else
250 {
251 0 return $self->{opts}->{$opt_class}->{$opt_name};
252 }
253 }
254  
255 11 ▶sub errstr { $_[0]->{struct}->{errstr} }
Subroutine errstr: called CC=1 SCAR=0.0
Pod documented
256  
257 sub list
258 {
259 0 ▶ my $self = shift;
Subroutine list: not called CC=11 SCAR=48.8
Pod documented
260 0 my $com = uc shift;
261 0 ▶ return () if $com !~ /COMMANDS|RESERVED|TYPES|OPS|OPTIONS|DIALECTS/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $com =~ /COMMANDS|RESERVED|TYPES|OPS|OPTIONS|DIALECTS/i 0 0 0
262 0 ▶ $com = 'valid_commands' if $com eq 'COMMANDS';
Branch: 1 branch
BranchTrueFalseTotal
if $com eq "COMMANDS" 0 0 0
263 0 ▶ $com = 'valid_comparison_operators' if $com eq 'OPS';
Branch: 1 branch
BranchTrueFalseTotal
if $com eq "OPS" 0 0 0
264 0 ▶ $com = 'valid_data_types' if $com eq 'TYPES';
Branch: 1 branch
BranchTrueFalseTotal
if $com eq "TYPES" 0 0 0
265 0 ▶ $com = 'valid_options' if $com eq 'OPTIONS';
Branch: 1 branch
BranchTrueFalseTotal
if $com eq "OPTIONS" 0 0 0
266 0 ▶ $com = 'reserved_words' if $com eq 'RESERVED';
Branch: 1 branch
BranchTrueFalseTotal
if $com eq "RESERVED" 0 0 0
267 0 ▶ $self->dialect( $self->{dialect} ) unless $self->{dialect_set};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dialect_set"} 0 0 0
268  
269 0 ▶ return sort keys %{ $self->{opts}->{$com} } unless $com eq 'DIALECTS';
Branch: 1 branch
BranchTrueFalseTotal
unless $com eq "DIALECTS" 0 0 0
270 0 my $dDir = "SQL/Dialects";
271 0 my @dialects;
272 0 for my $dir (@INC)
273 {
274 0 local *D;
275  
276 0 ▶ if ( opendir( D, "$dir/$dDir" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (opendir D, "$dir/$dDir") 0 0 0
277 {
278 0 @dialects = grep /.*\.pm$/, readdir(D);
279 0 last;
280 }
281 }
282 0 @dialects = map { s/\.pm$//; $_ } @dialects;
283 0 return @dialects;
284 }
285  
286 sub dialect
287 {
288 18 ▶ my ( $self, $dialect ) = @_;
Subroutine dialect: called CC=5 SCAR=16.1
Pod documented
289 18 ▶ return $self->{dialect} unless ($dialect);
Branch: 1 branch
BranchTrueFalseTotal
unless $dialect 0 18 18
290 18 ▶ return $self->{dialect} if ( $self->{dialect_set} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dialect_set"} 1 17 18
291 17 $self->{opts} = {};
292 17 my $mod_class = "SQL::Dialects::$dialect";
293  
294 17 ▶ $self->_load_class($mod_class) unless $mod_class->can("get_config");
Branch: 1 branch
BranchTrueFalseTotal
unless $mod_class->can("get_config") 16 1 17
295  
296 # This is here for backwards compatibility with existing dialects
297 # before the had the role to add new methods.
298 17 ▶ $self->_inject_role( "SQL::Dialects::Role", $mod_class )
Branch: 1 branch
BranchTrueFalseTotal
unless $mod_class->can("get_config_as_hash") 0 17 17
299 unless ( $mod_class->can("get_config_as_hash") );
300  
301 17 $self->{opts} = $mod_class->get_config_as_hash();
302  
303 17 $self->create_op_regexen();
304 17 $self->{dialect} = $dialect;
305 17 $self->{dialect_set}++;
306  
307 17 return $self->{dialect};
308 }
309  
310 sub _load_class
311 {
312 34 ▶ my ( $self, $class ) = @_;
Subroutine _load_class: called CC=2 SCAR=7.0
313  
314 34 my $mod = $class;
315 34 $mod =~ s{::}{/}g;
316 34 $mod .= ".pm";
317  
318 34 local ( $!, $@ );
319 34 ▶ eval { require "$mod"; } or return $self->do_err($@);
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require "$mod" } } or return $self->do_err($@) 0 34 34
320  
321 34 return 1;
322 }
323  
324 sub _inject_role
325 {
326 0 ▶ my ( $self, $role, $dest ) = @_;
Subroutine _inject_role: not called CC=2 SCAR=17.9
327  
328 0 ▶ eval qq{
Branch: 1 branch
BranchTrueFalseTotal
eval "\n package $dest;\n use $role;\n 1;\n " or croak("Can't inject $role into ${dest}: $@") 0 0 0
329 package $dest;
330 use $role;
331 1;
332 } or croak "Can't inject $role into $dest: $@";
333 }
334  
335 sub create_op_regexen
336 {
337 20 ▶ my ($self) = @_;
Subroutine create_op_regexen: called CC=8 SCAR=21.0
Pod documented
338  
339 #
340 # DAA precompute the predicate operator regex's
341 #
342 # JZ moved this into a sub so it can be called from both
343 # dialect() and from CREATE_OPERATOR and DROP_OPERATOR
344 # since those also modify the available operators
345 #
346 20 my @allops = keys %{ $self->{opts}->{valid_comparison_operators} };
347  
348 #
349 # complement operators
350 #
351 20 my @notops;
352 20 for (@allops)
353 {
354 285 ▶ push( @notops, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if /NOT/i 80 205 285
355 if /NOT/i;
356 }
357 20 ▶ $self->{opts}->{valid_comparison_NOT_ops_regex} = '^\s*(.+)\s+(' . join( '|', @notops ) . ')\s+(.*)\s*$'
Branch: 1 branch
BranchTrueFalseTotal
if scalar @notops 20 0 20
358 if scalar @notops;
359  
360 #
361 # <>, <=, >= operators
362 #
363 20 my @compops;
364 20 for (@allops)
365 {
366 285 ▶ push( @compops, $_ )
Branch: 1 branch
BranchTrueFalseTotal
if /<=|>=|<>/ 60 225 285
367 if /<=|>=|<>/;
368 }
369 20 ▶ $self->{opts}->{valid_comparison_twochar_ops_regex} = '^\s*(.+)\s+(' . join( '|', @compops ) . ')\s+(.*)\s*$'
Branch: 1 branch
BranchTrueFalseTotal
if scalar @compops 20 0 20
370 if scalar @compops;
371  
372 #
373 # everything
374 #
375 20 ▶ $self->{opts}->{valid_comparison_ops_regex} = '^\s*(.+)\s+(' . join( '|', @allops ) . ')\s+(.*)\s*$'
Branch: 1 branch
BranchTrueFalseTotal
if scalar @allops 20 0 20
376 if scalar @allops;
377  
378 #
379 # end DAA
380 #
381 }
382  
383 ##################################################################
384 # SQL COMMANDS
385 ##################################################################
386  
387 ####################################################
388 # DROP TABLE <table_name>
389 ####################################################
390 sub DROP
391 {
392 19 ▶ my ( $self, $stmt ) = @_;
Subroutine DROP: called CC=8 SCAR=21.0
Pod undocumented
393 19 my $features = 'TYPE|KEYWORD|FUNCTION|OPERATOR|PREDICATE';
394 19 ▶ if ( $stmt =~ /^\s*DROP\s+($features)\s+(.+)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^\s*DROP\s+($features)\s+(.+)$/is) 3 16 19
395 {
396 3 my ( $sub, $arg ) = ( $1, $2 );
397 3 $sub = 'DROP_' . $sub;
398 3 return $self->$sub($arg);
399 }
400 16 my $table_name;
401 16 $self->{struct}->{command} = 'DROP';
402 16 ▶ if ( $stmt =~ /^\s*DROP\s+TABLE\s+IF\s+EXISTS\s+(.*)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^\s*DROP\s+TABLE\s+IF\s+EXISTS\s+(.*)$/is) 9 7 16
403 {
404 9 $stmt = "DROP TABLE $1";
405 9 $self->{struct}->{ignore_missing_table} = 1;
406 }
407 16 ▶ if ( $stmt =~ /^\s*DROP\s+(\S+)\s+(.+)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^\s*DROP\s+(\S+)\s+(.+)$/is) { } 16 0 16
408 {
409 16 ▶ my $com2 = $1 || '';
Condition50%1/2
$1 || ''
l!l
160
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
410 16 $table_name = $2;
411 16 ▶ if ( $com2 !~ /^TABLE$/i )
Branch: 1 branch
BranchTrueFalseTotal
unless ($com2 =~ /^TABLE$/i) 0 16 16
412 {
413 0 return $self->do_err("The command 'DROP $com2' is not recognized or not supported!");
414 }
415 16 $table_name =~ s/^\s+//;
416 16 $table_name =~ s/\s+$//;
417 16 ▶ if ( $table_name =~ /(\S+) (RESTRICT|CASCADE)/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_name =~ /(\S+) (RESTRICT|CASCADE)/i) 2 14 16
418 {
419 2 $table_name = $1;
420 2 $self->{struct}->{drop_behavior} = uc $2;
421 }
422 }
423 else
424 {
425 0 return $self->do_err("Incomplete DROP statement!");
426  
427 }
428 16 ▶ return undef unless $self->TABLE_NAME($table_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table_name) 0 16 16
429 16 $table_name = $self->replace_quoted_ids($table_name);
430 16 $self->{tmp}->{is_table_name} = { $table_name => 1 };
431 16 $self->{struct}->{table_names} = [$table_name];
432 16 return 1;
433 }
434  
435 ####################################################
436 # DELETE FROM <table_name> WHERE <search_condition>
437 ####################################################
438 sub DELETE
439 {
440 9 ▶ my ( $self, $str ) = @_;
Subroutine DELETE: called CC=5 SCAR=16.2
441 9 $self->{struct}->{command} = 'DELETE';
442 9 $str =~ s/^DELETE\s+FROM\s+/DELETE /i; # Make FROM optional
443 9 my ( $table_name, $where_clause ) = $str =~ /^DELETE (\S+)(.*)$/i;
444 9 ▶ return $self->do_err('Incomplete DELETE statement!') if !$table_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $table_name 0 9 9
445 9 ▶ return undef unless $self->TABLE_NAME($table_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table_name) 0 9 9
446 9 $self->{tmp}->{is_table_name} = { $table_name => 1 };
447 9 $self->{struct}->{table_names} = [$table_name];
448 $self->{struct}->{column_defs} = [
449 {
450 9 type => 'column',
451 value => '*'
452 }
453 ];
454 9 $where_clause =~ s/^\s+//;
455 9 $where_clause =~ s/\s+$//;
456  
457 9 ▶ if ($where_clause)
Branch: 1 branch
BranchTrueFalseTotal
if ($where_clause) 6 3 9
458 {
459 6 $where_clause =~ s/^WHERE\s*(.*)$/$1/i;
460 6 ▶ return undef unless $self->SEARCH_CONDITION($where_clause);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SEARCH_CONDITION($where_clause) 0 6 6
461 }
462 9 return 1;
463 }
464  
465 ##############################################################
466 # SELECT
467 ##############################################################
468 # SELECT [<set_quantifier>] <select_list>
469 # | <set_function_specification>
470 # FROM <from_clause>
471 # [WHERE <search_condition>]
472 # [ORDER BY <order_by_clause>]
473 # [LIMIT <limit_clause>]
474 ##############################################################
475  
476 sub SELECT
477 {
478 549 ▶ my ( $self, $str ) = @_;
Subroutine SELECT: called CC=26 SCAR=33.1
Pod undocumented
479 549 $self->{struct}->{command} = 'SELECT';
480 549 my ( $from_clause, $where_clause, $order_clause, $groupby_clause, $limit_clause );
481 549 $str =~ s/^SELECT (.+)$/$1/i;
482 549 ▶ if ( $str =~ s/^(.+) LIMIT (.+)$/$1/i ) { $limit_clause = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(.+) LIMIT (.+)$/$1/i) 9 540 549
483 549 ▶ if ( $str =~ s/^(.+) ORDER BY (.+)$/$1/i ) { $order_clause = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(.+) ORDER BY (.+)$/$1/i) 20 529 549
484 549 ▶ if ( $str =~ s/^(.+) GROUP BY (.+)$/$1/i ) { $groupby_clause = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(.+) GROUP BY (.+)$/$1/i) 8 541 549
485 549 ▶ if ( $str =~ s/^(.+?) WHERE (.+)$/$1/i ) { $where_clause = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(.+?) WHERE (.+)$/$1/i) 219 330 549
486 549 ▶ if ( $str =~ s/^(.+?) FROM (.+)$/$1/i ) { $from_clause = $2; }
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(.+?) FROM (.+)$/$1/i) 359 190 549
487  
488 # else {
489 # return $self->do_err("Couldn't find FROM clause in SELECT!");
490 # }
491 # return undef unless $self->FROM_CLAUSE($from_clause);
492 549 ▶ my $has_from_clause = $self->FROM_CLAUSE($from_clause) if ($from_clause);
Branch: 1 branch
BranchTrueFalseTotal
if $from_clause 359 190 549
493  
494 547 ▶ return undef unless ( $self->SELECT_CLAUSE($str) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SELECT_CLAUSE($str) 7 540 547
495  
496 540 ▶ if ($where_clause)
Branch: 1 branch
BranchTrueFalseTotal
if ($where_clause) 219 321 540
497 {
498 219 ▶ return undef unless ( $self->SEARCH_CONDITION($where_clause) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SEARCH_CONDITION($where_clause) 0 217 217
499 }
500 538 ▶ if ($groupby_clause)
Branch: 1 branch
BranchTrueFalseTotal
if ($groupby_clause) 7 531 538
501 {
502 7 ▶ return undef unless ( $self->GROUPBY_LIST($groupby_clause) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->GROUPBY_LIST($groupby_clause) 0 7 7
503 }
504 538 ▶ if ($order_clause)
Branch: 1 branch
BranchTrueFalseTotal
if ($order_clause) 20 518 538
505 {
506 20 ▶ return undef unless ( $self->SORT_SPEC_LIST($order_clause) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SORT_SPEC_LIST($order_clause) 0 20 20
507 }
508 538 ▶ if ($limit_clause)
Branch: 1 branch
BranchTrueFalseTotal
if ($limit_clause) 9 529 538
509 {
510 9 ▶ return undef unless ( $self->LIMIT_CLAUSE($limit_clause) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->LIMIT_CLAUSE($limit_clause) 0 9 9
511 }
512 538 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"struct"}{"join"}{"clause"} and $self->{"struct"}{"join"}{"clause"} eq "ON" or $self->{"struct"}{"multiple_tables"} and not scalar keys %{$$self{"struct"}{"join"};}) 39 499 538
Condition100%9/9
$self->{"struct"}{"join"}{"clause"} and $self->{"struct"}{"join"}{"clause"} eq "ON" or $self->{"struct"}{"multiple_tables"} and not scalar keys %{$$self{"struct"}{"join"};}
l!l&&r!l&&!r
2724487
$self->{"struct"}{"join"}{"clause"} and $self->{"struct"}{"join"}{"clause"} eq "ON"
!ll&&!rl&&r
4763527
$self->{"struct"}{"multiple_tables"} and not scalar keys %{$$self{"struct"}{"join"};}
!ll&&!rl&&r
4643512
MC/DC25%1/4
$self->{"struct"}{"join"}{"clause"} and $self->{"struct"}{"join"}{"clause"} eq "ON" or $self->{"struct"}{"multiple_tables"} and not scalar keys %{$$self{"struct"}{"join"};}
$self->{"struct"}{"join"}{"clause"} $self->{"struct"}{"join"}{"clause"} eq "ON" $self->{"struct"}{"multiple_tables"} not scalar keys %{$$self{"struct"}{"join"};}
Truth table42%3/7
A and B or C and not(D)
A= $self->{"struct"}{"join"}{"clause"}B= $self->{"struct"}{"join"}{"clause"} eq "ON"C= $self->{"struct"}{"multiple_tables"}D= not scalar keys %{$$self{"struct"}{"join"};}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
513 ( $self->{struct}->{join}->{clause} and $self->{struct}->{join}->{clause} eq 'ON' )
514 or ( $self->{struct}->{multiple_tables}
515 47 and !( scalar keys %{ $self->{struct}->{join} } ) )
516 )
517 {
518 39 ▶ return undef unless ( $self->IMPLICIT_JOIN() );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->IMPLICIT_JOIN 0 39 39
519 }
520  
521 538 ▶ if ( $self->{struct}->{set_quantifier}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"struct"}{"set_quantifier"} and "DISTINCT" eq $self->{"struct"}{"set_quantifier"} and $self->{"struct"}{"has_set_functions"} and not defined &_ARRAY($self->{"struct"}{"group_by"})) 0 538 538
Condition88%8/9
$self->{"struct"}{"set_quantifier"} and "DISTINCT" eq $self->{"struct"}{"set_quantifier"} and $self->{"struct"}{"has_set_functions"} and not defined &_ARRAY($self->{"struct"}{"group_by"})
!ll&&!rl&&r
53710
$self->{"struct"}{"set_quantifier"} and "DISTINCT" eq $self->{"struct"}{"set_quantifier"} and $self->{"struct"}{"has_set_functions"}
!ll&&!rl&&r
53161
$self->{"struct"}{"set_quantifier"} and "DISTINCT" eq $self->{"struct"}{"set_quantifier"}
!ll&&!rl&&r
53017
MC/DC0%0/4
$self->{"struct"}{"set_quantifier"} and "DISTINCT" eq $self->{"struct"}{"set_quantifier"} and $self->{"struct"}{"has_set_functions"} and not defined &_ARRAY($self->{"struct"}{"group_by"})
$self->{"struct"}{"set_quantifier"} "DISTINCT" eq $self->{"struct"}{"set_quantifier"} $self->{"struct"}{"has_set_functions"} not defined &_ARRAY($self->{"struct"}{"group_by"})
Truth table80%4/5
A and B and C and not(D)
A= $self->{"struct"}{"set_quantifier"}B= "DISTINCT" eq $self->{"struct"}{"set_quantifier"}C= $self->{"struct"}{"has_set_functions"}D= not defined &_ARRAY($self->{"struct"}{"group_by"})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
522 && ( 'DISTINCT' eq $self->{struct}->{set_quantifier} )
523 && $self->{struct}->{has_set_functions}
524 && !defined( _ARRAY( $self->{struct}->{group_by} ) ) )
525 {
526 0 delete $self->{struct}->{set_quantifier};
527 carp "Specifying DISTINCT when using aggregate functions isn't reasonable - ignored."
528 0 ▶ if ( $self->{PrintError} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PrintError"} 0 0 0
529 }
530  
531 538 return 1;
532 }
533  
534 sub GROUPBY_LIST
535 {
536 7 ▶ my ( $self, $gclause ) = @_;
Subroutine GROUPBY_LIST: called CC=3 SCAR=11.1
Pod undocumented
537 7 ▶ return 1 unless ($gclause);
Branch: 1 branch
BranchTrueFalseTotal
unless $gclause 0 7 7
538 7 my $cols = $self->ROW_VALUE_LIST($gclause);
539 7 ▶ return undef if ( $self->{struct}->{errstr} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"struct"}{"errstr"} 0 7 7
540 7 @{ $self->{struct}->{group_by} } = map { $_->{fullorg} } @{$cols};
541 7 return 1;
542 }
543  
544 sub IMPLICIT_JOIN
545 {
546 39 ▶ my $self = $_[0];
Subroutine IMPLICIT_JOIN: called CC=4 SCAR=14.0
Pod undocumented
547 39 delete $self->{struct}->{multiple_tables};
548 39 ▶ if ( !$self->{struct}->{join}->{clause}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"struct"}{"join"}{"clause"} or $self->{"struct"}{"join"}{"clause"} ne "ON") 12 27 39
Condition66%2/3
not $self->{"struct"}{"join"}{"clause"} or $self->{"struct"}{"join"}{"clause"} ne "ON"
l!l&&r!l&&!r
12027
MC/DC50%1/2
not $self->{"struct"}{"join"}{"clause"} or $self->{"struct"}{"join"}{"clause"} ne "ON"
not $self->{"struct"}{"join"}{"clause"} $self->{"struct"}{"join"}{"clause"} ne "ON"
Truth table66%2/3
not(A) or B
A= not $self->{"struct"}{"join"}{"clause"}B= $self->{"struct"}{"join"}{"clause"} ne "ON"
ABresult
1X1
011
000
549 or $self->{struct}->{join}->{clause} ne 'ON' )
550 {
551 12 $self->{struct}->{join}->{type} = 'INNER';
552 12 $self->{struct}->{join}->{clause} = 'IMPLICIT';
553 }
554 39 ▶ if ( defined $self->{struct}->{keycols} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'struct'}{'keycols'}) { } 39 0 39
555 {
556 39 my @keys;
557 39 my @keys2 = @keys = @{ $self->{struct}->{keycols} };
558 39 $self->{struct}->{join}->{table_order} = $self->order_joins( \@keys2 );
559 39 @{ $self->{struct}->{join}->{keycols} } = @keys;
560 39 delete $self->{struct}->{keycols};
561 }
562 else
563 {
564 0 return $self->do_err("No equijoin condition in WHERE or ON clause");
565 }
566 39 return 1;
567 }
568  
569 sub EXPLICIT_JOIN
570 {
571 64 ▶ my ( $self, $remainder ) = @_;
Subroutine EXPLICIT_JOIN: called CC=31 SCAR=35.7
Pod undocumented
572 64 ▶ return undef unless ($remainder);
Branch: 1 branch
BranchTrueFalseTotal
unless $remainder 0 64 64
573 64 my ( $tableA, $tableB, $keycols, $jtype, $natural );
574 64 ▶ if ( $remainder =~ m/^(.+?) (NATURAL|INNER|LEFT|RIGHT|FULL|CROSS|UNION|JOIN)(.+)$/is )
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder =~ /^(.+?) (NATURAL|INNER|LEFT|RIGHT|FULL|CROSS|UNION|JOIN)(.+)$/is) { } 64 0 64
575 {
576 64 $tableA = $1;
577 64 $remainder = $2 . $3;
578 }
579 else
580 {
581 0 ( $tableA, $remainder ) = $remainder =~ m/^(\S+) (.*)/i;
582 }
583 64 ▶ if ( $remainder =~ m/^NATURAL (.+)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder =~ /^NATURAL (.+)/) 15 49 64
584 {
585 15 $self->{struct}->{join}->{clause} = 'NATURAL';
586 15 $natural++;
587 15 $remainder = $1;
588 }
589 64 ▶ if ( $remainder =~ m/^(INNER|LEFT|RIGHT|FULL|CROSS|UNION) JOIN (.+)/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder =~ /^(INNER|LEFT|RIGHT|FULL|CROSS|UNION) JOIN (.+)/i) 43 21 64
590 {
591 43 $jtype = $self->{struct}->{join}->{clause} = uc($1);
592 43 $remainder = $2;
593 43 ▶ $jtype = "$jtype OUTER" if $jtype !~ /INNER|UNION/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $jtype =~ /INNER|UNION/i 34 9 43
594 }
595 64 ▶ if ( $remainder =~ m/^(LEFT|RIGHT|FULL|CROSS) OUTER JOIN (.+)/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder =~ /^(LEFT|RIGHT|FULL|CROSS) OUTER JOIN (.+)/i) 0 64 64
596 {
597 0 $jtype = $self->{struct}->{join}->{clause} = uc($1) . " OUTER";
598 0 $remainder = $2;
599 }
600 64 ▶ if ( $remainder =~ m/^JOIN (.+)/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder =~ /^JOIN (.+)/i) 21 43 64
601 {
602 21 $jtype = 'INNER';
603 21 $self->{struct}->{join}->{clause} = 'DEFAULT INNER';
604 21 $remainder = $1;
605 }
606 64 ▶ if ( $self->{struct}->{join} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"struct"}{"join"}) 64 0 64
607 {
608 64 ▶ if ( $remainder && $remainder =~ m/^(.+?) USING \(([^\)]+)\)(.*)/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder and $remainder =~ /^(.+?) USING \(([^\)]+)\)(.*)/i) 20 44 64
Condition66%2/3
$remainder and $remainder =~ /^(.+?) USING \(([^\)]+)\)(.*)/i
!ll&&!rl&&r
04420
MC/DC50%1/2
$remainder and $remainder =~ /^(.+?) USING \(([^\)]+)\)(.*)/i
$remainder $remainder =~ /^(.+?) USING \(([^\)]+)\)(.*)/i
Truth table66%2/3
A and B
A= $remainderB= $remainder =~ /^(.+?) USING \(([^\)]+)\)(.*)/i
ABresult
0X0
100
111
609 {
610 20 $self->{struct}->{join}->{clause} = 'USING';
611 20 $tableB = $1;
612 20 my $keycolstr = $2;
613 20 $remainder = $3;
614 20 @$keycols = split( /,/, $keycolstr );
615 }
616 64 ▶ if ( $remainder && $remainder =~ m/^(.+?) ON (.+)/i )
Branch: 2 branches
BranchTrueFalseTotal
if ($remainder and $remainder =~ /^(.+?) ON (.+)/i) { } 27 37 64
elsif ($remainder =~ /^(.+?)$/i) { } 18 19 37
Condition100%3/3
$remainder and $remainder =~ /^(.+?) ON (.+)/i
!ll&&!rl&&r
191827
MC/DC100%2/2
$remainder and $remainder =~ /^(.+?) ON (.+)/i
$remainder $remainder =~ /^(.+?) ON (.+)/i
Truth table100%3/3
A and B
A= $remainderB= $remainder =~ /^(.+?) ON (.+)/i
ABresult
0X0
100
111
617 {
618 27 $self->{struct}->{join}->{clause} = 'ON';
619 27 $tableB = $1;
620 27 my $keycolstr = $2;
621 27 $remainder = $3;
622 27 @$keycols = split(/ AND|OR /i, $keycolstr);
623  
624 return undef
625 27 ▶ unless $self->TABLE_NAME_LIST( $tableA . ',' . $tableB );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME_LIST($tableA . ',' . $tableB) 0 27 27
626  
627 # $self->{tmp}->{is_table_name}->{"$tableA"} = 1;
628 # $self->{tmp}->{is_table_name}->{"$tableB"} = 1;
629 27 for my $keycol (@$keycols)
630 {
631 48 my %is_done;
632 48 $keycol =~ s/\)|\(//g;
633 48 my ( $arg1, $arg2 ) = split( m/ [>=<] /, $keycol );
634 48 my ( $c1, $c2 ) = ( $arg1, $arg2 );
635 48 $c1 =~ s/^.*\.([^\.]+)$/$1/;
636 48 $c2 =~ s/^.*\.([^\.]+)$/$1/;
637 48 ▶ if ( $c1 eq $c2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($c1 eq $c2) { } 9 39 48
638 {
639 9 ▶ return undef unless ( $arg1 = $self->ROW_VALUE($c1) );
Branch: 1 branch
BranchTrueFalseTotal
unless $arg1 = $self->ROW_VALUE($c1) 0 9 9
640 9 ▶ if ( $arg1->{type} eq 'column' and !$is_done{$c1} )
Branch: 1 branch
BranchTrueFalseTotal
if ($arg1->{"type"} eq "column" and not $is_done{$c1}) 9 0 9
Condition33%1/3
$arg1->{"type"} eq "column" and not $is_done{$c1}
!ll&&!rl&&r
009
MC/DC0%0/2
$arg1->{"type"} eq "column" and not $is_done{$c1}
$arg1->{"type"} eq "column" not $is_done{$c1}
Truth table33%1/3
A and not(B)
A= $arg1->{"type"} eq "column"B= not $is_done{$c1}
ABresult
0X0
100
111
641 {
642 9 push( @{ $self->{struct}->{keycols} }, $arg1->{value} );
643 9 $is_done{$c1} = 1;
644 }
645 }
646 else
647 {
648 39 ▶ return undef unless ( $arg1 = $self->ROW_VALUE($arg1) );
Branch: 1 branch
BranchTrueFalseTotal
unless $arg1 = $self->ROW_VALUE($arg1) 0 39 39
649 39 ▶ return undef unless ( $arg2 = $self->ROW_VALUE($arg2) );
Branch: 1 branch
BranchTrueFalseTotal
unless $arg2 = $self->ROW_VALUE($arg2) 0 39 39
650 39 ▶ if ( $arg1->{type} eq 'column'
Branch: 1 branch
BranchTrueFalseTotal
if ($arg1->{"type"} eq "column" and $arg2->{"type"} eq "column") 34 5 39
Condition66%2/3
$arg1->{"type"} eq "column" and $arg2->{"type"} eq "column"
!ll&&!rl&&r
0534
MC/DC50%1/2
$arg1->{"type"} eq "column" and $arg2->{"type"} eq "column"
$arg1->{"type"} eq "column" $arg2->{"type"} eq "column"
Truth table66%2/3
A and B
A= $arg1->{"type"} eq "column"B= $arg2->{"type"} eq "column"
ABresult
0X0
100
111
651 and $arg2->{type} eq 'column' )
652 {
653 34 push( @{ $self->{struct}->{keycols} }, $arg1->{value} );
654 34 push( @{ $self->{struct}->{keycols} }, $arg2->{value} );
655  
656 # delete $self->{struct}->{where_clause};
657 }
658 }
659 }
660 }
661 elsif ( $remainder =~ /^(.+?)$/i )
662 {
663 18 $tableB = $1;
664 18 $remainder = $2;
665 }
666 64 ▶ $remainder =~ s/^\s+// if ($remainder);
Branch: 1 branch
BranchTrueFalseTotal
if $remainder 0 64 64
667 }
668  
669 64 ▶ if ($jtype)
Branch: 1 branch
BranchTrueFalseTotal
if ($jtype) 64 0 64
670 {
671 64 ▶ $jtype = "NATURAL $jtype" if ($natural);
Branch: 1 branch
BranchTrueFalseTotal
if $natural 15 49 64
672 64 ▶ if ( $natural and $keycols )
Branch: 1 branch
BranchTrueFalseTotal
if ($natural and $keycols) 0 64 64
Condition66%2/3
$natural and $keycols
!ll&&!rl&&r
49150
MC/DC0%0/2
$natural and $keycols
$natural $keycols
Truth table66%2/3
A and B
A= $naturalB= $keycols
ABresult
0X0
100
111
673 {
674 0 return $self->do_err(qq{Can't use NATURAL with a USING or ON clause!});
675 }
676 64 ▶ return undef unless ( $self->TABLE_NAME_LIST("$tableA,$tableB") );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME_LIST("$tableA,$tableB") 2 62 64
677 62 $self->{struct}->{join}->{type} = $jtype;
678 62 ▶ $self->{struct}->{join}->{keycols} = $keycols if ($keycols);
Branch: 1 branch
BranchTrueFalseTotal
if $keycols 46 16 62
679 62 return 1;
680 }
681 0 return $self->do_err("Couldn't parse explicit JOIN!");
682 }
683  
684 sub SELECT_CLAUSE
685 {
686 547 ▶ my ( $self, $str ) = @_;
Subroutine SELECT_CLAUSE: called CC=4 SCAR=13.9
Pod undocumented
687 547 ▶ return undef unless ($str);
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 547 547
688 547 ▶ if ( $str =~ s/^(DISTINCT|ALL) (.+)$/$2/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/^(DISTINCT|ALL) (.+)$/$2/i) 8 539 547
689 {
690 8 $self->{struct}->{set_quantifier} = uc($1);
691 }
692 547 ▶ return undef unless ( $self->SELECT_LIST($str) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SELECT_LIST($str) 7 540 547
693 }
694  
695 sub FROM_CLAUSE
696 {
697 359 ▶ my ( $self, $str ) = @_;
Subroutine FROM_CLAUSE: called CC=5 SCAR=16.1
Pod undocumented
698 359 ▶ return undef unless $str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 359 359
699 359 ▶ if ( $str =~ m/ JOIN /i )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ / JOIN /i) { } 64 295 359
700 {
701 64 ▶ return undef unless $self->EXPLICIT_JOIN($str);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->EXPLICIT_JOIN($str) 2 62 64
702 }
703 else
704 {
705 295 ▶ return undef unless $self->TABLE_NAME_LIST($str);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME_LIST($str) 3 290 293
706 }
707 }
708  
709 sub INSERT
710 {
711 172 ▶ my ( $self, $str ) = @_;
Subroutine INSERT: called CC=12 SCAR=25.9
Pod undocumented
712 172 my $col_str;
713 172 $str =~ s/^INSERT\s+INTO\s+/INSERT /i; # allow INTO to be optional
714 172 my ( $table_name, $val_str ) = $str =~ m/^INSERT\s+(.+?)\s+VALUES\s+(\(.+\))$/i;
715 172 ▶ if ( $table_name and $table_name =~ m/[()]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_name and $table_name =~ /[()]/) 5 167 172
Condition66%2/3
$table_name and $table_name =~ /[()]/
!ll&&!rl&&r
01675
MC/DC50%1/2
$table_name and $table_name =~ /[()]/
$table_name $table_name =~ /[()]/
Truth table66%2/3
A and B
A= $table_nameB= $table_name =~ /[()]/
ABresult
0X0
100
111
716 {
717 5 ( $table_name, $col_str, $val_str ) = $str =~ m/^INSERT\s+(.+?)\s+\((.+?)\)\s+VALUES\s+(\(.+\))$/i;
718 }
719 172 ▶ return $self->do_err('No table name specified!') unless ($table_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $table_name 0 172 172
720 172 ▶ return $self->do_err('Missing values list!') unless ( defined $val_str );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val_str 0 172 172
721 172 ▶ return undef unless ( $self->TABLE_NAME($table_name) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table_name) 0 172 172
722 172 $self->{struct}->{command} = 'INSERT';
723 172 $self->{struct}->{table_names} = [$table_name];
724 172 ▶ if ($col_str)
Branch: 1 branch
BranchTrueFalseTotal
if ($col_str) { } 5 167 172
725 {
726 5 ▶ return undef unless ( $self->{struct}->{column_defs} = $self->ROW_VALUE_LIST($col_str) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"struct"}{"column_defs"} = $self->ROW_VALUE_LIST($col_str) 0 5 5
727 }
728 else
729 {
730 $self->{struct}->{column_defs} = [
731 {
732 167 type => 'column',
733 value => '*'
734 }
735 ];
736 }
737 172 $self->{struct}->{values} = [];
738 172 ▶ for (my ($v,$line_str) = $val_str;
Branch: 1 branch
BranchTrueFalseTotal
if (($line_str, $v) = &extract_bracketed($v, "('", "") and defined $line_str) 178 0 178
Condition33%1/3
($line_str, $v) = &extract_bracketed($v, "('", "") and defined $line_str
!ll&&!rl&&r
00178
MC/DC0%0/2
($line_str, $v) = &extract_bracketed($v, "('", "") and defined $line_str
($line_str, $v) = &extract_bracketed($v, "('", "") defined $line_str
Truth table33%1/3
A and B
A= ($line_str, $v) = &extract_bracketed($v, "('", "")B= defined $line_str
ABresult
0X0
100
111
739 (($line_str,$v)=extract_bracketed($v,"('",'')) && defined $line_str;
740 ) {
741 178 ▶ return undef unless ( $self->LITERAL_LIST(substr($line_str,1,-1)) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->LITERAL_LIST(substr($line_str, 1, -1)) 0 178 178
742 178 ▶ last unless $v =~ s/\A\s*,\s*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $v =~ s/\A\s*,\s*// 172 6 178
743 }
744  
745 172 return 1;
746 }
747  
748 ###################################################################
749 # UPDATE ::=
750 #
751 # UPDATE <table> SET <set_clause_list> [ WHERE <search_condition>]
752 #
753 ###################################################################
754 sub UPDATE
755 {
756 10 ▶ my ( $self, $str ) = @_;
Subroutine UPDATE: called CC=10 SCAR=23.3
Pod undocumented
757 10 $self->{struct}->{command} = 'UPDATE';
758 10 my ( $table_name, $remainder ) = $str =~ m/^UPDATE (.+?) SET (.+)$/i;
759 10 ▶ return $self->do_err('Incomplete UPDATE clause') unless ( $table_name && $remainder );
Branch: 1 branch
BranchTrueFalseTotal
unless $table_name and $remainder 0 10 10
Condition33%1/3
$table_name and $remainder
!ll&&!rl&&r
0010
MC/DC0%0/2
$table_name and $remainder
$table_name $remainder
Truth table33%1/3
A and B
A= $table_nameB= $remainder
ABresult
0X0
100
111
760 10 ▶ return undef unless ( $self->TABLE_NAME($table_name) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table_name) 0 10 10
761 10 $self->{tmp}->{is_table_name} = { $table_name => 1 };
762 10 $self->{struct}->{table_names} = [$table_name];
763 10 my ( $set_clause, $where_clause ) = $remainder =~ m/(.*?) WHERE (.*)$/i;
764 10 ▶ $set_clause = $remainder if ( !$set_clause );
Branch: 1 branch
BranchTrueFalseTotal
unless $set_clause 4 6 10
765 10 ▶ return undef unless ( $self->SET_CLAUSE_LIST($set_clause) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SET_CLAUSE_LIST($set_clause) 1 9 10
766  
767 9 ▶ if ($where_clause)
Branch: 1 branch
BranchTrueFalseTotal
if ($where_clause) 6 3 9
768 {
769 6 ▶ return undef unless ( $self->SEARCH_CONDITION($where_clause) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SEARCH_CONDITION($where_clause) 0 6 6
770 }
771  
772 9 my @vals = @{ $self->{struct}->{values}->[0] };
773 9 my $num_val_placeholders = 0;
774 9 for my $v (@vals)
775 {
776 14 ▶ ++$num_val_placeholders if ( $v->{type} eq 'placeholder' );
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"type"} eq "placeholder" 4 10 14
777 }
778 9 $self->{struct}->{num_val_placeholders} = $num_val_placeholders;
779  
780 9 return 1;
781 }
782  
783 ############
784 # FUNCTIONS
785 ############
786 sub LOAD
787 {
788 18 ▶ my ( $self, $str ) = @_;
Subroutine LOAD: called CC=3 SCAR=11.0
Pod undocumented
789 18 $self->{struct}->{command} = 'LOAD';
790 18 $self->{struct}->{no_execute} = 1;
791 18 my ($package) = $str =~ /^LOAD\s+(.+)$/;
792 18 $str = $package;
793 18 $package =~ s/\?(\d+)\?/$self->{struct}->{literals}->[$1]/g;
794  
795 18 $self->_load_class($package);
796  
797 18 my %subs = eval '%' . $package . '::';
798  
799 18 for my $sub ( keys %subs )
800 {
801 2992 ▶ next unless ( $sub =~ m/^SQL_FUNCTION_([A-Z_0-9]+)$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $sub =~ /^SQL_FUNCTION_([A-Z_0-9]+)$/ 1138 1854 2992
802 1854 my $funcName = uc $1;
803 1854 my $subname = $package . '::' . 'SQL_FUNCTION_' . $funcName;
804 1854 $self->{opts}->{function_names}->{$funcName} = $subname;
805 1854 delete $self->{opts}->{_udf_function_names};
806 }
807 18 1;
808 }
809  
810 sub CREATE_RAM_TABLE
811 {
812 0 ▶ my ( $self, $stmt ) = @_;
Subroutine CREATE_RAM_TABLE: not called CC=5 SCAR=34.0
Pod undocumented
813 0 $self->{struct}->{is_ram_table} = 1;
814 0 $self->{struct}->{command} = 'CREATE_RAM_TABLE';
815 0 my ( $table_name, $table_element_def, %is_col_name );
816 0 ▶ if ( $stmt =~ /^(\S+)\s+LIKE\s*(.+)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^(\S+)\s+LIKE\s*(.+)$/is) { } 0 0 0
817 {
818 0 $table_name = $1;
819 0 $table_element_def = $2;
820 0 ▶ if ( $table_element_def =~ /^(.*)\s+KEEP CONNECTION\s*$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_element_def =~ /^(.*)\s+KEEP CONNECTION\s*$/i) 0 0 0
821 {
822 0 $table_element_def = $1;
823 0 $self->{struct}->{ram_table_keep_connection} = 1;
824 }
825 }
826 else
827 {
828 0 return $self->CREATE("CREATE TABLE $stmt");
829 }
830 0 ▶ return undef unless $self->TABLE_NAME($table_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table_name) 0 0 0
831 0 for my $col ( split ',', $table_element_def )
832 {
833 0 push( @{ $self->{struct}->{column_defs} }, $self->ROW_VALUE($col) );
834 }
835 0 $self->{struct}->{table_names} = [$table_name];
836 0 return 1;
837 }
838  
839 sub CREATE_FUNCTION
840 {
841 3 ▶ my ( $self, $stmt ) = @_;
Subroutine CREATE_FUNCTION: called CC=6 SCAR=18.1
Pod undocumented
842 3 $self->{struct}->{command} = 'CREATE_FUNCTION';
843 3 $self->{struct}->{no_execute} = 1;
844 3 my ( $func, $subname );
845 3 $stmt =~ s/\s*EXTERNAL//i;
846 3 ▶ if ( $stmt =~ /^(\S+)\s+NAME\s+(.*)$/smi )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^(\S+)\s+NAME\s+(.*)$/ism) 2 1 3
847 {
848 2 $func = trim($1);
849 2 $subname = trim($2);
850 }
851 3 ▶ $func ||= $stmt;
Condition66%2/3
$func ||= $stmt
l!l&&r!l&&!r
210
MC/DC0%0/2
$func ||= $stmt
$func $stmt
Truth table66%2/3
A ||= B
A= $funcB= $stmt
ABresult
1X1
011
000
852 3 ▶ $subname ||= $func;
Condition66%2/3
$subname ||= $func
l!l&&r!l&&!r
210
MC/DC0%0/2
$subname ||= $func
$subname $func
Truth table66%2/3
A ||= B
A= $subnameB= $func
ABresult
1X1
011
000
853 3 ▶ if ( $func =~ /^\?QI(\d+)\?$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($func =~ /^\?QI(\d+)\?$/) 0 3 3
854 {
855 0 $func = $self->{struct}->{quoted_ids}->[$1];
856 }
857 3 ▶ if ( $subname =~ /^\?QI(\d+)\?$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($subname =~ /^\?QI(\d+)\?$/) 2 1 3
858 {
859 2 $subname = $self->{struct}->{quoted_ids}->[$1];
860 }
861 3 $self->{opts}->{function_names}->{ uc $func } = $subname;
862 3 delete $self->{opts}->{_udf_function_names};
863  
864 3 return 1;
865 }
866  
867 sub CALL
868 {
869 0 ▶ my ( $self, $stmt ) = @_;
Subroutine CALL: not called CC=1 SCAR=6.9
Pod undocumented
870 0 $stmt =~ s/^CALL\s+(.*)/$1/i;
871 0 $self->{struct}->{command} = 'CALL';
872 0 $self->{struct}->{procedure} = $self->ROW_VALUE($stmt);
873 0 return 1;
874 }
875  
876 sub CREATE_TYPE
877 {
878 3 ▶ my ( $self, $type ) = @_;
Subroutine CREATE_TYPE: called CC=1 SCAR=0.0
Pod undocumented
879 3 $self->{struct}->{command} = 'CREATE_TYPE';
880 3 $self->{struct}->{no_execute} = 1;
881 3 $self->feature( 'valid_data_types', uc $type, 1 );
882 }
883  
884 sub DROP_TYPE
885 {
886 1 ▶ my ( $self, $type ) = @_;
Subroutine DROP_TYPE: called CC=1 SCAR=0.0
Pod undocumented
887 1 $self->{struct}->{command} = 'DROP_TYPE';
888 1 $self->{struct}->{no_execute} = 1;
889 1 $self->feature( 'valid_data_types', uc $type, 0 );
890 }
891  
892 sub CREATE_KEYWORD
893 {
894 1 ▶ my ( $self, $type ) = @_;
Subroutine CREATE_KEYWORD: called CC=1 SCAR=0.0
Pod undocumented
895 1 $self->{struct}->{command} = 'CREATE_KEYWORD';
896 1 $self->{struct}->{no_execute} = 1;
897 1 $self->feature( 'reserved_words', uc $type, 1 );
898 }
899  
900 sub DROP_KEYWORD
901 {
902 1 ▶ my ( $self, $type ) = @_;
Subroutine DROP_KEYWORD: called CC=1 SCAR=0.0
Pod undocumented
903 1 $self->{struct}->{command} = 'DROP_KEYWORD';
904 1 $self->{struct}->{no_execute} = 1;
905 1 $self->feature( 'reserved_words', uc $type, 0 );
906 }
907  
908 sub CREATE_OPERATOR
909 {
910 2 ▶ my ( $self, $stmt ) = @_;
Subroutine CREATE_OPERATOR: called CC=6 SCAR=20.5
Pod undocumented
911 2 $self->{struct}->{command} = 'CREATE_OPERATOR';
912 2 $self->{struct}->{no_execute} = 1;
913  
914 2 my ( $func, $subname );
915 2 $stmt =~ s/\s*EXTERNAL//i;
916 2 ▶ if ( $stmt =~ /^(\S+)\s+NAME\s+(.*)$/smi )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^(\S+)\s+NAME\s+(.*)$/ism) 0 2 2
917 {
918 0 $func = trim($1);
919 0 $subname = trim($2);
920 }
921 2 ▶ $func ||= $stmt;
Condition33%1/3
$func ||= $stmt
l!l&&r!l&&!r
020
MC/DC0%0/2
$func ||= $stmt
$func $stmt
Truth table33%1/3
A ||= B
A= $funcB= $stmt
ABresult
1X1
011
000
922 2 ▶ $subname ||= $func;
Condition33%1/3
$subname ||= $func
l!l&&r!l&&!r
020
MC/DC0%0/2
$subname ||= $func
$subname $func
Truth table33%1/3
A ||= B
A= $subnameB= $func
ABresult
1X1
011
000
923 2 ▶ if ( $func =~ /^\?QI(\d+)\?$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($func =~ /^\?QI(\d+)\?$/) 0 2 2
924 {
925 0 $func = $self->{struct}->{quoted_ids}->[$1];
926 }
927 2 ▶ if ( $subname =~ /^\?QI(\d+)\?$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($subname =~ /^\?QI(\d+)\?$/) 0 2 2
928 {
929 0 $subname = $self->{struct}->{quoted_ids}->[$1];
930 }
931 2 $self->{opts}->{function_names}->{ uc $func } = $subname;
932 2 delete $self->{opts}->{_udf_function_names};
933  
934 2 $self->feature( 'valid_comparison_operators', uc $func, 1 );
935 2 return $self->create_op_regexen();
936 }
937  
938 sub DROP_OPERATOR
939 {
940 1 ▶ my ( $self, $type ) = @_;
Subroutine DROP_OPERATOR: called CC=1 SCAR=0.0
Pod undocumented
941 1 $self->{struct}->{command} = 'DROP_OPERATOR';
942 1 $self->{struct}->{no_execute} = 1;
943 1 $self->feature( 'valid_comparison_operators', uc $type, 0 );
944 1 return $self->create_op_regexen();
945 }
946  
947 sub replace_quoted($)
948 {
949 9 ▶ my ( $self, $str ) = @_;
Subroutine replace_quoted: called CC=1 SCAR=0.0
Pod documented
950 9 my @l = map { $self->replace_quoted_ids($_) } split( ',', $self->replace_quoted_commas($str) );
951 9 return @l;
952 }
953  
954 #########
955 # CREATE
956 #########
957 sub CREATE
958 {
959 70 ▶ my ( $self, $stmt ) = @_;
Subroutine CREATE: called CC=30 SCAR=36.1
Pod undocumented
960 70 my $features = 'TYPE|KEYWORD|FUNCTION|OPERATOR|PREDICATE';
961 70 ▶ if ( $stmt =~ m/^\s*CREATE\s+($features)\s+(.+)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^\s*CREATE\s+($features)\s+(.+)$/is) 9 61 70
962 {
963 9 my ( $sub, $arg ) = ( $1, $2 );
964 9 $sub = 'CREATE_' . uc $sub;
965 9 return $self->$sub($arg);
966 }
967  
968 61 $stmt =~ s/^CREATE (LOCAL|GLOBAL) /CREATE /si;
969 61 ▶ if ( $stmt =~ m/^\s*CREATE\s+(?:TEMP|TEMPORARY)\s+TABLE\s+(.+)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^\s*CREATE\s+(?:TEMP|TEMPORARY)\s+TABLE\s+(.+)$/is) 43 18 61
970 {
971 43 $stmt = "CREATE TABLE $1";
972 43 $self->{struct}->{is_ram_table} = 1;
973 }
974 61 $self->{struct}->{command} = 'CREATE';
975 61 my ( $table_name, $table_element_def, %is_col_name );
976  
977 61 ▶ if ( $stmt =~ m/^(.*) ON COMMIT (DELETE|PRESERVE) ROWS\s*$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt =~ /^(.*) ON COMMIT (DELETE|PRESERVE) ROWS\s*$/is) 4 57 61
978 {
979 4 $stmt = $1;
980 4 $self->{struct}->{commit_behaviour} = $2;
981  
982 # return $self->do_err(
983 # "Can't specify commit behaviour for permanent tables."
984 # )
985 # if !defined $self->{struct}->{table_type}
986 # or $self->{struct}->{table_type} !~ /TEMPORARY/;
987 }
988 61 ▶ if ( $stmt =~ m/^CREATE TABLE (\S+) \((.*)\)$/si )
Branch: 2 branches
BranchTrueFalseTotal
if ($stmt =~ /^CREATE TABLE (\S+) \((.*)\)$/is) { } 61 0 61
elsif ($stmt =~ /^CREATE TABLE (\S+) AS (.*)$/is) { } 0 0 0
989 {
990 61 $table_name = $1;
991 61 $table_element_def = $2;
992 }
993 elsif ( $stmt =~ m/^CREATE TABLE (\S+) AS (.*)$/si )
994 {
995 0 $table_name = $1;
996 0 my $subquery = $2;
997 0 ▶ return undef unless $self->TABLE_NAME($table_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table_name) 0 0 0
998 0 $self->{struct}->{table_names} = [$table_name];
999  
1000 # undo subquery replaces
1001 0 $subquery =~ s/\?(\d+)\?/'$self->{struct}{literals}[$1]'/g;
1002 0 $subquery =~ s/\?QI(\d+)\?/"$self->{struct}->{quoted_ids}->[$1]"/g;
1003 0 $subquery =~ s/\?COMMA\?/,/gs;
1004 0 $self->{struct}->{subquery} = $subquery;
1005 0 ▶ if ( -1 != index( $subquery, '?' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (index($subquery, "?") != -1) 0 0 0
1006 {
1007 0 ++$self->{struct}->{num_placeholders};
1008 }
1009 0 return 1;
1010 }
1011 else
1012 {
1013 0 return $self->do_err("Can't find column definitions!");
1014 }
1015 61 ▶ return undef unless ( $self->TABLE_NAME($table_name) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table_name) 0 61 61
1016 61 $table_element_def =~ s/\s+\(/(/g;
1017 61 my $primary_defined;
1018 61 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($table_element_def =~ s/( # start of grouping 1 \( # match a bracket; vi compatible bracket -> \)( [^)]+ # everything up to but not including the comma, no nesting of brackets is required ) # end of grouping 1 , # the comma to be removed to allow splitting on commas ( # start of grouping 2; vi compatible bracket -> \( .*?\) # everything up to and including the end bracket )/$1?COMMA?$2/gsx) 6 61 67
1019 $table_element_def =~ s/( # start of grouping 1
1020 \( # match a bracket; vi compatible bracket -> \)(
1021 [^)]+ # everything up to but not including the comma, no nesting of brackets is required
1022 ) # end of grouping 1
1023 , # the comma to be removed to allow splitting on commas
1024 ( # start of grouping 2; vi compatible bracket -> \(
1025 .*?\) # everything up to and including the end bracket
1026 )/$1?COMMA?$2/sgx
1027 )
1028 {
1029 }
1030  
1031 61 for my $col ( split( ',', $table_element_def ) )
1032 {
1033 139 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($col =~ /^\s*(?:CONSTRAINT\s+(\S+)\s*)? # optional name of foreign key FOREIGN\s+KEY\s*\(\s* # start of list of; vi compatibile bracket -> ( (\s*[^)]+\s*) # field names in this table \s*\)\s* # end of field names in this table REFERENCES # key word \s*(\S+)\s* # table name being referenced in foreign key \(\s* # start of list of; vi compatible bracket -> ( (\s*[^)]+\s*) # field names in foreign table \s*\)\s* # end of field names in foreign table $/x) { } 3 136 139
elsif ($col =~ /^\s*(?:CONSTRAINT\s+(\S+)\s*)? # optional name of foreign key PRIMARY\s+KEY\s*\(\s* # start of list of; vi compatibile bracket -> ( (\s*[^)]+\s*) # field names in this table \s*\)\s* # end of field names in this table $/x) { } 3 133 136
1034 $col =~ m/^\s*(?:CONSTRAINT\s+(\S+)\s*)? # optional name of foreign key
1035 FOREIGN\s+KEY\s*\(\s* # start of list of; vi compatibile bracket -> (
1036 (\s*[^)]+\s*) # field names in this table
1037 \s*\)\s* # end of field names in this table
1038 REFERENCES # key word
1039 \s*(\S+)\s* # table name being referenced in foreign key
1040 \(\s* # start of list of; vi compatible bracket -> (
1041 (\s*[^)]+\s*) # field names in foreign table
1042 \s*\)\s* # end of field names in foreign table
1043 $/x
1044 )
1045 {
1046 3 my ( $name, $local_cols, $referenced_table, $referenced_cols ) = ( $1, $2, $3, $4 );
1047 3 my @local_cols = $self->replace_quoted($local_cols);
1048 3 $referenced_table = $self->replace_quoted_ids($referenced_table);
1049 3 my @referenced_cols = $self->replace_quoted($referenced_cols);
1050  
1051 3 ▶ if ( defined $name )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 2 1 3
1052 {
1053 2 $name = $self->replace_quoted_ids($name);
1054 }
1055 else
1056 {
1057 1 $name = $self->replace_quoted_ids($table_name);
1058 1 my ($quote_char) = '';
1059 1 ▶ if ( $name =~ s/(\W)$// )
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/(\W)$//) 0 1 1
1060 {
1061 0 $quote_char = ($1);
1062 }
1063 1 foreach my $local_col (@local_cols)
1064 {
1065 2 my $col_name = $local_col;
1066 2 $col_name =~ s/^\W//;
1067 2 $col_name =~ s/\W$//;
1068 2 $name .= '_' . $col_name;
1069 }
1070 1 $name .= '_fkey' . $quote_char;
1071 }
1072  
1073 3 $self->{struct}->{table_defs}->{$name}->{type} = 'FOREIGN';
1074 3 $self->{struct}->{table_defs}->{$name}->{local_cols} = \@local_cols;
1075 3 $self->{struct}->{table_defs}->{$name}->{referenced_table} = $referenced_table;
1076 3 $self->{struct}->{table_defs}->{$name}->{referenced_cols} = \@referenced_cols;
1077 3 next;
1078 }
1079 elsif (
1080 $col =~ m/^\s*(?:CONSTRAINT\s+(\S+)\s*)? # optional name of foreign key
1081 PRIMARY\s+KEY\s*\(\s* # start of list of; vi compatibile bracket -> (
1082 (\s*[^)]+\s*) # field names in this table
1083 \s*\)\s* # end of field names in this table
1084 $/x
1085 )
1086 {
1087 3 my ( $name, $local_cols ) = ( $1, $2 );
1088 3 my @local_cols = $self->replace_quoted($local_cols);
1089 3 ▶ if ( defined $name )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 2 1 3
1090 {
1091 2 $name = $self->replace_quoted_ids($name);
1092 }
1093 else
1094 {
1095 1 $name = $table_name;
1096 1 ▶ if ( $name =~ s/(\W)$// )
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/(\W)$//) { } 0 1 1
1097 {
1098 0 $name .= '_pkey' . $1;
1099 }
1100 else
1101 {
1102 1 $name .= '_pkey';
1103 }
1104 }
1105 3 $self->{struct}->{table_defs}->{$name}->{type} = 'PRIMARY';
1106 3 $self->{struct}->{table_defs}->{$name}->{local_cols} = \@local_cols;
1107 3 next;
1108 }
1109  
1110 # it seems, perl 5.6 isn't greedy enough .. let's help a bit
1111 133 my ($data_types_regex) = join( '|', sort { length($b) <=> length($a) } keys %{ $self->{opts}->{valid_data_types} } );
1112 133 $data_types_regex =~ s/ /\\ /g; # backslash spaces to allow the /x modifier below
1113 133 my ( $name, $type, $suffix ) = (
1114 $col =~ m/\s*(\S+)\s+ # capture the column name
1115 ((?:$data_types_regex|\S+) # check for all allowed data types OR anything that looks like a bad data type to give a good error
1116 (?:\s*\(\d+(?:\?COMMA\?\d+)?\))?) # allow the data type to have a precision specifier such as NUMERIC(4,6) on it
1117 \s*(\W.*|$) # capture the suffix of the column definition, e.g. constraints
1118 /ix
1119 );
1120 133 ▶ return $self->do_err("Column definition is missing a data type!") unless ($type);
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 133 133
1121 133 ▶ return undef unless ( $self->IDENTIFIER($name) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->IDENTIFIER($name) 0 133 133
1122  
1123 133 $name = $self->replace_quoted_ids($name);
1124  
1125 133 my @possible_constraints = ('PRIMARY KEY', 'NOT NULL', 'UNIQUE');
1126  
1127 133 for my $constraint (@possible_constraints)
1128 {
1129 399 my $count = $suffix =~ s/$constraint//gi;
1130 399 ▶ next if $count == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count == 0 389 10 399
1131  
1132 10 ▶ return $self->do_err(qq~Duplicate column constraint: '$constraint'!~)
Branch: 1 branch
BranchTrueFalseTotal
if $count > 1 0 10 10
1133 if $count > 1;
1134  
1135 10 ▶ return $self->do_err(qq{Can't have two PRIMARY KEYs in a table!})
Branch: 1 branch
BranchTrueFalseTotal
if $constraint eq "PRIMARY KEY" and $primary_defined++ 0 10 10
Condition66%2/3
$constraint eq "PRIMARY KEY" and $primary_defined++
!ll&&!rl&&r
820
MC/DC0%0/2
$constraint eq "PRIMARY KEY" and $primary_defined++
$constraint eq "PRIMARY KEY" $primary_defined++
Truth table66%2/3
A and B
A= $constraint eq "PRIMARY KEY"B= $primary_defined++
ABresult
0X0
100
111
1136 if $constraint eq 'PRIMARY KEY' and $primary_defined++;
1137  
1138 10 push @{ $self->{struct}->{table_defs}->{columns}->{$name}->{constraints} }, $constraint;
1139 }
1140  
1141 133 $suffix =~ s/^\s+//;
1142 133 $suffix =~ s/\s+$//;
1143  
1144 133 ▶ return $self->do_err("Unknown column constraint: '$suffix'!") unless ($suffix eq '');
Branch: 1 branch
BranchTrueFalseTotal
unless $suffix eq "" 0 133 133
1145  
1146 133 $type = uc $type;
1147 133 my $length;
1148 133 ▶ if ( $type =~ m/(.+)\((.+)\)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /(.+)\((.+)\)/) 20 113 133
1149 {
1150 20 $type = $1;
1151 20 $length = $2;
1152 }
1153 133 ▶ if ( !$self->{opts}->{valid_data_types}->{$type} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"opts"}{"valid_data_types"}{$type}) 2 131 133
1154 {
1155 2 return $self->do_err("'$type' is not a recognized data type!");
1156 }
1157 131 $self->{struct}->{table_defs}->{columns}->{$name}->{data_type} = $type;
1158 131 $self->{struct}->{table_defs}->{columns}->{$name}->{data_length} = $length;
1159 push(
1160 131 @{ $self->{struct}->{column_defs} },
1161 {
1162 type => 'column',
1163 value => $name,
1164 fullorg => $name,
1165 }
1166 );
1167  
1168 131 my $tmpname = $name;
1169 131 ▶ $tmpname = lc $tmpname unless ( $tmpname =~ m/^(?:\p{Word}+\.)?"/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpname =~ /^(?:\p{Word}+\.)?"/ 125 6 131
1170 131 ▶ return $self->do_err("Duplicate column names!") if $is_col_name{$tmpname}++;
Branch: 1 branch
BranchTrueFalseTotal
if $is_col_name{$tmpname}++ 0 131 131
1171  
1172 }
1173 59 $self->{struct}->{table_names} = [$table_name];
1174 59 return 1;
1175 }
1176  
1177 ###############
1178 # SQL SUBRULES
1179 ###############
1180  
1181 sub SET_CLAUSE_LIST
1182 {
1183 10 ▶ my ( $self, $set_string ) = @_;
Subroutine SET_CLAUSE_LIST: called CC=6 SCAR=18.1
Pod undocumented
1184 10 my @sets = split( /,/, $set_string );
1185 10 my ( @cols, @vals );
1186 10 for my $set (@sets)
1187 {
1188 16 my ( $col, $val ) = split( m/ = /, $set );
1189 16 ▶ return $self->do_err('Incomplete SET clause!') unless ( defined($col) && defined($val) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col and defined $val 1 15 16
Condition66%2/3
defined $col and defined $val
!ll&&!rl&&r
0115
MC/DC50%1/2
defined $col and defined $val
defined $col defined $val
Truth table66%2/3
A and B
A= defined $colB= defined $val
ABresult
0X0
100
111
1190 15 push( @cols, $col );
1191 15 push( @vals, $val );
1192 }
1193 return undef
1194 9 ▶ unless ( $self->{struct}->{column_defs} = $self->ROW_VALUE_LIST( join ',', @cols ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"struct"}{"column_defs"} = $self->ROW_VALUE_LIST(join(",", @cols)) 0 9 9
1195 9 ▶ return undef unless ( $self->LITERAL_LIST( join ',', @vals ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->LITERAL_LIST(join(",", @vals)) 0 9 9
1196 9 return 1;
1197 }
1198  
1199 sub SET_QUANTIFIER
1200 {
1201 0 ▶ my ( $self, $str ) = @_;
Subroutine SET_QUANTIFIER: not called CC=2 SCAR=17.9
Pod undocumented
1202 0 ▶ if ( $str =~ /^(DISTINCT|ALL)\s+(.*)$/si )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^(DISTINCT|ALL)\s+(.*)$/is) 0 0 0
1203 {
1204 0 $self->{struct}->{set_quantifier} = uc $1;
1205 0 $str = $2;
1206 }
1207 0 return $str;
1208 }
1209  
1210 #
1211 # DAA v1.11
1212 # modify to transform || strings into
1213 # CONCAT(<expr>); note that we
1214 # only xform the topmost expressions;
1215 # if a concat is contained within a subfunction,
1216 # it should get handled by ROW_VALUE()
1217 #
1218 sub transform_concat
1219 {
1220 1 ▶ my ( $obj, $colstr ) = @_;
Subroutine transform_concat: called CC=8 SCAR=23.2
Pod documented
1221  
1222 1 pos($colstr) = 0;
1223 1 my $parens = 0;
1224 1 my $spos = 0;
1225 1 my @concats = ();
1226 1 ▶ my $alias = ( $colstr =~ s/^(.+)(\s+AS\s+\S+)$/$1/ ) ? $2 : '';
Branch: 1 branch
BranchTrueFalseTotal
$colstr =~ s/^(.+)(\s+AS\s+\S+)$/$1/ ? : 0 1 1
1227  
1228 1 ▶ while ( $colstr =~ /\G.*?([\(\)\|])/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($colstr =~ /\G.*?([\(\)\|])/cgs) 10 1 11
1229 {
1230 10 ▶ if ( $1 eq '(' )
Branch: 3 branches
BranchTrueFalseTotal
if ($1 eq '(') { } 3 7 10
elsif ($1 eq ')') { } 3 4 7
elsif (not $parens and substr($colstr, $-[1] + 1, 1) eq '|') { } 0 8 8
1231 {
1232 3 $parens++;
1233 }
1234 elsif ( $1 eq ')' )
1235 {
1236 3 $parens--;
1237 }
1238 ▶ elsif (( !$parens )
Condition33%1/3
not $parens and substr($colstr, $-[1] + 1, 1) eq "|"
!ll&&!rl&&r
400
MC/DC0%0/2
not $parens and substr($colstr, $-[1] + 1, 1) eq "|"
not $parens substr($colstr, $-[1] + 1, 1) eq "|"
Truth table33%1/3
not(A) and B
A= not $parensB= substr($colstr, $-[1] + 1, 1) eq "|"
ABresult
0X0
100
111
1239 && ( substr( $colstr, $-[1] + 1, 1 ) eq '|' ) )
1240 {
1241  
1242 #
1243 # its a concat outside of parens, push prior string on stack
1244 #
1245 0 push @concats, substr( $colstr, $spos, $-[1] - $spos );
1246 0 $spos = $+[1] + 1;
1247 0 pos($colstr) = $spos;
1248 }
1249 }
1250  
1251 #
1252 # no concats, return original
1253 #
1254 1 ▶ return $colstr unless scalar @concats;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @concats 1 0 1
1255  
1256 #
1257 # don't forget the last one!
1258 #
1259 0 push @concats, substr( $colstr, $spos );
1260 0 return 'CONCAT(' . join( ', ', @concats ) . ")$alias";
1261 }
1262  
1263 #
1264 # DAA v1.10
1265 # improved column list extraction
1266 # original doesn't seem to handle
1267 # commas within function argument lists
1268 #
1269 # DAA v1.11
1270 # modify to transform || strings into
1271 # CONCAT(<expr-list>)
1272 #
1273 sub extract_column_list
1274 {
1275 315 ▶ my ( $self, $colstr ) = @_;
Subroutine extract_column_list: called CC=10 SCAR=23.0
Pod documented
1276  
1277 315 my @collist = ();
1278 315 pos($colstr) = 0;
1279 315 my $parens = 0;
1280 315 my $spos = 0;
1281 315 ▶ while ( $colstr =~ m/\G.*?([\(\),])/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($colstr =~ /\G.*?([\(\),])/cgs) 711 315 1026
1282 {
1283 711 ▶ if ( $1 eq '(' )
Branch: 3 branches
BranchTrueFalseTotal
if ($1 eq '(') { } 242 469 711
elsif ($1 eq ')') { } 239 230 469
elsif (not $parens) { } 137 93 230
1284 {
1285 242 $parens++;
1286 }
1287 elsif ( $1 eq ')' )
1288 {
1289 239 $parens--;
1290 }
1291 elsif ( !$parens )
1292 { # its a comma outside of parens
1293 137 push( @collist, substr( $colstr, $spos, $-[1] - $spos ) );
1294 137 $collist[-1] =~ s/^\s+//;
1295 137 $collist[-1] =~ s/\s+$//;
1296 137 ▶ return $self->do_err('Bad column list!') if ( $collist[-1] eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if $collist[-1] eq "" 0 137 137
1297 137 $spos = $+[1];
1298 }
1299 }
1300 315 ▶ return $self->do_err('Unbalanced parentheses!') if ($parens);
Branch: 1 branch
BranchTrueFalseTotal
if $parens 3 312 315
1301  
1302 # don't forget the last one!
1303 312 push( @collist, substr( $colstr, $spos ) );
1304 312 $collist[-1] =~ s/^\s+//;
1305 312 $collist[-1] =~ s/\s+$//;
1306 312 ▶ return $self->do_err('Bad column list!') if ( $collist[-1] eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if $collist[-1] eq "" 0 312 312
1307  
1308 # scan for and convert string concats to CONCAT()
1309 312 foreach ( 0 .. $#collist )
1310 {
1311 449 ▶ $collist[$_] = $self->transform_concat( $collist[$_] ) if ( $collist[$_] =~ m/\|\|/ );
Branch: 1 branch
BranchTrueFalseTotal
if $collist[$_] =~ /\|\|/ 1 448 449
1312 }
1313  
1314 312 return @collist;
1315 }
1316  
1317 sub SELECT_LIST
1318 {
1319 547 ▶ my ( $self, $col_str ) = @_;
Subroutine SELECT_LIST: called CC=18 SCAR=29.1
Pod undocumented
1320 547 ▶ if ( $col_str =~ m/^\s*\*\s*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($col_str =~ /^\s*\*\s*$/) 232 315 547
1321 {
1322 $self->{struct}->{column_defs} = [
1323 {
1324 232 type => 'column',
1325 value => '*'
1326 }
1327 ];
1328 232 $self->{struct}->{column_aliases} = {};
1329  
1330 232 return 1;
1331 }
1332 315 my @col_list = $self->extract_column_list($col_str);
1333 315 ▶ return undef unless ( scalar(@col_list) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @col_list 3 312 315
1334  
1335 312 my ( @newcols, %aliases );
1336 312 for my $col (@col_list)
1337 {
1338 # DAA:
1339 # need better alias test here, since AS is a common
1340 # keyword that might be used in a function
1341 445 ▶ my ( $fld, $alias ) =
Branch: 1 branch
BranchTrueFalseTotal
$col =~ /^(.+?)\s+(?:AS\s+)?([A-Z]\p{Word}*|\?QI\d+\?)$/i ? : 16 429 445
1342 ( $col =~ m/^(.+?)\s+(?:AS\s+)?([A-Z]\p{Word}*|\?QI\d+\?)$/i )
1343 ? ( $1, $2 )
1344 : ( $col, undef );
1345 445 $col = $fld;
1346 445 ▶ if ( $col =~ m/^(\S+)\.\*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($col =~ /^(\S+)\.\*$/) { } 2 443 445
1347 {
1348 2 my $table = $1;
1349 2 ▶ if ( defined($alias) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alias) 0 2 2
1350 {
1351 0 return $self->do_err("'$table.*' cannot be aliased");
1352 }
1353 $table = $self->{tmp}->{is_table_alias}->{$table}
1354 2 ▶ if ( $self->{tmp}->{is_table_alias}->{$table} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tmp"}{"is_table_alias"}{$table} 0 2 2
1355 $table = $self->{tmp}->{is_table_alias}->{"\L$table"}
1356 2 ▶ if ( $self->{tmp}->{is_table_alias}->{"\L$table"} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tmp"}{"is_table_alias"}{lc $table} 0 2 2
1357 2 ▶ return undef unless ( $self->TABLE_NAME($table) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table) 0 2 2
1358 2 $table = $self->replace_quoted_ids($table);
1359 2 push(
1360 @newcols,
1361 {
1362 type => 'column',
1363 value => "$table.*",
1364 }
1365 );
1366 }
1367 else
1368 {
1369 443 my $newcol;
1370 443 $newcol = $self->SET_FUNCTION_SPEC($col);
1371 443 ▶ return if ( $self->{struct}->{errstr} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"struct"}{"errstr"} 3 440 443
1372 440 ▶ $newcol ||= $self->ROW_VALUE($col);
Condition66%2/3
$newcol ||= $self->ROW_VALUE($col)
l!l&&r!l&&!r
334070
MC/DC0%0/2
$newcol ||= $self->ROW_VALUE($col)
$newcol $self->ROW_VALUE($col)
Truth table66%2/3
A ||= B
A= $newcolB= $self->ROW_VALUE($col)
ABresult
1X1
011
000
1373 440 ▶ return if ( $self->{struct}->{errstr} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"struct"}{"errstr"} 1 439 440
1374 439 ▶ return $self->do_err("Invalid SELECT entry '$col'")
Branch: 1 branch
BranchTrueFalseTotal
unless defined &_HASH($newcol) 0 439 439
1375 unless ( defined( _HASH($newcol) ) );
1376  
1377 # FIXME this might be better done later and only if not 2 functions with the same name are selected
1378 439 ▶ if ( !defined($alias)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $alias and "function" eq $newcol->{"type"} || "setfunc" eq $newcol->{"type"}) 220 219 439
Condition100%6/6
not defined $alias and "function" eq $newcol->{"type"} || "setfunc" eq $newcol->{"type"}
!ll&&!rl&&r
1639231
"function" eq $newcol->{"type"} or "setfunc" eq $newcol->{"type"}
l!l&&r!l&&!r
18931203
MC/DC66%2/3
not defined $alias and "function" eq $newcol->{"type"} || "setfunc" eq $newcol->{"type"}
not defined $alias "function" eq $newcol->{"type"} "setfunc" eq $newcol->{"type"}
Truth table75%3/4
not(A) and B or C
A= not defined $aliasB= "function" eq $newcol->{"type"}C= "setfunc" eq $newcol->{"type"}
ABCresult
0XX0
1000
11X1
1011
1379 && ( ( 'function' eq $newcol->{type} ) || ( 'setfunc' eq $newcol->{type} ) ) )
1380 {
1381 220 $alias = $newcol->{name};
1382 }
1383  
1384 439 ▶ if ( defined($alias) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alias) 236 203 439
1385 {
1386 236 $alias = $self->replace_quoted_ids($alias);
1387 236 $newcol->{alias} = $alias;
1388 236 $aliases{ $newcol->{fullorg} } = $alias;
1389 236 $self->{struct}->{ORG_NAME}->{ $newcol->{fullorg} } = $alias;
1390 236 $self->{struct}->{ALIASES}->{$alias} = $newcol->{fullorg};
1391 }
1392 439 push( @newcols, $newcol );
1393 }
1394 }
1395 308 $self->{struct}->{column_aliases} = \%aliases;
1396 308 $self->{struct}->{column_defs} = \@newcols;
1397 308 return 1;
1398 }
1399  
1400 sub SET_FUNCTION_SPEC
1401 {
1402 443 ▶ my ( $self, $col_str ) = @_;
Subroutine SET_FUNCTION_SPEC: called CC=8 SCAR=20.8
Pod undocumented
1403  
1404 443 ▶ if ( $col_str =~ m/^(COUNT|AVG|SUM|MAX|MIN) \((.*)\)\s*$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($col_str =~ /^(COUNT|AVG|SUM|MAX|MIN) \((.*)\)\s*$/i) { } 34 409 443
1405 {
1406 34 my $set_function_name = uc $1;
1407 34 my $set_function_arg_str = $2;
1408 34 my $distinct = 'ALL';
1409 34 ▶ if ( $set_function_arg_str =~ s/(DISTINCT|ALL) (.+)$/$2/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($set_function_arg_str =~ s/(DISTINCT|ALL) (.+)$/$2/i) 5 29 34
1410 {
1411 5 $distinct = uc $1;
1412 }
1413 34 ▶ my $count_star = ( $set_function_name eq 'COUNT' ) && ( $set_function_arg_str eq '*' );
Condition100%3/3
$set_function_name eq 'COUNT' && $set_function_arg_str eq '*'
!ll&&!rl&&r
2068
MC/DC100%2/2
$set_function_name eq 'COUNT' && $set_function_arg_str eq '*'
$set_function_name eq 'COUNT' $set_function_arg_str eq '*'
Truth table100%3/3
A && B
A= $set_function_name eq 'COUNT'B= $set_function_arg_str eq '*'
ABresult
0X0
100
111
1414  
1415 34 my $set_function_arg;
1416 34 ▶ if ($count_star)
Branch: 1 branch
BranchTrueFalseTotal
if ($count_star) { } 8 26 34
1417 {
1418 8 ▶ return $self->do_err("Keyword DISTINCT is not allowed for COUNT(*)")
Branch: 1 branch
BranchTrueFalseTotal
if "DISTINCT" eq $distinct 1 7 8
1419 if ( 'DISTINCT' eq $distinct );
1420 7 $set_function_arg = {
1421 type => 'column',
1422 value => '*'
1423 };
1424 }
1425 else
1426 {
1427 26 $set_function_arg = $self->ROW_VALUE($set_function_arg_str);
1428 26 ▶ return if ( $self->{struct}->{errstr} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"struct"}{"errstr"} 0 26 26
1429 26 ▶ return unless ( defined( _HASH($set_function_arg) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined &_HASH($set_function_arg) 0 26 26
1430 }
1431  
1432 33 $self->{struct}->{has_set_functions} = 1;
1433  
1434 33 my $value = {
1435 name => $set_function_name,
1436 arg => $set_function_arg,
1437 argstr => lc($set_function_arg_str),
1438 distinct => $distinct,
1439 type => 'setfunc',
1440 fullorg => $col_str,
1441 };
1442 33 return $value;
1443 }
1444 else
1445 {
1446 409 return undef;
1447 }
1448 }
1449  
1450 sub LIMIT_CLAUSE
1451 {
1452 9 ▶ my ( $self, $limit_clause ) = @_;
Subroutine LIMIT_CLAUSE: called CC=10 SCAR=24.5
Pod undocumented
1453  
1454 # $limit_clause = trim($limit_clause);
1455 9 $limit_clause =~ s/^\s+//;
1456 9 $limit_clause =~ s/\s+$//;
1457  
1458 9 ▶ return 1 if !$limit_clause;
Branch: 1 branch
BranchTrueFalseTotal
unless $limit_clause 0 9 9
1459 9 my $offset;
1460 my $limit;
1461 9 my $junk;
1462 9 ($offset, $limit, $junk ) = split /,|OFFSET/i, $limit_clause;
1463 9 ▶ if ($limit_clause =~ m/(\d+)\s+OFFSET\s+(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit_clause =~ /(\d+)\s+OFFSET\s+(\d+)/) { } 1 8 9
1464 1 $limit = $1;
1465 1 $offset = $2;
1466 } else {
1467 8 ( $offset, $limit, $junk ) = split /,/i, $limit_clause;
1468 }
1469 9 ▶ return $self->do_err('Bad limit clause!:'.$limit_clause)
Branch: 1 branch
BranchTrueFalseTotal
if defined $limit and $limit =~ /[^\d]/ or defined $offset and $offset =~ /[^\d]/ or defined $junk 0 9 9
Condition41%5/12
defined $limit and $limit =~ /[^\d]/ or defined $offset and $offset =~ /[^\d]/ or defined $junk
l!l&&r!l&&!r
009
defined $limit and $limit =~ /[^\d]/ or defined $offset and $offset =~ /[^\d]/
l!l&&r!l&&!r
009
defined $limit and $limit =~ /[^\d]/
!ll&&!rl&&r
270
defined $offset and $offset =~ /[^\d]/
!ll&&!rl&&r
090
MC/DC0%0/5
defined $limit and $limit =~ /[^\d]/ or defined $offset and $offset =~ /[^\d]/ or defined $junk
defined $limit $limit =~ /[^\d]/ defined $offset $offset =~ /[^\d]/ defined $junk
Truth table18%2/11
A and B or C and D or E
A= defined $limitB= $limit =~ /[^\d]/C= defined $offsetD= $offset =~ /[^\d]/E= defined $junk
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
1470 if ( defined $limit and $limit =~ /[^\d]/ )
1471 or ( defined $offset and $offset =~ /[^\d]/ )
1472 or defined $junk;
1473 9 ▶ if ( defined $offset and !defined $limit )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset and not defined $limit) 2 7 9
Condition66%2/3
defined $offset and not defined $limit
!ll&&!rl&&r
072
MC/DC50%1/2
defined $offset and not defined $limit
defined $offset not defined $limit
Truth table66%2/3
A and not(B)
A= defined $offsetB= not defined $limit
ABresult
0X0
100
111
1474 {
1475 2 $limit = $offset;
1476 2 undef $offset;
1477 }
1478 $self->{struct}->{limit_clause} = {
1479 9 limit => $limit,
1480 offset => $offset,
1481 };
1482 9 return 1;
1483 }
1484  
1485 sub SORT_SPEC_LIST
1486 {
1487 20 ▶ my ( $self, $order_clause ) = @_;
Subroutine SORT_SPEC_LIST: called CC=7 SCAR=19.6
Pod undocumented
1488 20 ▶ return 1 if !$order_clause;
Branch: 1 branch
BranchTrueFalseTotal
unless $order_clause 0 20 20
1489 20 my @ocols;
1490 20 my @order_columns = split ',', $order_clause;
1491 20 for my $col (@order_columns)
1492 {
1493 26 my $newcol;
1494 my $newarg;
1495 26 ▶ if ( $col =~ /\s*(\S+)\s+(ASC|DESC)/si )
Branch: 2 branches
BranchTrueFalseTotal
if ($col =~ /\s*(\S+)\s+(ASC|DESC)/is) { } 9 17 26
elsif ($col =~ /^\s*(\S+)\s*$/is) { } 17 0 17
1496 {
1497 9 $newcol = $1;
1498 9 $newarg = uc $2;
1499 }
1500 elsif ( $col =~ /^\s*(\S+)\s*$/si )
1501 {
1502 17 $newcol = $1;
1503 17 $newarg = 'ASC';
1504 }
1505 else
1506 {
1507 0 return $self->do_err('Junk after column name in ORDER BY clause!');
1508 }
1509 26 ▶ $newcol = $self->COLUMN_NAME($newcol) or return;
Branch: 1 branch
BranchTrueFalseTotal
$newcol = $self->COLUMN_NAME($newcol) or return 0 26 26
1510 26 ▶ if ( $newcol =~ /^(.+)\..+$/s )
Branch: 1 branch
BranchTrueFalseTotal
if ($newcol =~ /^(.+)\..+$/s) 3 23 26
1511 {
1512 3 my $table = $1;
1513 3 $self->_verify_tablename( $table, "ORDER BY" );
1514 }
1515 26 push( @ocols, { $newcol => $newarg } );
1516 }
1517 20 $self->{struct}->{sort_spec_list} = \@ocols;
1518 20 return 1;
1519 }
1520  
1521 sub SEARCH_CONDITION
1522 {
1523 231 ▶ my ( $self, $str ) = @_;
Subroutine SEARCH_CONDITION: called CC=5 SCAR=16.3
Pod undocumented
1524 231 $str =~ s/^\s*WHERE (.+)/$1/;
1525 231 $str =~ s/^\s+//;
1526 231 $str =~ s/\s+$//;
1527 231 ▶ return $self->do_err("Couldn't find WHERE clause!") unless $str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 231 231
1528  
1529 #
1530 # DAA
1531 # make these OO so subclasses can override them
1532 #
1533 231 $str = $self->repl_btwin($str);
1534  
1535 #
1536 # DAA
1537 # add another abstract method so subclasses
1538 # can inject their own syntax transforms
1539 #
1540 231 $str = $self->transform_syntax($str);
1541  
1542 231 my $open_parens = $str =~ tr/\(//;
1543 231 my $close_parens = $str =~ tr/\)//;
1544 231 ▶ if ( $open_parens != $close_parens )
Branch: 1 branch
BranchTrueFalseTotal
if ($open_parens != $close_parens) 0 231 231
1545 {
1546 0 return $self->do_err("Mismatched parentheses in WHERE clause!");
1547 }
1548 231 $str = nongroup_numeric( $self->nongroup_string($str) );
1549 231 ▶ my $pred =
Branch: 1 branch
BranchTrueFalseTotal
$open_parens ? : 135 96 231
1550 $open_parens
1551 ? $self->parens_search( $str, [] )
1552 : $self->non_parens_search( $str, [] );
1553 229 ▶ return $self->do_err("Couldn't find predicate!") unless $pred;
Branch: 1 branch
BranchTrueFalseTotal
unless $pred 0 229 229
1554 229 $self->{struct}->{where_clause} = $pred;
1555 229 return 1;
1556 }
1557  
1558 ############################################################
1559 # UTILITY FUNCTIONS CALLED TO PARSE PARENS IN WHERE CLAUSE
1560 ############################################################
1561  
1562 sub repl_btwin
1563 {
1564 231 ▶ my ( $self, $str ) = @_; # DAA make OO for subclassing
Subroutine repl_btwin: called CC=6 SCAR=17.9
Pod documented
1565 231 my @lids;
1566  
1567 231 my $i = -1;
1568 231 ▶ while ( $str =~ m/\G.*(?:IN|BETWEEN)\s+\(/g )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G.*(?:IN|BETWEEN)\s+\(/g) 32 231 263
1569 {
1570 32 my $start = pos($str) - 1;
1571 32 my $lparens = 1;
1572 32 my $rparens = 0;
1573 32 ▶ while ( $str =~ m/\G.*?([\(\)])/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G.*?([\(\)])/cgs) 36 0 36
1574 {
1575 36 ▶ ++$lparens if ( '(' eq $1 );
Branch: 1 branch
BranchTrueFalseTotal
if "(" eq $1 2 34 36
1576 36 ▶ ++$rparens if ( ')' eq $1 );
Branch: 1 branch
BranchTrueFalseTotal
if ")" eq $1 34 2 36
1577 36 ▶ last if ( $lparens == $rparens );
Branch: 1 branch
BranchTrueFalseTotal
if $lparens == $rparens 32 4 36
1578 }
1579 32 my $now = pos($str);
1580 32 ++$i;
1581 32 my $subst = "?LI$i?";
1582 32 my $term = substr( $str, $start, $now - $start, $subst );
1583 32 $term = substr( $term, 1, length($term) - 2 );
1584 32 push( @lids, $term );
1585 32 pos($str) = $start + length($subst);
1586 }
1587  
1588 231 $self->{struct}->{list_ids} = \@lids;
1589 231 return $str;
1590 }
1591  
1592 # groups clauses by nested parens
1593 #
1594 # DAA
1595 # rewrite to correct paren scan
1596 # and optimize code, and remove
1597 # recursion
1598 #
1599 sub parens_search
1600 {
1601 135 ▶ my ( $self, $str, $predicates ) = @_;
Subroutine parens_search: called CC=7 SCAR=19.5
Pod documented
1602 135 my $index = scalar( @{$predicates} );
1603  
1604 # to handle WHERE (a=b) AND (c=d)
1605 # but needs escape space to not foul up AND/OR
1606  
1607 # locate all open parens
1608 # locate all close parens
1609 # apply non_paren_search to contents of
1610 # inner parens
1611  
1612 135 my $lparens = ( $str =~ tr/\(// );
1613 135 my $rparens = ( $str =~ tr/\)// );
1614 135 ▶ return $self->do_err( 'Unmatched ' . ( ( $lparens > $rparens ) ? 'left' : 'right' ) . " parentheses in '$str'!" )
Branch: 2 branches
BranchTrueFalseTotal
unless $lparens == $rparens 0 135 135
$lparens > $rparens ? : 0 0 0
1615 unless ( $lparens == $rparens );
1616  
1617 135 ▶ return $self->non_parens_search( $str, $predicates )
Branch: 1 branch
BranchTrueFalseTotal
unless $lparens 127 8 135
1618 unless $lparens;
1619  
1620 8 my @lparens = ();
1621 8 ▶ while ( $str =~ m/\G.*?([\(\)])/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G.*?([\(\)])/cgs) 20 8 28
1622 {
1623 20 ▶ push( @lparens, $-[1] ), next
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "(" 10 10 20
1624 if ( $1 eq '(' );
1625  
1626 #
1627 # got a close paren, so pop the position of matching
1628 # left paren and extract the expression, removing the
1629 # parens
1630 #
1631 10 my $pos = pop @lparens;
1632 10 my $predlen = $+[1] - $pos;
1633 10 my $pred = substr( $str, $pos + 1, $predlen - 2 );
1634  
1635 #
1636 # note that this will pass thru any prior ^$index^ xlation,
1637 # so we don't need to recurse to recover the predicate
1638 #
1639 10 ▶ substr( $str, $pos, $predlen ) = $pred, pos($str) = $pos + length($pred), next
Branch: 1 branch
BranchTrueFalseTotal
unless $pred =~ / (AND|OR) /i 7 3 10
1640 unless ( $pred =~ / (AND|OR) /i );
1641  
1642 #
1643 # handle AND/OR
1644 #
1645 3 push( @$predicates, substr( $str, $pos + 1, $predlen - 2 ) );
1646 3 my $replacement = "^$#$predicates^";
1647 3 substr( $str, $pos, $predlen ) = $replacement;
1648 3 pos($str) = $pos + length($replacement);
1649 }
1650  
1651 8 return $self->non_parens_search( $str, $predicates );
1652 }
1653  
1654 # creates predicates from clauses that either have no parens
1655 # or ANDs or have been previously grouped by parens and ANDs
1656 #
1657 # DAA
1658 # rewrite to fix paren scanning
1659 #
1660 sub non_parens_search
1661 {
1662 311 ▶ my ( $self, $str, $predicates ) = @_;
Subroutine non_parens_search: called CC=12 SCAR=24.9
Pod documented
1663 311 my $neg = 0;
1664 311 my $nots = {};
1665  
1666 311 ▶ $neg = 1, $nots = { pred => 1 }
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ s/^NOT (\^.+)$/$1/i 0 311 311
1667 if ( $str =~ s/^NOT (\^.+)$/$1/i );
1668  
1669 311 my ( $pred1, $pred2, $op );
1670 311 my $and_preds = [];
1671 311 ( $str, $and_preds ) = group_ands($str);
1672 311 ▶ $str = $and_preds->[$1]
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^\s*~(\d+)~\s*$/ 0 311 311
1673 if $str =~ /^\s*~(\d+)~\s*$/;
1674  
1675 311 ▶ return $self->non_parens_search( $$predicates[$1], $predicates )
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^\s*\^(\d+)\^\s*$/ 2 309 311
1676 if ( $str =~ /^\s*\^(\d+)\^\s*$/ );
1677  
1678 309 ▶ if ( $str =~ /\G(.*?)\s+(AND|OR)\s+(.*)$/igcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G(.*?)\s+(AND|OR)\s+(.*)$/cgis) 39 270 309
1679 {
1680 39 ( $pred1, $op, $pred2 ) = ( $1, $2, $3 );
1681  
1682 39 ▶ if ( $pred1 =~ /^\s*\^(\d+)\^\s*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($pred1 =~ /^\s*\^(\d+)\^\s*$/) { } 1 38 39
1683 {
1684 1 $pred1 = $self->non_parens_search( $$predicates[$1], $predicates );
1685 }
1686 else
1687 {
1688 38 $pred1 =~ s/\~(\d+)\~$/$and_preds->[$1]/g;
1689 38 $pred1 = $self->non_parens_search( $pred1, $predicates );
1690 }
1691  
1692 #
1693 # handle pred2 as a full predicate
1694 #
1695 39 $pred2 =~ s/\~(\d+)\~$/$and_preds->[$1]/g;
1696 39 $pred2 = $self->non_parens_search( $pred2, $predicates );
1697  
1698 return {
1699 39 neg => $neg,
1700 nots => $nots,
1701 arg1 => $pred1,
1702 op => uc $op,
1703 arg2 => $pred2,
1704 };
1705 }
1706  
1707 #
1708 # terminal predicate
1709 # need to check for singleton functions here
1710 #
1711 270 my $xstr = $str;
1712 270 my ( $k, $v );
1713 270 ▶ if ( $str =~ /^\s*([A-Z]\p{Word}*)\s*\[/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^\s*([A-Z]\p{Word}*)\s*\[/cgs) { } 120 150 270
1714 {
1715  
1716 #
1717 # we've got a function, check if its a singleton
1718 #
1719 120 my $parens = 1;
1720 120 my $spos = $-[1];
1721 120 my $epos = 0;
1722 120 ▶ $epos = $-[1], $parens += ( $1 eq '[' ) ? 1 : -1 while ( ( $parens > 0 ) && ( $str =~ /\G.*?([\[\]])/gcs ) );
Branch: 2 branches
BranchTrueFalseTotal
$parens > 0 and $str =~ /\G.*?([\[\]])/cgs and do { $epos = $-[1], $parens += $1 eq "[" ? 1 : -1 } 126 120 246
$1 eq '[' ? : 3 123 126
Condition66%2/3
$parens > 0 and $str =~ /\G.*?([\[\]])/cgs
!ll&&!rl&&r
1200126
MC/DC50%1/2
$parens > 0 and $str =~ /\G.*?([\[\]])/cgs
$parens > 0 $str =~ /\G.*?([\[\]])/cgs
Truth table66%2/3
A and B
A= $parens > 0B= $str =~ /\G.*?([\[\]])/cgs
ABresult
0X0
100
111
1723 120 $k = substr( $str, $spos, $epos - $spos + 1 );
1724 120 $k =~ s/\?(\d+)\?/$self->{struct}{literals}[$1]/g;
1725  
1726 #
1727 # for now we assume our parens are balanced
1728 # now look for a predicate operator and a right operand
1729 #
1730 120 ▶ $v = $1, $v =~ s/\?(\d+)\?/$self->{struct}{literals}[$1]/g
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /\G\s+\S+\s*(.+)\s*$/cgs 66 54 120
1731 if ( $str =~ /\G\s+\S+\s*(.+)\s*$/gcs );
1732 }
1733 else
1734 {
1735 150 $xstr =~ s/\?(\d+)\?/$self->{struct}{literals}[$1]/g;
1736 150 ( $k, $v ) = $xstr =~ /^(\S+?)\s+\S+\s*(.+)\s*$/;
1737 }
1738 270 ▶ push @{ $self->{struct}{where_cols}{$k} }, $v
Branch: 1 branch
BranchTrueFalseTotal
if defined $k 270 0 270
1739 if defined $k;
1740 270 return $self->PREDICATE($str);
1741 }
1742  
1743 # groups AND clauses that aren't already grouped by parens
1744 #
1745 sub group_ands
1746 {
1747 315 ▶ my $str = shift;
Subroutine group_ands: called CC=7 SCAR=19.6
Pod documented
1748 315 ▶ my $and_preds = shift || [];
Condition100%2/2
shift() || []
l!l
4311
MC/DC100%1/1
shift() || []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1749 315 ▶ return ( $str, $and_preds )
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ / AND / and $str =~ / OR / 311 4 315
Condition100%3/3
$str =~ / AND / and $str =~ / OR /
!ll&&!rl&&r
283284
MC/DC100%2/2
$str =~ / AND / and $str =~ / OR /
$str =~ / AND / $str =~ / OR /
Truth table100%3/3
A and B
A= $str =~ / AND /B= $str =~ / OR /
ABresult
0X0
100
111
1750 unless $str =~ / AND / and $str =~ / OR /;
1751  
1752 4 ▶ return $str, $and_preds
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /^(.*?) AND (.*)$/i 0 4 4
1753 unless ( $str =~ /^(.*?) AND (.*)$/i );
1754  
1755 4 my ( $front, $back ) = ( $1, $2 );
1756 4 my $index = scalar @$and_preds;
1757 4 ▶ $front = $1
Branch: 1 branch
BranchTrueFalseTotal
if $front =~ /^.* OR (.*)$/i 0 4 4
1758 if ( $front =~ /^.* OR (.*)$/i );
1759  
1760 4 ▶ $back = $1
Branch: 1 branch
BranchTrueFalseTotal
if $back =~ /^(.*?) (OR|AND) .*$/i 4 0 4
1761 if ( $back =~ /^(.*?) (OR|AND) .*$/i );
1762  
1763 4 my $newpred = "$front AND $back";
1764 4 push @$and_preds, $newpred;
1765 4 $str =~ s/\Q$newpred/~$index~/i;
1766 4 return group_ands( $str, $and_preds );
1767 }
1768  
1769 # replaces string function parens with square brackets
1770 # e.g TRIM (foo) -> TRIM[foo]
1771 #
1772 # DAA update to support UDFs
1773 # and remove recursion
1774 #
1775 sub nongroup_string
1776 {
1777 231 ▶ my ( $self, $str ) = @_;
Subroutine nongroup_string: called CC=6 SCAR=17.9
Pod documented
1778  
1779 #
1780 # add in any user defined functions
1781 #
1782 231 my $f = join( '|', FUNCTION_NAMES, $self->_udf_function_names );
1783  
1784 #
1785 # we need a scan here to permit arbitrarily nested paren
1786 # arguments to functions
1787 #
1788 231 my $parens = 0;
1789 231 my $pos;
1790 231 my @lparens = ();
1791 231 ▶ while ( $str =~ /\G.*?((\b($f)\s*\()|[\(\)])/igcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G.*?((\b($f)\s*\()|[\(\)])/cgis) 298 231 529
1792 {
1793 298 ▶ if ( $1 eq ')' )
Branch: 2 branches
BranchTrueFalseTotal
if ($1 eq ')') { } 149 149 298
elsif ($1 eq '(') { } 15 134 149
1794 {
1795 #
1796 # close paren, see if any pending function open
1797 # paren matches it
1798 #
1799 149 --$parens;
1800 149 ▶ $pos = $+[0], substr( $str, $+[0] - 1, 1 ) = ']', pos($str) = $pos, pop(@lparens)
Branch: 1 branch
BranchTrueFalseTotal
if @lparens and $lparens[-1] == $parens 134 15 149
Condition66%2/3
@lparens and $lparens[-1] == $parens
!ll&&!rl&&r
150134
MC/DC50%1/2
@lparens and $lparens[-1] == $parens
@lparens $lparens[-1] == $parens
Truth table66%2/3
A and B
A= @lparensB= $lparens[-1] == $parens
ABresult
0X0
100
111
1801 if ( @lparens && ( $lparens[-1] == $parens ) );
1802 }
1803 elsif ( $1 eq '(' )
1804 {
1805  
1806 #
1807 # just an open paren, count it and go on
1808 #
1809 15 ++$parens;
1810 }
1811 else
1812 {
1813  
1814 #
1815 # new function definition, capture its open paren
1816 # also uppercase the function name
1817 #
1818 134 $pos = $+[0];
1819 134 substr( $str, $-[3], length($3) ) = uc $3;
1820 134 substr( $str, $+[0] - 1, 1 ) = '[';
1821 134 pos($str) = $pos;
1822 134 push @lparens, $parens;
1823 134 ++$parens;
1824 }
1825 }
1826  
1827 # return $self->do_err('Unmatched ' .
1828 # (($parens > 0) ? 'left' : 'right') . ' parentheses!')
1829 # if $parens;
1830 #
1831 # DAA
1832 # remove scoped recursion
1833 #
1834 # return ( $str =~ /($f)\s*\(/i ) ?
1835 # nongroup_string($str) : $str;
1836 231 return $str;
1837 }
1838  
1839 # replaces math parens with square brackets
1840 # e.g (4-(6+7)*9) -> MATH[4-MATH[6+7]*9]
1841 #
1842 sub nongroup_numeric
1843 {
1844 233 ▶ my $str = $_[0];
Subroutine nongroup_numeric: called CC=5 SCAR=16.1
Pod documented
1845 233 my $has_op;
1846  
1847 #
1848 # DAA
1849 # optimize regex
1850 #
1851 233 ▶ if ( $str =~ m/\(([\p{Word} \*\/\+\-\[\]\?]+)\)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m<\(([\p{Word} \*/\+\-\[\]\?]+)\)>) 7 226 233
1852 {
1853 7 my $match = $1;
1854 7 ▶ if ( $match !~ m/(LIKE |IS|BETWEEN|IN)/i )
Branch: 1 branch
BranchTrueFalseTotal
if (not $match =~ /(LIKE |IS|BETWEEN|IN)/i) { } 5 2 7
1855 {
1856 5 my $re = quotemeta($match);
1857 5 $str =~ s/\($re\)/MATH\[$match\]/;
1858 }
1859 else
1860 {
1861 2 $has_op++;
1862 }
1863 }
1864  
1865 #
1866 # DAA
1867 # remove scoped recursion
1868 #
1869 233 ▶ return ( !$has_op and $str =~ /\(([\p{Word} \*\/\+\-\[\]\?]+)\)/ )
Branch: 1 branch
BranchTrueFalseTotal
!$has_op && $str =~ m<\(([\p{Word} \*/\+\-\[\]\?]+)\)> ? : 2 231 233
Condition100%3/3
not $has_op and $str =~ m<\(([\p{Word} \*/\+\-\[\]\?]+)\)>
!ll&&!rl&&r
22292
MC/DC100%2/2
not $has_op and $str =~ m<\(([\p{Word} \*/\+\-\[\]\?]+)\)>
not $has_op $str =~ m<\(([\p{Word} \*/\+\-\[\]\?]+)\)>
Truth table100%3/3
not(A) and B
A= not $has_opB= $str =~ m<\(([\p{Word} \*/\+\-\[\]\?]+)\)>
ABresult
0X0
100
111
1870 ? nongroup_numeric($str)
1871 : $str;
1872 }
1873 ############################################################
1874  
1875 #########################################################
1876 # LITERAL_LIST ::= <literal> [,<literal>]
1877 #########################################################
1878 sub LITERAL_LIST
1879 {
1880 187 ▶ my ( $self, $str ) = @_;
Subroutine LITERAL_LIST: called CC=3 SCAR=11.0
Pod undocumented
1881 187 my @tokens = split /,/, $str;
1882 187 my @values;
1883 187 for my $tok (@tokens)
1884 {
1885 602 my $val = $self->ROW_VALUE($tok);
1886 602 ▶ return $self->do_err(qq('$tok' is not a valid value or is not quoted!))
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 602 602
1887 unless $val;
1888 602 push @values, $val;
1889 }
1890 187 push( @{ $self->{struct}->{values} }, \@values );
1891 187 return 1;
1892 }
1893  
1894 #############################################################################
1895 # LITERAL ::= <quoted_string> | <question mark> | <number> | NULL/TRUE/FALSE
1896 #############################################################################
1897 sub LITERAL
1898 {
1899 1868 ▶ my ( $self, $str ) = @_;
Subroutine LITERAL: called CC=7 SCAR=19.5
Pod undocumented
1900  
1901 #
1902 # DAA
1903 # strip parens (if any)
1904 #
1905 1868 ▶ $str = $1 while ( $str =~ m/^\s*\(\s*(.+)\s*\)\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /^\s*\(\s*(.+)\s*\)\s*$/ and do { $str = $1 } 0 1868 1868
1906  
1907 1868 ▶ return 'null' if $str =~ m/^NULL$/i; # NULL
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^NULL$/i 27 1841 1868
1908 1841 ▶ return 'boolean' if $str =~ m/^(?:TRUE|FALSE)$/i; # TRUE/FALSE
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^(?:TRUE|FALSE)$/i 13 1828 1841
1909  
1910 # return 'empty_string' if $str =~ /^~E~$/i; # NULL
1911 1828 ▶ if ( $str eq '?' )
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq "?") 36 1792 1828
1912 {
1913 36 $self->{struct}->{num_placeholders}++;
1914 36 return 'placeholder';
1915 }
1916  
1917 # return 'placeholder' if $str eq '?'; # placeholder question mark
1918 1792 ▶ return 'string' if $str =~ m/^'.*'$/s; # quoted string
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^'.*'$/s 1 1791 1792
1919 # return 'number' if $str =~ m/^[+-]?(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/; # number
1920 1791 ▶ return 'number' if ( looks_like_number($str) ); # number
Branch: 1 branch
BranchTrueFalseTotal
if &looks_like_number($str) 695 1096 1791
1921  
1922 1096 return undef;
1923 }
1924 ###################################################################
1925 # PREDICATE
1926 ###################################################################
1927 sub PREDICATE
1928 {
1929 270 ▶ my ( $self, $str ) = @_;
Subroutine PREDICATE: called CC=24 SCAR=32.6
Pod undocumented
1930  
1931 270 my ( $arg1, $op, $arg2, $opexp );
1932  
1933 $opexp = $self->{opts}{valid_comparison_NOT_ops_regex}, ( $arg1, $op, $arg2 ) = $str =~ /$opexp/i
1934 270 ▶ if $self->{opts}{valid_comparison_NOT_ops_regex};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"opts"}{"valid_comparison_NOT_ops_regex"} 270 0 270
1935  
1936 $opexp = $self->{opts}{valid_comparison_twochar_ops_regex}, ( $arg1, $op, $arg2 ) = $str =~ /$opexp/i
1937 if ( !defined($op)
1938 270 ▶ && $self->{opts}{valid_comparison_twochar_ops_regex} );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $op and $self->{"opts"}{"valid_comparison_twochar_ops_regex"} 260 10 270
Condition66%2/3
not defined $op and $self->{"opts"}{"valid_comparison_twochar_ops_regex"}
!ll&&!rl&&r
100260
MC/DC50%1/2
not defined $op and $self->{"opts"}{"valid_comparison_twochar_ops_regex"}
not defined $op $self->{"opts"}{"valid_comparison_twochar_ops_regex"}
Truth table66%2/3
not(A) and B
A= not defined $opB= $self->{"opts"}{"valid_comparison_twochar_ops_regex"}
ABresult
0X0
100
111
1939  
1940 $opexp = $self->{opts}{valid_comparison_ops_regex}, ( $arg1, $op, $arg2 ) = $str =~ /$opexp/i
1941 270 ▶ if ( !defined($op) && $self->{opts}{valid_comparison_ops_regex} );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $op and $self->{"opts"}{"valid_comparison_ops_regex"} 254 16 270
Condition66%2/3
not defined $op and $self->{"opts"}{"valid_comparison_ops_regex"}
!ll&&!rl&&r
160254
MC/DC50%1/2
not defined $op and $self->{"opts"}{"valid_comparison_ops_regex"}
not defined $op $self->{"opts"}{"valid_comparison_ops_regex"}
Truth table66%2/3
not(A) and B
A= not defined $opB= $self->{"opts"}{"valid_comparison_ops_regex"}
ABresult
0X0
100
111
1942  
1943 #
1944 ### USER-DEFINED PREDICATE
1945 #
1946 269 ▶ unless ( defined $arg1 && defined $op && defined $arg2 )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $arg1 and defined $op and defined $arg2) 0 212 212
Condition66%4/6
defined $arg1 and defined $op and defined $arg2
!ll&&!rl&&r
570212
defined $arg1 and defined $op
!ll&&!rl&&r
570212
MC/DC33%1/3
defined $arg1 and defined $op and defined $arg2
defined $arg1 defined $op defined $arg2
Truth table50%2/4
A and B and C
A= defined $arg1B= defined $opC= defined $arg2
ABCresult
0XX0
10X0
1100
1111
1947 {
1948 57 $arg1 = $str;
1949 57 $op = 'USER_DEFINED';
1950 57 $arg2 = '';
1951 }
1952  
1953 269 $op = uc $op;
1954  
1955 # my $uname = $self->is_func($arg1);
1956 # if (!$uname) {
1957 # $arg1 =~ s/^(\S+).*$/$1/;
1958 # return $self->do_err("Bad predicate: '$arg1'!");
1959 # }
1960  
1961 269 my $negated = 0; # boolean value showing if predicate is negated
1962 269 my %not; # hash showing elements modified by NOT
1963 #
1964 # e.g. "NOT bar = foo" -> %not = (arg1=>1)
1965 # "bar NOT LIKE foo" -> %not = (op=>1)
1966 # "NOT bar NOT LIKE foo" -> %not = (arg1=>1,op=>1);
1967 # "NOT bar IS NOT NULL" -> %not = (arg1=>1,op=>1);
1968 # "bar = foo" -> %not = undef;
1969 #
1970 269 ▶ $not{arg1}++
Branch: 1 branch
BranchTrueFalseTotal
if $arg1 =~ s/^NOT (.+)$/$1/i 15 254 269
1971 if ( $arg1 =~ s/^NOT (.+)$/$1/i );
1972  
1973 269 ▶ $not{op}++
Branch: 1 branch
BranchTrueFalseTotal
if $op =~ s/^(.+) NOT$/$1/i or $op =~ s/^NOT (.+)$/$1/i 10 259 269
Condition100%3/3
$op =~ s/^(.+) NOT$/$1/i or $op =~ s/^NOT (.+)$/$1/i
l!l&&r!l&&!r
19259
MC/DC100%2/2
$op =~ s/^(.+) NOT$/$1/i or $op =~ s/^NOT (.+)$/$1/i
$op =~ s/^(.+) NOT$/$1/i $op =~ s/^NOT (.+)$/$1/i
Truth table100%3/3
A or B
A= $op =~ s/^(.+) NOT$/$1/iB= $op =~ s/^NOT (.+)$/$1/i
ABresult
1X1
011
000
1974 if ( $op =~ s/^(.+) NOT$/$1/i
1975 || $op =~ s/^NOT (.+)$/$1/i );
1976  
1977 269 ▶ $negated = 1 if %not and scalar keys %not == 1;
Branch: 1 branch
BranchTrueFalseTotal
if %not and scalar keys %not == 1 25 244 269
Condition66%2/3
%not and scalar keys %not == 1
!ll&&!rl&&r
244025
MC/DC50%1/2
%not and scalar keys %not == 1
%not scalar keys %not == 1
Truth table66%2/3
A and B
A= %notB= scalar keys %not == 1
ABresult
0X0
100
111
1978  
1979 269 ▶ return undef unless $arg1 = $self->ROW_VALUE($arg1);
Branch: 1 branch
BranchTrueFalseTotal
unless $arg1 = $self->ROW_VALUE($arg1) 0 268 268
1980  
1981 268 ▶ if ( $op ne 'USER_DEFINED' )
Branch: 1 branch
BranchTrueFalseTotal
if ($op ne 'USER_DEFINED') { } 212 56 268
1982 { # USER-PREDICATE;
1983 212 ▶ return undef unless $arg2 = $self->ROW_VALUE($arg2);
Branch: 1 branch
BranchTrueFalseTotal
unless $arg2 = $self->ROW_VALUE($arg2) 0 212 212
1984 }
1985 else
1986 {
1987  
1988 # $arg2 = $self->ROW_VALUE($arg2);
1989 }
1990  
1991 268 ▶ if ( defined( _HASH($arg1) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined &_HASH($arg1) and defined &_HASH($arg2) and ($arg1->{"type"} || "") eq "column" and ($arg2->{"type"} || "") eq "column" and $op eq "=") 27 241 268
Condition81%13/16
defined &_HASH($arg1) and defined &_HASH($arg2) and ($arg1->{"type"} || "") eq "column" and ($arg2->{"type"} || "") eq "column" and $op eq "="
!ll&&!rl&&r
233827
defined &_HASH($arg1) and defined &_HASH($arg2) and ($arg1->{"type"} || "") eq "column" and ($arg2->{"type"} || "") eq "column"
!ll&&!rl&&r
1656835
defined &_HASH($arg1) and defined &_HASH($arg2) and ($arg1->{"type"} || "") eq "column"
!ll&&!rl&&r
8679103
defined &_HASH($arg1) and defined &_HASH($arg2)
!ll&&!rl&&r
086182
$arg1->{'type'} || ''
l!l
1820
$arg2->{'type'} || ''
l!l
1030
MC/DC40%2/5
defined &_HASH($arg1) and defined &_HASH($arg2) and ($arg1->{"type"} || "") eq "column" and ($arg2->{"type"} || "") eq "column" and $op eq "="
defined &_HASH($arg1) defined &_HASH($arg2) $arg1->{'type'} $arg2->{'type'} $op eq "="
Truth table50%3/6
A and B and C and D and E
A= defined &_HASH($arg1)B= defined &_HASH($arg2)C= $arg1->{'type'}D= $arg2->{'type'}E= $op eq "="
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1992 and defined( _HASH($arg2) )
1993 and ( ( $arg1->{type} || '' ) eq 'column' )
1994 and ( ( $arg2->{type} || '' ) eq 'column' )
1995 and ( $op eq '=' ) )
1996 {
1997 27 push( @{ $self->{struct}->{keycols} }, $arg1->{value} );
1998 27 push( @{ $self->{struct}->{keycols} }, $arg2->{value} );
1999 }
2000  
2001 return {
2002 268 neg => $negated,
2003 nots => \%not,
2004 arg1 => $arg1,
2005 op => $op,
2006 arg2 => $arg2,
2007 };
2008 }
2009  
2010 sub _udf_function_names
2011 {
2012 $_[0]->{opts}->{_udf_function_names}
2013 2500 ▶ or return $_[0]->{opts}->{_udf_function_names} = join( "|", map { uc $_ } keys %{ $_[0]->{opts}->{function_names} } );
Subroutine _udf_function_names: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"opts"}{"_udf_function_names"} or return $_[0]{"opts"}{"_udf_function_names"} = join("|", map({uc $_;} keys %{$_[0]{"opts"}{"function_names"};})) 18 2482 2500
2014 2482 $_[0]->{opts}->{_udf_function_names};
2015 }
2016  
2017 sub undo_string_funcs
2018 {
2019 2269 ▶ my ( $self, $str ) = @_;
Subroutine undo_string_funcs: called CC=6 SCAR=17.9
Pod documented
2020 2269 my $f = join( '|', FUNCTION_NAMES, $self->_udf_function_names );
2021  
2022 # eliminate recursion:
2023 # we have to scan for closing brackets, since we may
2024 # have intervening MATH elements with brackets
2025 2269 my ( $brackets, $pos, @lbrackets ) = (0);
2026 2269 ▶ while ( $str =~ /\G.*?((\b($f)\s*\[)|[\[\]])/igcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G.*?((\b($f)\s*\[)|[\[\]])/cgis) 278 2269 2547
2027 {
2028 278 ▶ if ( $1 eq ']' )
Branch: 2 branches
BranchTrueFalseTotal
if ($1 eq ']') { } 139 139 278
elsif ($1 eq '[') { } 5 134 139
2029 {
2030 # close paren, see if any pending function open
2031 # paren matches it
2032 139 $brackets--;
2033 139 ▶ $pos = $+[0], substr( $str, $+[0] - 1, 1 ) = ')', pos($str) = $pos, pop @lbrackets
Branch: 1 branch
BranchTrueFalseTotal
if @lbrackets and $lbrackets[-1] == $brackets 134 5 139
Condition66%2/3
@lbrackets and $lbrackets[-1] == $brackets
!ll&&!rl&&r
50134
MC/DC50%1/2
@lbrackets and $lbrackets[-1] == $brackets
@lbrackets $lbrackets[-1] == $brackets
Truth table66%2/3
A and B
A= @lbracketsB= $lbrackets[-1] == $brackets
ABresult
0X0
100
111
2034 if ( @lbrackets && ( $lbrackets[-1] == $brackets ) );
2035 }
2036 elsif ( $1 eq '[' )
2037 {
2038 # just an open paren, count it and go on
2039 5 $brackets++;
2040 }
2041 else
2042 {
2043 # new function definition, capture its open paren
2044 # also uppercase the function name
2045 134 $pos = $+[0];
2046 134 substr( $str, $-[3], length($3) ) = uc $3;
2047 134 substr( $str, $+[0] - 1, 1 ) = '(';
2048 134 pos($str) = $pos;
2049 134 push @lbrackets, $brackets;
2050 134 $brackets++;
2051 }
2052 }
2053  
2054 2269 return $str;
2055 }
2056  
2057 sub undo_math_funcs
2058 {
2059 2269 ▶ my $str = $_[0];
Subroutine undo_math_funcs: called CC=2 SCAR=6.9
Pod documented
2060  
2061 # eliminate recursion
2062 2269 ▶ while ( $str =~ s/MATH\[([^\]\[]+?)\]/($1)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/MATH\[([^\]\[]+?)\]/($1)/) 5 2269 2274
2063 {
2064 }
2065  
2066 2269 return $str;
2067 }
2068  
2069 #
2070 # DAA
2071 # need better nested function/parens handling
2072 #
2073 sub extract_func_args
2074 {
2075 339 ▶ my ( $self, $value ) = @_;
Subroutine extract_func_args: called CC=7 SCAR=19.5
Pod documented
2076  
2077 339 my @final_args = ();
2078 339 my ( $spos, $parens, $epos, $delim ) = ( 0, 0, 0, 0 );
2079 339 ▶ while ( $value =~ m/\G.*?([\(\),])/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /\G.*?([\(\),])/cgs) 193 339 532
2080 {
2081 193 $epos = $+[0];
2082 193 $delim = $1;
2083 193 ▶ unless ( $parens or ( $delim ne ',' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($parens or $delim ne ",") 143 50 193
Condition100%3/3
$parens or $delim ne ","
l!l&&r!l&&!r
3218143
MC/DC100%2/2
$parens or $delim ne ","
$parens $delim ne ","
Truth table100%3/3
A or B
A= $parensB= $delim ne ","
ABresult
1X1
011
000
2084 {
2085 143 push( @final_args, $self->ROW_VALUE( substr( $value, $spos, $epos - $spos - 1 ) ) );
2086 143 $spos = $epos;
2087 143 next;
2088 }
2089  
2090 50 ▶ unless ( $delim eq ',' )
Branch: 1 branch
BranchTrueFalseTotal
unless ($delim eq ",") 36 14 50
2091 {
2092 36 ▶ $parens += ( $delim eq '(' ) ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$delim eq '(' ? : 18 18 36
2093 }
2094 }
2095  
2096 # don't forget the last argument
2097 339 ▶ if ( $spos != length($value) )
Branch: 1 branch
BranchTrueFalseTotal
if ($spos != length $value) 305 34 339
2098 {
2099 305 $epos = length($value);
2100 305 push( @final_args, $self->ROW_VALUE( substr( $value, $spos, $epos - $spos ) ) ); # XXX
2101 }
2102  
2103 339 return @final_args;
2104 }
2105  
2106 ###################################################################
2107 # ROW_VALUE ::= <literal> | <column_name>
2108 ###################################################################
2109 sub ROW_VALUE
2110 {
2111 2269 ▶ my ( $self, $str ) = @_;
Subroutine ROW_VALUE: called CC=58 SCAR=42.0
Pod undocumented
2112  
2113 2269 $str =~ s/^\s+//;
2114 2269 $str =~ s/\s+$//;
2115 2269 $str = $self->undo_string_funcs($str);
2116 2269 $str = undo_math_funcs($str);
2117 2269 my ( $orgstr, $f, $bf ) = ( $str, FUNCTION_NAMES, BAREWORD_FUNCTIONS );
2118  
2119 # USER-DEFINED FUNCTION
2120 2269 my ( $user_func_name, $user_func_args, $is_func );
2121  
2122 # DAA
2123 # need better paren check here
2124 2269 ▶ if ( $str =~ m/^([^\s\(]+)\s*(.*)\s*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^([^\s\(]+)\s*(.*)\s*$/) { } 2265 4 2269
2125 {
2126 2265 $user_func_name = $1;
2127 2265 $user_func_args = $2;
2128  
2129 # convert operator-like function to parenthetical format
2130 2265 ▶ if ( ( $is_func = $self->is_func($user_func_name) )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_func = $self->is_func($user_func_name) and not $user_func_args =~ /^\(.*\)$/ and $is_func =~ /^(?:$bf)$/i) 8 2257 2265
Condition100%6/6
$is_func = $self->is_func($user_func_name) and not $user_func_args =~ /^\(.*\)$/ and $is_func =~ /^(?:$bf)$/i
!ll&&!rl&&r
225258
$is_func = $self->is_func($user_func_name) and not $user_func_args =~ /^\(.*\)$/
!ll&&!rl&&r
192133113
MC/DC100%3/3
$is_func = $self->is_func($user_func_name) and not $user_func_args =~ /^\(.*\)$/ and $is_func =~ /^(?:$bf)$/i
$is_func = $self->is_func($user_func_name) not $user_func_args =~ /^\(.*\)$/ $is_func =~ /^(?:$bf)$/i
Truth table100%4/4
A and not(B) and C
A= $is_func = $self->is_func($user_func_name)B= not $user_func_args =~ /^\(.*\)$/C= $is_func =~ /^(?:$bf)$/i
ABCresult
0XX0
10X0
1100
1111
2131 && ( $user_func_args !~ m/^\(.*\)$/ )
2132 && ( $is_func =~ /^(?:$bf)$/i ) )
2133 {
2134 8 $orgstr = $str = "$user_func_name ($user_func_args)";
2135 }
2136 }
2137 else
2138 {
2139 4 $user_func_name = $str;
2140 4 $user_func_name =~ s/^(\S+).*$/$1/;
2141 4 $user_func_args = '';
2142 4 $is_func = $self->is_func($user_func_name);
2143 }
2144  
2145 # BLKB
2146 # Limiting the parens convert shortcut, so that "SELECT LOG(1), PI" works as a
2147 # two functions, and "SELECT x FROM log" works as a table
2148 2269 ▶ undef $is_func if ( $is_func && $is_func !~ /^(?:$bf)$/i && $str !~ m/^\S+\s*\(.*\)\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $is_func and not $is_func =~ /^(?:$bf)$/i and not $str =~ /^\S+\s*\(.*\)\s*$/ 5 2264 2269
Condition100%6/6
$is_func and not $is_func =~ /^(?:$bf)$/i and not $str =~ /^\S+\s*\(.*\)\s*$/
!ll&&!rl&&r
19613035
$is_func and not $is_func =~ /^(?:$bf)$/i
!ll&&!rl&&r
192536308
MC/DC100%3/3
$is_func and not $is_func =~ /^(?:$bf)$/i and not $str =~ /^\S+\s*\(.*\)\s*$/
$is_func not $is_func =~ /^(?:$bf)$/i not $str =~ /^\S+\s*\(.*\)\s*$/
Truth table100%4/4
A and not(B) and not(C)
A= $is_funcB= not $is_func =~ /^(?:$bf)$/iC= not $str =~ /^\S+\s*\(.*\)\s*$/
ABCresult
0XX0
10X0
1100
1111
2149  
2150 2269 ▶ if ( $is_func && ( uc($is_func) !~ m/^($f)$/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_func and not uc($is_func) =~ /^($f)$/) 339 1930 2269
Condition66%2/3
$is_func and not uc($is_func) =~ /^($f)$/
!ll&&!rl&&r
19300339
MC/DC50%1/2
$is_func and not uc($is_func) =~ /^($f)$/
$is_func not uc($is_func) =~ /^($f)$/
Truth table66%2/3
A and not(B)
A= $is_funcB= not uc($is_func) =~ /^($f)$/
ABresult
0X0
100
111
2151 {
2152 339 my ( $name, $value ) = ( $user_func_name, '' );
2153 339 ▶ if ( $str =~ m/^(\S+)\s*\((.*)\)\s*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^(\S+)\s*\((.*)\)\s*$/) 339 0 339
2154 {
2155 339 $name = $1;
2156 339 $value = $2;
2157 339 $is_func = $self->is_func($name);
2158 }
2159  
2160 339 ▶ if ($is_func)
Branch: 1 branch
BranchTrueFalseTotal
if ($is_func) 339 0 339
2161 {
2162 #
2163 # DAA
2164 # need a better argument extractor, since it can
2165 # contain arbitrary (possibly parenthesized)
2166 # expressions/functions
2167 #
2168 # if ($value =~ /\(/ ) {
2169 # $value = $self->ROW_VALUE($value);
2170 # }
2171 # my @args = split ',',$value;
2172  
2173 339 my @final_args = $self->extract_func_args($value);
2174 339 my $usr_sub = $self->{opts}->{function_names}->{$is_func};
2175 339 $self->{struct}->{procedure} = {};
2176 339 ▶ if ($usr_sub)
Branch: 1 branch
BranchTrueFalseTotal
if ($usr_sub) 339 0 339
2177 {
2178 339 $value = {
2179 type => 'function',
2180 name => lc $name,
2181 subname => $usr_sub,
2182 value => \@final_args,
2183 fullorg => $orgstr,
2184 };
2185  
2186 339 return $value;
2187 }
2188 }
2189 }
2190  
2191 1930 my $type;
2192 # MATH
2193 #
2194 1930 ▶ if ( $str =~ m/[\*\+\-\/\%]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[[\*\+\-/\%]]) 44 1886 1930
2195 {
2196 44 my @vals;
2197 44 my $i = -1;
2198 44 my $open_parens = $str =~ tr/\(//;
2199 44 my $close_parens = $str =~ tr/\)//;
2200 44 ▶ if ( $open_parens != $close_parens )
Branch: 1 branch
BranchTrueFalseTotal
if ($open_parens != $close_parens) 0 44 44
2201 {
2202 0 return $self->do_err("Mismatched parentheses in term '$str'!");
2203 }
2204  
2205 # $str =~ s/([^\s\*\+\-\/\%\)\(]+)/push @vals,$1;++$i;"?$i?"/ge;
2206 44 ▶ while ( $str =~ m/\G.*?([^\s\*\+\-\/\%\)\(]+)/g )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[\G.*?([^\s\*\+\-/\%\)\(]+)]g) 72 44 116
2207 {
2208 72 my $term = $1;
2209 72 my $start = pos($str) - length($term);
2210 72 ▶ if ( $self->is_func($term) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_func($term)) { } 4 68 72
2211 {
2212 4 my $lparens = 0;
2213 4 my $rparens = 0;
2214 4 ▶ while ( $str =~ m/\G.*?([\(\)])/gcs )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\G.*?([\(\)])/cgs) 2 4 6
2215 {
2216 2 ▶ ++$lparens if ( '(' eq $1 );
Branch: 1 branch
BranchTrueFalseTotal
if "(" eq $1 2 0 2
2217 2 ▶ ++$rparens if ( ')' eq $1 );
Branch: 1 branch
BranchTrueFalseTotal
if ")" eq $1 0 2 2
2218 2 ▶ last if ( $lparens == $rparens );
Branch: 1 branch
BranchTrueFalseTotal
if $lparens == $rparens 0 2 2
2219 }
2220 4 my $now = pos($str);
2221 4 ++$i;
2222 4 $term = substr( $str, $start, $now - $start, "?$i?" );
2223 4 push( @vals, $term );
2224 4 pos($str) = $start + length("?$i?");
2225 }
2226 else
2227 {
2228 68 push( @vals, $term );
2229 68 ++$i;
2230 68 substr( $str, $start, length($term), "?$i?" );
2231 68 pos($str) = $start + length("?$i?");
2232 }
2233 }
2234  
2235 44 my @newvalues;
2236 44 foreach my $val (@vals)
2237 {
2238 72 my $newval = $self->ROW_VALUE($val);
2239 72 ▶ if ( $newval && $newval->{type} !~ m/number|column|placeholder|function/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($newval and not $newval->{"type"} =~ /number|column|placeholder|function/) 0 72 72
Condition66%2/3
$newval and not $newval->{"type"} =~ /number|column|placeholder|function/
!ll&&!rl&&r
3690
MC/DC0%0/2
$newval and not $newval->{"type"} =~ /number|column|placeholder|function/
$newval not $newval->{"type"} =~ /number|column|placeholder|function/
Truth table66%2/3
A and not(B)
A= $newvalB= not $newval->{"type"} =~ /number|column|placeholder|function/
ABresult
0X0
100
111
2240 {
2241 0 return $self->do_err(qq[String '$val' not allowed in Numeric expression!]);
2242 }
2243 72 push( @newvalues, $newval );
2244 }
2245  
2246 return {
2247 44 type => 'function',
2248 name => 'numeric_exp',
2249 str => $str,
2250 value => \@newvalues,
2251 fullorg => $orgstr,
2252 };
2253 }
2254  
2255 # SUBSTRING (value FROM start [FOR length])
2256 #
2257 1886 ▶ if ( $str =~ m/^SUBSTRING \((.+?) FROM (.+)\)\s*$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^SUBSTRING \((.+?) FROM (.+)\)\s*$/i) 4 1882 1886
2258 {
2259 4 my $name = 'SUBSTRING';
2260 4 my $start = $2;
2261 4 my $value = $self->ROW_VALUE($1);
2262 4 my $length;
2263 4 ▶ if ( $start =~ /^(.+?) FOR (.+)$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($start =~ /^(.+?) FOR (.+)$/i) 3 1 4
2264 {
2265 3 $start = $1;
2266 3 $length = $2;
2267 3 $length = $self->ROW_VALUE($length);
2268 }
2269 4 $start = $self->ROW_VALUE($start);
2270 4 $str =~ s/\?(\d+)\?/$self->{struct}->{literals}->[$1]/g;
2271 4 ▶ if ( ( $start->{type} eq 'string' )
Branch: 1 branch
BranchTrueFalseTotal
if ($start->{"type"} eq "string" or $start->{"length"} and $start->{"length"}{"type"} eq "string") 0 4 4
Condition33%2/6
$start->{"type"} eq "string" or $start->{"length"} and $start->{"length"}{"type"} eq "string"
l!l&&r!l&&!r
004
$start->{"length"} and $start->{"length"}{"type"} eq "string"
!ll&&!rl&&r
400
MC/DC0%0/3
$start->{"type"} eq "string" or $start->{"length"} and $start->{"length"}{"type"} eq "string"
$start->{"type"} eq "string" $start->{"length"} $start->{"length"}{"type"} eq "string"
Truth table0%0/4
A or B and C
A= $start->{"type"} eq "string"B= $start->{"length"}C= $start->{"length"}{"type"} eq "string"
ABCresult
1XX1
0111
00X0
0100
2272 or ( $start->{length} && ( $start->{length}->{type} eq 'string' ) ) )
2273 {
2274 0 return $self->do_err("Can't use a string as a SUBSTRING position: '$str'!");
2275 }
2276 4 ▶ return undef unless ($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 4 4
2277 return $self->do_err("Can't use a number in SUBSTRING: '$str'!")
2278 4 ▶ if $value->{type} eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $value->{"type"} eq "number" 0 4 4
2279 return {
2280 4 type => 'function',
2281 name => $name,
2282 value => [$value],
2283 start => $start,
2284 length => $length,
2285 fullorg => $orgstr,
2286 };
2287 }
2288  
2289 # TRIM ( [ [TRAILING|LEADING|BOTH] ['char'] FROM ] value )
2290 #
2291 1882 ▶ if ( $str =~ m/^(TRIM) \((.+)\)\s*$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^(TRIM) \((.+)\)\s*$/i) 11 1871 1882
2292 {
2293 11 my $name = uc $1;
2294 11 my $value = $2;
2295 11 my ( $trim_spec, $trim_char );
2296 11 ▶ if ( $value =~ m/^(.+) FROM ([^\(\)]+)$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(.+) FROM ([^\(\)]+)$/i) 5 6 11
2297 {
2298 5 my $front = $1;
2299 5 $value = $2;
2300 5 ▶ if ( $front =~ m/^\s*(TRAILING|LEADING|BOTH)(.*)$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($front =~ /^\s*(TRAILING|LEADING|BOTH)(.*)$/i) { } 5 0 5
2301 {
2302 5 $trim_spec = uc $1;
2303 5 $trim_char = $2;
2304 5 $trim_char =~ s/^\s+//;
2305 5 $trim_char =~ s/\s+$//;
2306 5 ▶ undef $trim_char if ( length($trim_char) == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if length $trim_char == 0 3 2 5
2307 }
2308 else
2309 {
2310 0 $trim_char = $front;
2311 0 $trim_char =~ s/^\s+//;
2312 0 $trim_char =~ s/\s+$//;
2313 }
2314 }
2315  
2316 11 ▶ $trim_char ||= '';
Condition100%2/2
$trim_char ||= ""
l!l
29
MC/DC100%1/1
$trim_char ||= ""
$trim_char
Truth table100%2/2
A
A= $trim_char
Aresult
11
00
2317 11 $trim_char =~ s/\?(\d+)\?/$self->{struct}->{literals}->[$1]/g;
2318 11 $value = $self->ROW_VALUE($value);
2319 11 ▶ return undef unless ($value);
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 11 11
2320 11 $str =~ s/\?(\d+)\?/$self->{struct}->{literals}->[$1]/g;
2321 11 ▶ my $value_type = $value->{type} if ref $value eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 11 0 11
2322 11 ▶ $value_type = $value->[0] if ( defined( _ARRAY($value) ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined &_ARRAY($value) 0 11 11
2323 11 ▶ return $self->do_err("Can't use a number in TRIM: '$str'!")
Branch: 1 branch
BranchTrueFalseTotal
if $value_type and $value_type eq "number" 0 11 11
Condition33%1/3
$value_type and $value_type eq "number"
!ll&&!rl&&r
0110
MC/DC0%0/2
$value_type and $value_type eq "number"
$value_type $value_type eq "number"
Truth table33%1/3
A and B
A= $value_typeB= $value_type eq "number"
ABresult
0X0
100
111
2324 if ( $value_type and $value_type eq 'number' );
2325  
2326 return {
2327 11 type => 'function',
2328 name => $name,
2329 value => [$value],
2330 trim_spec => $trim_spec,
2331 trim_char => $trim_char,
2332 fullorg => $orgstr,
2333 };
2334 }
2335  
2336 # UNKNOWN FUNCTION
2337 1871 ▶ if ( $str =~ m/^(\S+) \(/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^(\S+) \(/) 2 1869 1871
2338 {
2339 2 return $self->do_err("Unknown function '$1'");
2340 }
2341  
2342 # STRING CONCATENATION
2343 #
2344 1869 ▶ if ( $str =~ m/\|\|/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /\|\|/) 1 1868 1869
2345 {
2346 1 my @vals = split( m/ \|\| /, $str );
2347 1 my @newvals;
2348 1 for my $val (@vals)
2349 {
2350 3 my $newval = $self->ROW_VALUE($val);
2351 3 ▶ return undef unless ($newval);
Branch: 1 branch
BranchTrueFalseTotal
unless $newval 0 3 3
2352 return $self->do_err("Can't use a number in string concatenation: '$str'!")
2353 3 ▶ if ( $newval->{type} eq 'number' );
Branch: 1 branch
BranchTrueFalseTotal
if $newval->{"type"} eq "number" 0 3 3
2354 3 push @newvals, $newval;
2355 }
2356 return {
2357 1 type => 'function',
2358 name => 'str_concat',
2359 value => \@newvals,
2360 fullorg => $orgstr,
2361 };
2362 }
2363  
2364 # NULL, BOOLEAN, PLACEHOLDER, NUMBER
2365 #
2366 1868 ▶ if ( $type = $self->LITERAL($str) )
Branch: 1 branch
BranchTrueFalseTotal
if ($type = $self->LITERAL($str)) 772 1096 1868
2367 {
2368 772 ▶ undef $str if ( $type eq 'null' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "null" 27 745 772
2369 772 ▶ $str = 1 if ( $type eq 'boolean' and $str =~ /^TRUE$/i );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "boolean" and $str =~ /^TRUE$/i 13 759 772
Condition66%2/3
$type eq "boolean" and $str =~ /^TRUE$/i
!ll&&!rl&&r
759013
MC/DC50%1/2
$type eq "boolean" and $str =~ /^TRUE$/i
$type eq "boolean" $str =~ /^TRUE$/i
Truth table66%2/3
A and B
A= $type eq "boolean"B= $str =~ /^TRUE$/i
ABresult
0X0
100
111
2370 772 ▶ $str = 0 if ( $type eq 'boolean' and $str =~ /^FALSE$/i );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "boolean" and $str =~ /^FALSE$/i 0 772 772
Condition66%2/3
$type eq "boolean" and $str =~ /^FALSE$/i
!ll&&!rl&&r
759130
MC/DC0%0/2
$type eq "boolean" and $str =~ /^FALSE$/i
$type eq "boolean" $str =~ /^FALSE$/i
Truth table66%2/3
A and B
A= $type eq "boolean"B= $str =~ /^FALSE$/i
ABresult
0X0
100
111
2371  
2372 # if ($type eq 'empty_string') {
2373 # $str = '';
2374 # $type = 'string';
2375 # }
2376 772 ▶ $str = '' if ( $str and $str eq q('') );
Branch: 1 branch
BranchTrueFalseTotal
if $str and $str eq "''" 1 771 772
Condition100%3/3
$str and $str eq "''"
!ll&&!rl&&r
547171
MC/DC100%2/2
$str and $str eq "''"
$str $str eq "''"
Truth table100%3/3
A and B
A= $strB= $str eq "''"
ABresult
0X0
100
111
2377 return {
2378 772 type => $type,
2379 value => $str,
2380 fullorg => $orgstr,
2381 };
2382 }
2383  
2384 # QUOTED STRING LITERAL
2385 #
2386 1096 ▶ if ( $str =~ m/\?(\d+)\?/ )
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ /\?(\d+)\?/) { } 419 677 1096
elsif ($str =~ /^\?LI(\d+)\?$/) { } 30 647 677
2387 {
2388 return {
2389 type => 'string',
2390 value => $self->{struct}->{literals}->[$1],
2391 419 fullorg => $self->{struct}->{literals}->[$1],
2392 };
2393 }
2394 elsif ( $str =~ /^\?LI(\d+)\?$/ )
2395 {
2396 30 return $self->ROW_VALUE_LIST( $self->{struct}->{list_ids}->[$1] );
2397 }
2398  
2399 # COLUMN NAME
2400 #
2401 647 ▶ return undef unless ( $str = $self->COLUMN_NAME($str) );
Branch: 1 branch
BranchTrueFalseTotal
unless $str = $self->COLUMN_NAME($str) 1 645 646
2402  
2403 645 ▶ if ( $str =~ m/^(.*)\./ )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^(.*)\./) 119 526 645
2404 {
2405 119 my $table_name = $1;
2406 119 $self->_verify_tablename( $table_name, "WHERE" );
2407 }
2408  
2409 # push @{ $self->{struct}->{where_cols}},$str
2410 # unless $self->{tmp}->{where_cols}->{"$str"};
2411 645 ++$self->{tmp}->{where_cols}->{$str};
2412 return {
2413 645 type => 'column',
2414 value => $str,
2415 fullorg => $orgstr,
2416 };
2417 }
2418  
2419 #########################################################
2420 # ROW_VALUE_LIST ::= <row_value> [,<row_value>...]
2421 #########################################################
2422 sub ROW_VALUE_LIST
2423 {
2424 51 ▶ my ( $self, $row_str ) = @_;
Subroutine ROW_VALUE_LIST: called CC=4 SCAR=14.2
Pod undocumented
2425 51 my @row_list = split ',', $row_str;
2426 51 ▶ if ( !( scalar @row_list ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @row_list) 0 51 51
2427 {
2428 0 return $self->do_err('Missing row value list!');
2429 }
2430 51 my @newvals;
2431 my $newval;
2432 51 for my $row_val (@row_list)
2433 {
2434 119 $row_val =~ s/^\s+//;
2435 119 $row_val =~ s/\s+$//;
2436  
2437 119 ▶ return undef if !( $newval = $self->ROW_VALUE($row_val) );
Branch: 1 branch
BranchTrueFalseTotal
unless $newval = $self->ROW_VALUE($row_val) 0 119 119
2438 119 push @newvals, $newval;
2439 }
2440 51 return \@newvals;
2441 }
2442  
2443 ###############################################
2444 # COLUMN NAME ::= [<table_name>.] <identifier>
2445 ###############################################
2446  
2447 sub COLUMN_NAME
2448 {
2449 673 ▶ my ( $self, $str ) = @_;
Subroutine COLUMN_NAME: called CC=17 SCAR=29.0
Pod undocumented
2450 673 my ( $table_name, $col_name );
2451 673 ▶ if ( $str =~ m/^\s*(\S+)\.(\S+)$/s )
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^\s*(\S+)\.(\S+)$/s) { } 122 551 673
2452 {
2453 122 ( $table_name, $col_name ) = ( $1, $2 );
2454 122 ▶ if ( !$self->{opts}->{valid_options}->{SELECT_MULTIPLE_TABLES} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"opts"}{"valid_options"}{"SELECT_MULTIPLE_TABLES"}) 0 122 122
2455 {
2456 0 return $self->do_err('Dialect does not support multiple tables!');
2457 }
2458 122 ▶ return undef unless ( $table_name = $self->TABLE_NAME($table_name) );
Branch: 1 branch
BranchTrueFalseTotal
unless $table_name = $self->TABLE_NAME($table_name) 0 122 122
2459 122 $table_name = $self->replace_quoted_ids($table_name);
2460 122 $self->_verify_tablename($table_name);
2461 }
2462 else
2463 {
2464 551 $col_name = $str;
2465 }
2466  
2467 673 $col_name =~ s/^\s+//;
2468 673 $col_name =~ s/\s+$//;
2469  
2470 673 my $user_func = $col_name;
2471 673 $user_func =~ s/^(\S+).*$/$1/;
2472 673 ▶ if ( $col_name !~ m/^(TRIM|SUBSTRING)$/i )
Branch: 1 branch
BranchTrueFalseTotal
unless ($col_name =~ /^(TRIM|SUBSTRING)$/i) 673 0 673
2473 {
2474 673 ▶ undef $user_func unless ( $self->{opts}->{function_names}->{ uc $user_func } );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"opts"}{"function_names"}{uc $user_func} 670 3 673
2475 }
2476 673 ▶ if ( !$user_func )
Branch: 1 branch
BranchTrueFalseTotal
unless ($user_func) 670 3 673
2477 {
2478 670 ▶ return undef unless ( ( $col_name eq '*' ) || $self->IDENTIFIER($col_name) );
Branch: 1 branch
BranchTrueFalseTotal
unless $col_name eq "*" or $self->IDENTIFIER($col_name) 1 668 669
Condition66%2/3
$col_name eq "*" or $self->IDENTIFIER($col_name)
l!l&&r!l&&!r
06691
MC/DC50%1/2
$col_name eq "*" or $self->IDENTIFIER($col_name)
$col_name eq "*" $self->IDENTIFIER($col_name)
Truth table66%2/3
A or B
A= $col_name eq "*"B= $self->IDENTIFIER($col_name)
ABresult
1X1
011
000
2479 }
2480  
2481 #
2482 # MAKE COL NAMES ALL UPPER CASE UNLESS IS DELIMITED IDENTIFIER
2483 671 my $orgcol = $col_name;
2484  
2485 671 ▶ if ( $col_name =~ m/^\?QI(\d+)\?$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($col_name =~ /^\?QI(\d+)\?$/) { } 10 661 671
2486 {
2487 10 $col_name = '"' . $self->{struct}->{quoted_ids}->[$1] . '"';
2488 }
2489 else
2490 {
2491 $col_name = lc $col_name
2492 unless (
2493 661 ▶ ( $self->{struct}->{command} eq 'CREATE' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"struct"}{"command"} eq "CREATE" or $col_name =~ /^(?:\p{Word}+\.)?"/ 661 0 661
Condition33%1/3
$self->{"struct"}{"command"} eq "CREATE" or $col_name =~ /^(?:\p{Word}+\.)?"/
l!l&&r!l&&!r
00661
MC/DC0%0/2
$self->{"struct"}{"command"} eq "CREATE" or $col_name =~ /^(?:\p{Word}+\.)?"/
$self->{"struct"}{"command"} eq "CREATE" $col_name =~ /^(?:\p{Word}+\.)?"/
Truth table33%1/3
A or B
A= $self->{"struct"}{"command"} eq "CREATE"B= $col_name =~ /^(?:\p{Word}+\.)?"/
ABresult
1X1
011
000
2494 ##############################################
2495 #
2496 # JZ addition to RR's alias patch
2497 #
2498 or ( $col_name =~ m/^(?:\p{Word}+\.)?"/ )
2499 );
2500  
2501 }
2502  
2503 #
2504 $col_name = $self->{struct}->{column_aliases}->{$col_name}
2505 671 ▶ if ( $self->{struct}->{column_aliases}->{$col_name} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"struct"}{"column_aliases"}{$col_name} 0 671 671
2506  
2507 # $orgcol = $self->replace_quoted_ids($orgcol);
2508 ##############################################
2509  
2510 671 ▶ if ($table_name)
Branch: 1 branch
BranchTrueFalseTotal
if ($table_name) 122 549 671
2511 {
2512 122 my $alias = $self->{tmp}->{is_table_alias}->{"\L$table_name"};
2513 122 ▶ $table_name = $alias if ( defined($alias) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $alias 17 105 122
2514 122 ▶ $table_name = lc $table_name unless ( $table_name =~ m/^"/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $table_name =~ /^"/ 120 2 122
2515 122 ▶ $col_name = "$table_name.$col_name" if ( -1 == index( $col_name, '.' ) );
Branch: 1 branch
BranchTrueFalseTotal
if (index($col_name, ".") == -1) 122 0 122
2516 }
2517 671 return $col_name;
2518 }
2519  
2520 #########################################################
2521 # COLUMN NAME_LIST ::= <column_name> [,<column_name>...]
2522 #########################################################
2523 sub COLUMN_NAME_LIST
2524 {
2525 0 ▶ my ( $self, $col_str ) = @_;
Subroutine COLUMN_NAME_LIST: not called CC=4 SCAR=30.0
Pod undocumented
2526  
2527 0 my @col_list = split( ',', $col_str );
2528 0 ▶ return $self->do_err('Missing column name list!') unless ( scalar(@col_list) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @col_list 0 0 0
2529  
2530 0 my @newcols;
2531 0 for my $col (@col_list)
2532 {
2533 0 $col =~ s/^\s+//;
2534 0 $col =~ s/\s+$//;
2535  
2536 0 my $newcol;
2537 0 ▶ return undef unless ( $newcol = $self->COLUMN_NAME($col) );
Branch: 1 branch
BranchTrueFalseTotal
unless $newcol = $self->COLUMN_NAME($col) 0 0 0
2538 0 push( @newcols, $newcol );
2539 }
2540  
2541 0 return \@newcols;
2542 }
2543  
2544 #####################################################
2545 # TABLE_NAME_LIST := <table_name> [,<table_name>...]
2546 #####################################################
2547 sub TABLE_NAME_LIST
2548 {
2549 386 ▶ my ( $self, $table_name_str ) = @_;
Subroutine TABLE_NAME_LIST: called CC=18 SCAR=29.2
Pod undocumented
2550 386 my %aliases = ();
2551 386 my @tables;
2552 386 $table_name_str =~ s/(\?\d+\?),/$1:/g; # fudge commas in functions
2553 386 my @table_names = split ',', $table_name_str;
2554 386 ▶ if ( scalar @table_names > 1
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @table_names > 1 and not $self->{"opts"}{"valid_options"}{"SELECT_MULTIPLE_TABLES"}) 0 386 386
Condition66%2/3
scalar @table_names > 1 and not $self->{"opts"}{"valid_options"}{"SELECT_MULTIPLE_TABLES"}
!ll&&!rl&&r
2831030
MC/DC0%0/2
scalar @table_names > 1 and not $self->{"opts"}{"valid_options"}{"SELECT_MULTIPLE_TABLES"}
scalar @table_names > 1 not $self->{"opts"}{"valid_options"}{"SELECT_MULTIPLE_TABLES"}
Truth table66%2/3
A and not(B)
A= scalar @table_names > 1B= not $self->{"opts"}{"valid_options"}{"SELECT_MULTIPLE_TABLES"}
ABresult
0X0
100
111
2555 and !$self->{opts}->{valid_options}->{SELECT_MULTIPLE_TABLES} )
2556 {
2557 0 return $self->do_err('Dialect does not support multiple tables!');
2558 }
2559  
2560 386 my $bf = BAREWORD_FUNCTIONS;
2561 386 my %is_table_alias;
2562 386 for my $table_str (@table_names)
2563 {
2564 501 $table_str =~ s/(\?\d+\?):/$1,/g; # unfudge commas in functions
2565 501 $table_str =~ s/\s+\(/\(/g; # fudge spaces in functions
2566 501 my ( $table, $alias );
2567 501 my (@tstr) = split( m/\s+/, $table_str );
2568 501 ▶ if ( @tstr == 1 )
Branch: 3 branches
BranchTrueFalseTotal
if (@tstr == 1) { } 475 26 501
elsif (@tstr == 2) { } 11 15 26
elsif (@tstr == 3) { } 13 2 15
2569 {
2570 475 $table = $tstr[0];
2571 }
2572 elsif ( @tstr == 2 )
2573 {
2574 11 $table = $tstr[0];
2575 11 $alias = $tstr[1];
2576 }
2577 elsif ( @tstr == 3 )
2578 {
2579 13 ▶ return $self->do_err("Can't find alias in FROM clause!")
Branch: 1 branch
BranchTrueFalseTotal
unless uc $tstr[1] eq "AS" 0 13 13
2580 unless ( uc( $tstr[1] ) eq 'AS' );
2581 13 $table = $tstr[0];
2582 13 $alias = $tstr[2];
2583 }
2584 else
2585 {
2586 2 return $self->do_err("Can't find table names in FROM clause!");
2587 }
2588  
2589 499 $table =~ s/\(/ \(/g; # unfudge spaces in functions
2590 499 my $u_name = $table;
2591 499 $u_name =~ s/^(\S+)\s*(.*$)/$1/;
2592 499 my $u_args = $2;
2593  
2594 499 ▶ if ( ( $u_name = $self->is_func($u_name) )
Branch: 1 branch
BranchTrueFalseTotal
if ($u_name = $self->is_func($u_name) and $u_name =~ /^(?:$bf)$/i || $table =~ /^$u_name\s*\(/i) { } 2 497 499
Condition83%5/6
$u_name = $self->is_func($u_name) and $u_name =~ /^(?:$bf)$/i || $table =~ /^$u_name\s*\(/i
!ll&&!rl&&r
48982
$u_name =~ /^(?:$bf)$/i or $table =~ /^$u_name\s*\(/i
l!l&&r!l&&!r
028
MC/DC66%2/3
$u_name = $self->is_func($u_name) and $u_name =~ /^(?:$bf)$/i || $table =~ /^$u_name\s*\(/i
$u_name = $self->is_func($u_name) $u_name =~ /^(?:$bf)$/i $table =~ /^$u_name\s*\(/i
Truth table75%3/4
A and B or C
A= $u_name = $self->is_func($u_name)B= $u_name =~ /^(?:$bf)$/iC= $table =~ /^$u_name\s*\(/i
ABCresult
0XX0
1000
11X1
1011
2595 && ( $u_name =~ /^(?:$bf)$/i || $table =~ /^$u_name\s*\(/i ) )
2596 {
2597 2 ▶ $u_args = " $u_args" if ($u_args);
Branch: 1 branch
BranchTrueFalseTotal
if $u_args 2 0 2
2598 2 my $u_func = $self->ROW_VALUE( $u_name . $u_args );
2599 2 $self->{struct}->{table_func}->{$u_name} = $u_func;
2600 2 $self->{struct}->{temp_table} = 1;
2601 2 $table = $u_name;
2602 }
2603 else
2604 {
2605 497 ▶ return undef unless ( $self->TABLE_NAME($table) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($table) 3 492 495
2606 }
2607  
2608 494 $table = $self->replace_quoted_ids($table);
2609 494 ▶ push( @tables, $table =~ m/^"/ ? $table : $table );
Branch: 1 branch
BranchTrueFalseTotal
$table =~ /^"/ ? : 7 487 494
2610  
2611 494 ▶ if ($alias)
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) 24 470 494
2612 {
2613 24 ▶ return unless ( $self->TABLE_NAME($alias) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->TABLE_NAME($alias) 0 24 24
2614 24 $alias = $self->replace_quoted_ids($alias);
2615 24 ▶ if ( $alias =~ m/^"/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($alias =~ /^"/) { } 0 24 24
2616 {
2617 0 push( @{ $aliases{$table} }, $alias );
2618 0 $is_table_alias{$alias} = $table;
2619 }
2620 else
2621 {
2622 24 push( @{ $aliases{$table} }, "\L$alias" );
2623 24 $is_table_alias{"\L$alias"} = $table;
2624 }
2625 }
2626 }
2627 379 my %is_table_name = map { $_ => 1 } @tables;
2628 379 $self->{tmp}->{is_table_alias} = \%is_table_alias;
2629 379 $self->{tmp}->{is_table_name} = \%is_table_name;
2630 379 $self->{struct}->{table_names} = \@tables;
2631 379 $self->{struct}->{table_alias} = \%aliases;
2632 379 ▶ $self->{struct}->{multiple_tables} = 1 if ( @tables > 1 );
Branch: 1 branch
BranchTrueFalseTotal
if @tables > 1 101 278 379
2633 379 return 1;
2634 }
2635  
2636 sub is_func($)
2637 {
2638 3179 ▶ my ( $self, $name ) = @_;
Subroutine is_func: called CC=3 SCAR=11.0
Pod documented
2639 3179 $name =~ s/^(\S+).*$/$1/;
2640 3179 ▶ return $name if ( $self->{opts}->{function_names}->{$name} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"opts"}{"function_names"}{$name} 665 2514 3179
2641 2514 ▶ return uc $name if ( $self->{opts}->{function_names}->{ uc $name } );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"opts"}{"function_names"}{uc $name} 32 2482 2514
2642 2482 undef;
2643 }
2644  
2645 #############################
2646 # TABLE_NAME := <identifier>
2647 #############################
2648 sub TABLE_NAME
2649 {
2650 913 ▶ my ( $self, $table_name ) = @_;
Subroutine TABLE_NAME: called CC=5 SCAR=18.7
Pod undocumented
2651 913 ▶ if ( $table_name =~ m/^(.+?)\.([^\.]+)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_name =~ /^(.+?)\.([^\.]+)$/) 0 913 913
2652 {
2653 0 my $schema = $1; # ignored
2654 0 $table_name = $2;
2655 }
2656 913 ▶ if ( $table_name =~ m/\s*(\S+)\s+\S+/s )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_name =~ /\s*(\S+)\s+\S+/s) 0 913 913
2657 {
2658 0 return $self->do_err("Junk after table name '$1'!");
2659 }
2660 913 $table_name =~ s/\s+//s;
2661 913 ▶ if ( !$table_name )
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_name) 0 913 913
2662 {
2663 0 return $self->do_err('No table name specified!');
2664 }
2665 913 ▶ return $table_name if ( $self->IDENTIFIER($table_name) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->IDENTIFIER($table_name) 908 3 911
2666  
2667 # return undef if !($self->IDENTIFIER($table_name));
2668 # return 1;
2669 }
2670  
2671 sub _verify_tablename
2672 {
2673 244 ▶ my ( $self, $table_name, $location ) = @_;
Subroutine _verify_tablename: called CC=6 SCAR=18.7
2674 244 ▶ if ( defined($location) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $location) { } 122 122 244
2675 {
2676 122 $location = " in $location";
2677 }
2678 else
2679 {
2680 122 $location = "";
2681 }
2682  
2683 244 ▶ if ( $table_name =~ m/^"/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($table_name =~ /^"/) { } 4 240 244
2684 {
2685 4 ▶ if ( !$self->{tmp}->{is_table_name}->{$table_name}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"tmp"}{"is_table_name"}{$table_name} or $self->{"tmp"}{"is_table_alias"}{$table_name}) 0 4 4
Condition33%1/3
$self->{"tmp"}{"is_table_name"}{$table_name} or $self->{"tmp"}{"is_table_alias"}{$table_name}
l!l&&r!l&&!r
400
MC/DC0%0/2
$self->{"tmp"}{"is_table_name"}{$table_name} or $self->{"tmp"}{"is_table_alias"}{$table_name}
$self->{"tmp"}{"is_table_name"}{$table_name} $self->{"tmp"}{"is_table_alias"}{$table_name}
Truth table33%1/3
A or B
A= $self->{"tmp"}{"is_table_name"}{$table_name}B= $self->{"tmp"}{"is_table_alias"}{$table_name}
ABresult
1X1
011
000
2686 and !$self->{tmp}->{is_table_alias}->{$table_name} )
2687 {
2688 0 return $self->do_err("Table '$table_name' referenced$location but not found in FROM list!");
2689 }
2690 }
2691 else
2692 {
2693 240 my @tblnamelist = ( keys( %{ $self->{tmp}->{is_table_name} } ), keys( %{ $self->{tmp}->{is_table_alias} } ) );
2694 240 my $tblnames = join( "|", @tblnamelist );
2695 240 ▶ unless ( $table_name =~ m/^(?:$tblnames)$/i )
Branch: 1 branch
BranchTrueFalseTotal
unless ($table_name =~ /^(?:$tblnames)$/i) 0 240 240
2696 {
2697 0 return $self->do_err(
2698 "Table '$table_name' referenced$location but not found in FROM list (" . join( ",", @tblnamelist ) . ")!" );
2699 }
2700 }
2701  
2702 244 return 1;
2703 }
2704  
2705 ###################################################################
2706 # IDENTIFIER ::= <alphabetic_char> { <alphanumeric_char> | _ }...
2707 #
2708 # and must not be a reserved word or over 128 chars in length
2709 ###################################################################
2710 sub IDENTIFIER
2711 {
2712 1716 ▶ my ( $self, $id ) = @_;
Subroutine IDENTIFIER: called CC=12 SCAR=26.9
Pod undocumented
2713 1716 ▶ if ( $id =~ m/^\?QI(.+)\?$/ or $id =~ m/^\?(.+)\?$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^\?QI(.+)\?$/ or $id =~ /^\?(.+)\?$/) 31 1685 1716
Condition66%2/3
$id =~ /^\?QI(.+)\?$/ or $id =~ /^\?(.+)\?$/
l!l&&r!l&&!r
3101685
MC/DC50%1/2
$id =~ /^\?QI(.+)\?$/ or $id =~ /^\?(.+)\?$/
$id =~ /^\?QI(.+)\?$/ $id =~ /^\?(.+)\?$/
Truth table66%2/3
A or B
A= $id =~ /^\?QI(.+)\?$/B= $id =~ /^\?(.+)\?$/
ABresult
1X1
011
000
2714 {
2715 31 return 1;
2716 }
2717 1685 ▶ if ( $id =~ m/^[`](.+)[`]$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^[`](.+)[`]$/) 21 1664 1685
2718 {
2719 21 ▶ $id = $1 and return 1;
Branch: 1 branch
BranchTrueFalseTotal
$id = $1 and return 1 21 0 21
2720 }
2721 1664 ▶ if ( $id =~ m/^(.+)\.([^\.]+)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^(.+)\.([^\.]+)$/) 0 1664 1664
2722 {
2723 0 my $schema = $1; # ignored
2724 0 $id = $2;
2725 }
2726 1664 $id =~ s/\(|\)//g;
2727 1664 ▶ return 1 if $id =~ m/^".+?"$/s; # QUOTED IDENTIFIER
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /^".+?"$/s 0 1664 1664
2728 1664 my $err = "Bad table or column name: '$id' "; # BAD CHARS
2729 1664 ▶ if ( $id =~ /\W/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /\W/) 4 1660 1664
2730 {
2731 4 $err .= "has chars not alphanumeric or underscore!";
2732 4 return $self->do_err($err);
2733 }
2734 # CSV requires optional start with _
2735 1660 ▶ my $badStartRx = uc( $self->{dialect} ) eq 'ANYDATA' ? qr/^\d/ : qr/^[_\d]/;
Branch: 1 branch
BranchTrueFalseTotal
uc $self->{'dialect'} eq 'ANYDATA' ? : 0 1660 1660
2736 1660 ▶ if ( $id =~ $badStartRx )
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /$badStartRx/) 0 1660 1660
2737 { # BAD START
2738 0 $err .= "starts with non-alphabetic character!";
2739 0 return $self->do_err($err);
2740 }
2741 1660 ▶ if ( length $id > 128 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $id > 128) 0 1660 1660
2742 { # BAD LENGTH
2743 0 $err .= "contains more than 128 characters!";
2744 0 return $self->do_err($err);
2745 }
2746 1660 $id = uc $id;
2747 1660 ▶ if ( $self->{opts}->{reserved_words}->{$id} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"opts"}{"reserved_words"}{$id}) 3 1657 1660
2748 { # BAD RESERVED WORDS
2749 3 $err .= "is a SQL reserved word!";
2750 3 return $self->do_err($err);
2751 }
2752 1657 return 1;
2753 }
2754  
2755 ########################################
2756 # PRIVATE METHODS AND UTILITY FUNCTIONS
2757 ########################################
2758 sub order_joins
2759 {
2760 39 ▶ my ( $self, $links ) = @_;
Subroutine order_joins: called CC=14 SCAR=26.8
Pod documented
2761 39 for my $link (@$links)
2762 {
2763 115 ▶ if ( $link !~ /\./ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($link =~ /\./) 19 96 115
2764 {
2765 19 return [];
2766 }
2767 }
2768 20 @$links = map { s/^(.+)\..*$/$1/; $1; } @$links;
2769 20 my @all_tables;
2770 my %relations;
2771 20 my %is_table;
2772 20 ▶ while (@$links)
Branch: 1 branch
BranchTrueFalseTotal
if (@$links) 48 20 68
2773 {
2774 48 my $t1 = shift @$links;
2775 48 my $t2 = shift @$links;
2776 48 ▶ return undef unless defined $t1 and defined $t2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t1 and defined $t2 0 48 48
Condition33%1/3
defined $t1 and defined $t2
!ll&&!rl&&r
0048
MC/DC0%0/2
defined $t1 and defined $t2
defined $t1 defined $t2
Truth table33%1/3
A and B
A= defined $t1B= defined $t2
ABresult
0X0
100
111
2777 48 ▶ push @all_tables, $t1 unless $is_table{$t1}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_table{$t1}++ 23 25 48
2778 48 ▶ push @all_tables, $t2 unless $is_table{$t2}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_table{$t2}++ 29 19 48
2779 48 $relations{$t1}{$t2}++;
2780 48 $relations{$t2}{$t1}++;
2781 }
2782 20 my @tables = @all_tables;
2783 20 my @order = shift @tables;
2784 20 my %is_ordered = ( $order[0] => 1 );
2785 20 my %visited;
2786 20 ▶ while (@tables)
Branch: 1 branch
BranchTrueFalseTotal
if (@tables) 32 20 52
2787 {
2788 32 my $t = shift @tables;
2789 32 my @rels = keys %{ $relations{$t} };
2790 32 for my $t2 (@rels)
2791 {
2792 37 ▶ next unless $is_ordered{$t2};
Branch: 1 branch
BranchTrueFalseTotal
unless $is_ordered{$t2} 5 32 37
2793 32 push @order, $t;
2794 32 $is_ordered{$t}++;
2795 32 last;
2796 }
2797 32 ▶ if ( !$is_ordered{$t} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_ordered{$t}) 0 32 32
2798 {
2799 0 ▶ push @tables, $t if $visited{$t}++ < @all_tables;
Branch: 1 branch
BranchTrueFalseTotal
if $visited{$t}++ < @all_tables 0 0 0
2800 }
2801 }
2802 20 ▶ return $self->do_err("Unconnected tables in equijoin statement!")
Branch: 1 branch
BranchTrueFalseTotal
if @order < @all_tables 0 20 20
2803 if @order < @all_tables;
2804 20 return \@order;
2805 }
2806  
2807 # PROVIDE BACKWARD COMPATIBILIT FOR JOCHEN'S FEATURE ATTRIBUTES TO NEW
2808 #
2809 #
2810 sub set_feature_flags
2811 {
2812 17 ▶ my ( $self, $select, $create ) = @_;
Subroutine set_feature_flags: called CC=4 SCAR=21.1
Pod documented
2813 17 ▶ if ( defined $select )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $select) 0 17 17
2814 {
2815 0 delete $self->{select};
2816 $self->{opts}->{valid_options}->{SELECT_MULTIPLE_TABLES} =
2817 0 $self->{opts}->{select}->{join} = $select->{join};
2818 }
2819 17 ▶ if ( defined $create )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $create) 0 17 17
2820 {
2821 0 delete $self->{create};
2822 0 for my $key ( keys %$create )
2823 {
2824 0 my $type = $key;
2825 0 $type =~ s/type_(.*)/\U$1/;
2826 $self->{opts}->{valid_data_types}->{$type} = $self->{opts}->{create}->{$key} =
2827 0 $create->{$key};
2828 }
2829 }
2830 }
2831  
2832 sub clean_sql
2833 {
2834 868 ▶ my ( $self, $sql ) = @_;
Subroutine clean_sql: called CC=10 SCAR=23.3
Pod documented
2835 868 my $fields;
2836 868 my $i = -1;
2837 868 my $e = '\\';
2838 868 $e = quotemeta($e);
2839  
2840 #
2841 # patch from cpan@goess.org, adds support for col2=''
2842 #
2843 # $sql =~ s~'(([^'$e]|$e.|'')+)'~push(@$fields,$1);$i++;"?$i?"~ge;
2844 868 $sql =~ s~(?<!')'(([^'$e]|$e.|'')+)'~push(@$fields,$1);$i++;"?$i?"~ge;
2845  
2846 #
2847 868 foreach (@$fields) { $_ =~ s/''/\\'/g; }
2848 868 my @a = $sql =~ m/((?<!\\)(?:(?:\\\\)*)')/g;
2849 868 ▶ if ( ( scalar(@a) % 2 ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(@a) % 2 == 1) 0 868 868
2850 {
2851 0 $sql =~ s/^.*\?(.+)$/$1/;
2852 0 $self->do_err("Mismatched single quote before: <$sql>");
2853 }
2854 868 ▶ if ( $sql =~ m/\?\?(\d)\?/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($sql =~ /\?\?(\d)\?/) 0 868 868
2855 {
2856 0 $sql = $fields->[$1];
2857 0 $self->do_err("Mismatched single quote: <$sql>");
2858 }
2859 868 foreach (@$fields) { $_ =~ s/$e'/'/g; s/^'(.*)'$/$1/; }
2860  
2861 #
2862 # From Steffen G. to correctly return newlines from $dbh->quote;
2863 #
2864 868 foreach (@$fields) { $_ =~ s/([^\\])\\r/$1\r/g; }
2865 868 foreach (@$fields) { $_ =~ s/([^\\])\\n/$1\n/g; }
2866  
2867 868 $self->{struct}->{literals} = $fields;
2868  
2869 868 my $qids;
2870 868 $i = -1;
2871 868 $e = q/""/;
2872  
2873 # $sql =~ s~"(([^"$e]|$e.)+)"~push(@$qids,$1);$i++;"?QI$i?"~ge;
2874 868 $sql =~ s/"(([^"]|"")+)"/push(@$qids,$1);$i++;"?QI$i?"/ge;
2875  
2876 #@$qids = map { s/$e'/'/g; s/^'(.*)'$/$1/; $_} @$qids;
2877 868 ▶ $self->{struct}->{quoted_ids} = $qids if ($qids);
Branch: 1 branch
BranchTrueFalseTotal
if $qids 28 840 868
2878  
2879 # $sql =~ s~'(([^'\\]|\\.)+)'~push(@$fields,$1);$i++;"?$i?"~ge;
2880 # @$fields = map { s/\\'/'/g; s/^'(.*)'$/$1/; $_} @$fields;
2881 #print "$sql [@$fields]\n";# if $sql =~ /SELECT/;
2882  
2883 ## before line 1511
2884 868 my $comment_re = $self->{comment_re};
2885  
2886 # if ( $sql =~ s/($comment_re)//gs) {
2887 # $self->{comment} = $1;
2888 # }
2889 868 ▶ if ( $sql =~ m/(.*)$comment_re$/s )
Branch: 1 branch
BranchTrueFalseTotal
if ($sql =~ /(.*)$comment_re$/s) 0 868 868
2890 {
2891 0 $sql = $1;
2892 0 $self->{comment} = $2;
2893 }
2894 868 ▶ if ( $sql =~ m/^(.*)--(.*)(\n|$)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($sql =~ /^(.*)--(.*)(\n|$)/) 2 866 868
2895 {
2896 2 $sql = $1;
2897 2 $self->{comment} = $2;
2898 }
2899  
2900 868 $sql =~ s/\n/ /g;
2901 868 $sql =~ s/\s+/ /g;
2902 868 $sql =~ s/(\S)\(/$1 (/g; # ensure whitespace before (
2903 868 $sql =~ s/\)(\S)/) $1/g; # ensure whitespace after )
2904 868 $sql =~ s/\(\s*/(/g; # trim whitespace after (
2905 868 $sql =~ s/\s*\)/)/g; # trim whitespace before )
2906 #
2907 # $sql =~ s/\s*\(/(/g; # trim whitespace before (
2908 # $sql =~ s/\)\s*/)/g; # trim whitespace after )
2909 # for my $op (qw(= <> < > <= >= \|\|))
2910 # {
2911 # $sql =~ s/(\S)$op/$1 $op/g;
2912 # $sql =~ s/$op(\S)/$op $1/g;
2913 # }
2914 868 $sql =~ s/(\S)([<>]?=|<>|<|>|\|\|)/$1 $2/g;
2915 868 $sql =~ s/([<>]?=|<>|<|>|\|\|)(\S)/$1 $2/g;
2916 868 $sql =~ s/< >/<>/g;
2917 868 $sql =~ s/< =/<=/g;
2918 868 $sql =~ s/> =/>=/g;
2919 868 $sql =~ s/\s*,/,/g;
2920 868 $sql =~ s/,\s*/,/g;
2921 868 $sql =~ s/^\s+//;
2922 868 $sql =~ s/\s+$//;
2923  
2924 868 return $sql;
2925 }
2926  
2927 sub trim
2928 {
2929 4 ▶ my $str = $_[0] or return ('');
Subroutine trim: called CC=2 SCAR=7.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $str = $_[0] or return "" 0 4 4
2930 4 $str =~ s/^\s+//;
2931 4 $str =~ s/\s+$//;
2932 4 return $str;
2933 }
2934  
2935 sub do_err
2936 {
2937 20 ▶ my ( $self, $err, $errstr ) = @_;
Subroutine do_err: called CC=3 SCAR=11.0
Pod documented
2938  
2939 # $err = $errtype ? "DIALECT ERROR: $err" : "SQL ERROR: $err";
2940 20 $self->{struct}->{errstr} = $err;
2941  
2942 20 ▶ carp $err if ( $self->{PrintError} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PrintError"} 0 20 20
2943 20 ▶ croak $err if ( $self->{RaiseError} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"RaiseError"} 6 14 20
2944 14 return;
2945 }
2946  
2947 #
2948 # DAA
2949 # abstract method so subclasses can provide
2950 # their own syntax transformations
2951 #
2952 sub transform_syntax
2953 {
2954 231 ▶ my ( $self, $str ) = @_;
Subroutine transform_syntax: called CC=1 SCAR=0.0
Pod documented
2955 231 return $str;
2956 }
2957  
2958 sub DESTROY
2959 {
2960 12 ▶ my $self = $_[0];
Subroutine DESTROY: called CC=1 SCAR=0.0
2961  
2962 12 undef $self->{opts};
2963 12 undef $self->{struct};
2964 12 undef $self->{tmp};
2965 12 undef $self->{dialect};
2966 12 undef $self->{dialect_set};
2967 }
2968  
2969 17 1;
2970  
2971 __END__
« Statement.pm ↑ Summary Statement/Functions.pm »