SimpleOps.pm

filter: Statementstmt 65.5% 902 / 1377 Branchbran 53.1% 529 / 996 Conditioncond 44.3% 125 / 282 MC/DCmcdc 23.9% 41 / 171 Subroutinesub 84.1% 69 / 82 Podpod 79.1% 19 / 24 totaltotal 57.4% 1685 / 2932 CC 623 SCAR 66.5
CC
623
Cov
59%
_Call
4624.3
_SelectCursor
1384.7
new
509.9
CRAP 771.4
↑ Summary SimpleOps/DBI/MySQL.pm »
1 ## ABSTRACT SQL Simple Operations Commands
2 #
3 ## LICENSE AND COPYRIGHT
4 #
5 ## Copyright (C) Carlos Celso
6 #
7 ## This program is free software: you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation, either version 3 of the License, or
10 ## (at your option) any later version.
11 #
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ## GNU General Public License for more details.
16 #
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program. If not, see L<http://www.gnu.org/licenses/>.
19 #
20 package SQL::SimpleOps;
21  
22 4 ▶ use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶ use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 4 ▶ use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 4 ▶ use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 ## dynamic modules
31  
32 ## option configfile=
33 ## JSON
34  
35 ## option driver=[drivername]
36 ## SQL::SimpleOps::[interface]::[driver]
37  
38 ## option message_log=1 (used as "required")
39 ## Sys::Syslog
40  
41 ## option sql_save=1 (used as "required")
42 ## Calc::Date
43 ## File::Path
44 ## IO::File
45  
46 ################################################################################
47 ## global initialization
48  
49 4 our @ISA = qw ( Exporter );
50  
51 4 our @EXPORT = qw(
52 new
53 Open Select SelectCursor Delete Insert Update Commit Close Call Wait
54 Join SelectSubQuery
55 getDBH getMessage getRC getRows getLastCursor getLastSQL getLastSave
56 getWhere getAliasTable getAliasCols
57 setDumper
58  
59 SQL_SIMPLE_ALIAS_INSERT
60 SQL_SIMPLE_ALIAS_UPDATE
61 SQL_SIMPLE_ALIAS_DELETE
62 SQL_SIMPLE_ALIAS_SELECT
63 SQL_SIMPLE_ALIAS_WHERE
64 SQL_SIMPLE_ALIAS_GROUPBY
65 SQL_SIMPLE_ALIAS_ORDERBY
66  
67 SQL_SIMPLE_CURSOR_BACK
68 SQL_SIMPLE_CURSOR_NEXT
69 SQL_SIMPLE_CURSOR_TOP
70 SQL_SIMPLE_CURSOR_LAST
71 SQL_SIMPLE_CURSOR_RELOAD
72  
73 SQL_SIMPLE_ORDER_OFF
74 SQL_SIMPLE_ORDER_ASC
75 SQL_SIMPLE_ORDER_DESC
76  
77 SQL_SIMPLE_CMD_OFF
78 SQL_SIMPLE_CMD_ON
79 SQL_SIMPLE_CMD_ALL
80  
81 SQL_SIMPLE_LOG_OFF
82 SQL_SIMPLE_LOG_STD
83 SQL_SIMPLE_LOG_SYS
84 SQL_SIMPLE_LOG_ALL
85  
86 SQL_SIMPLE_RC_SYNTAX
87 SQL_SIMPLE_RC_OK
88 SQL_SIMPLE_RC_ERROR
89 SQL_SIMPLE_RC_EMPTY
90  
91 $VERSION
92 $errstr
93 $err
94 );
95  
96 4 our $VERSION = "2026.101.1";
97  
98 4 our @EXPORT_OK = @EXPORT;
99  
100 4 our %EXPORT_TAGS = ( all => [@EXPORT_OK] );
101  
102 ################################################################################
103 ## literals initialization
104  
105 4 ▶ use constant SQL_SIMPLE_ALIAS_INSERT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
106 4 ▶ use constant SQL_SIMPLE_ALIAS_UPDATE => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
107 4 ▶ use constant SQL_SIMPLE_ALIAS_DELETE => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 4 ▶ use constant SQL_SIMPLE_ALIAS_SELECT => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
109 4 ▶ use constant SQL_SIMPLE_ALIAS_WHERE => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 4 ▶ use constant SQL_SIMPLE_ALIAS_GROUPBY => 32;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 4 ▶ use constant SQL_SIMPLE_ALIAS_ORDERBY => 64;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 4 ▶ use constant SQL_SIMPLE_ALIAS_FQDN => 32768;
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114 4 ▶ use constant SQL_SIMPLE_CURSOR_TOP => 1; # page first
Subroutine BEGIN: called CC=1 SCAR=0.0
115 4 ▶ use constant SQL_SIMPLE_CURSOR_BACK => 2; # page backward
Subroutine BEGIN: called CC=1 SCAR=0.0
116 4 ▶ use constant SQL_SIMPLE_CURSOR_NEXT => 3; # page next
Subroutine BEGIN: called CC=1 SCAR=0.0
117 4 ▶ use constant SQL_SIMPLE_CURSOR_LAST => 4; # page last
Subroutine BEGIN: called CC=1 SCAR=0.0
118 4 ▶ use constant SQL_SIMPLE_CURSOR_RELOAD => 5; # page current
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 4 ▶ use constant SQL_SIMPLE_ORDER_OFF => undef; # order disabled
Subroutine BEGIN: called CC=1 SCAR=0.0
121 4 ▶ use constant SQL_SIMPLE_ORDER_ASC => "ASC"; # order asceding
Subroutine BEGIN: called CC=1 SCAR=0.0
122 4 ▶ use constant SQL_SIMPLE_ORDER_DESC => "DESC"; # order descending
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124 4 ▶ use constant SQL_SIMPLE_CMD_OFF => 0; # sql_save disabled
Subroutine BEGIN: called CC=1 SCAR=0.0
125 4 ▶ use constant SQL_SIMPLE_CMD_ON => 1; # sql_save update
Subroutine BEGIN: called CC=1 SCAR=0.0
126 4 ▶ use constant SQL_SIMPLE_CMD_ALL => 2; # sql_save read/update
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 4 ▶ use constant SQL_SIMPLE_LOG_OFF => 0; # log disabled
Subroutine BEGIN: called CC=1 SCAR=0.0
129 4 ▶ use constant SQL_SIMPLE_LOG_SYS => 1; # log syslog
Subroutine BEGIN: called CC=1 SCAR=0.0
130 4 ▶ use constant SQL_SIMPLE_LOG_STD => 2; # log stderr
Subroutine BEGIN: called CC=1 SCAR=0.0
131 4 ▶ use constant SQL_SIMPLE_LOG_ALL => 3; # log stderr/syslog
Subroutine BEGIN: called CC=1 SCAR=0.0
132  
133 4 ▶ use constant SQL_SIMPLE_RC_SYNTAX => -1; # syntax error
Subroutine BEGIN: called CC=1 SCAR=0.0
134 4 ▶ use constant SQL_SIMPLE_RC_OK => 0; # sql successul
Subroutine BEGIN: called CC=1 SCAR=0.0
135 4 ▶ use constant SQL_SIMPLE_RC_ERROR => 1; # sql error
Subroutine BEGIN: called CC=1 SCAR=0.0
136 4 ▶ use constant SQL_SIMPLE_RC_EMPTY => 2; # sql successul, empty
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138 4 our $SQL_SIMPLE_CURSOR_ORDER =
139 {
140 1 => SQL_SIMPLE_ORDER_ASC, # top
141 2 => SQL_SIMPLE_ORDER_DESC, # last
142 3 => SQL_SIMPLE_ORDER_ASC, # next
143 4 => SQL_SIMPLE_ORDER_DESC, # last
144 5 => SQL_SIMPLE_ORDER_ASC, # reload
145 };
146  
147 ################################################################################
148 ## local environments
149
150 4 our $SQL_SIMPLE_CLASS = "SQL::SimpleOps";
151  
152 4 our %SQL_SIMPLE_TABLE_OF_MSGS =
153 (
154 "001" => { T=>"E", M=>"[%s] Database is missing" },
155 "002" => { T=>"E", M=>"[%s] Server is missing" },
156 "003" => { T=>"E", M=>"[%s] Interface invalid" },
157 "004" => { T=>"S", M=>"[%s] The Database driver is omitted or empty" },
158 "005" => { T=>"E", M=>"[%s] Table is missing or invalid" },
159 "006" => { T=>"E", M=>"[%s] Table invalid, must be single-value or array" },
160 "007" => { T=>"E", M=>"[%s] Fields invalid, must be array" },
161 "008" => { T=>"E", M=>"[%s] Group_by invalid, must be single-value or array" },
162 "009" => { T=>"E", M=>"[%s] Order_by invalid, must be single-value or array-pairs" },
163 "010" => { T=>"E", M=>"[%s] Field '%s' not mapped in table list" },
164 "011" => { T=>"E", M=>"[%s} Stat File error, %s" },
165 "012" => { T=>"I", M=>"[%s] Key not found" },
166 "013" => { T=>"E", M=>"[%s] Cursor is missing or invalid" },
167 "014" => { T=>"E", M=>"[%s] Cursor Key is missing or invalid" },
168 "015" => { T=>"E", M=>"[%s] Cursor Command invalid" },
169 "016" => { T=>"W", M=>"[%s] Key is missing, option 'force' is required" },
170 "017" => { T=>"E", M=>"[%s] Fields is missing" },
171 "018" => { T=>"E", M=>"[%s] Fields Format error, must be hash-pairs or arrayref" },
172 "019" => { T=>"E", M=>"[%s] Interface '%s::%s' missing" },
173 "020" => { T=>"E", M=>"[%s] Where Clause invalid" },
174 "021" => { T=>"E", M=>"[%s] Where invalid, must be single-value or array" },
175 "022" => { T=>"E", M=>"[%s] Database is not open" },
176 "023" => { T=>"E", M=>"[%s] SQL Command is missing" },
177 "024" => { T=>"E", M=>"[%s] Buffer Type invalid, must be hashref, arrayref, scalaref or callback_ref" },
178 "025" => { T=>"S", M=>"[%s] Make Folder error, %s" },
179 "026" => { T=>"S", M=>"[%s] Open File error, %s" },
180 "027" => { T=>"S", M=>"[%s] Values is missing" },
181 "028" => { T=>"E", M=>"[%s] Table/Field Value invalid, must be single-value or array" },
182 "029" => { T=>"E", M=>"[%s] TCP Port invalid, must be numeric and between 1-65536" },
183 "030" => { T=>"E", M=>"[%s] Aliass Table is not a hashref" },
184 "031" => { T=>"E", M=>"[%s] Aliases '%s' invalid, table_cols must be hashref" },
185 "032" => { T=>"E", M=>"[%s] Aliases '%s' invalid, table_cols invalid format" },
186 "033" => { T=>"E", M=>"[%s] Table '%s' already, there can be only one" },
187 "034" => { T=>"E", M=>"[%s] Aliases '%s' invalid, table_name is missing" },
188 "035" => { T=>"S", M=>"[%s] Interface '%s::%s' error, %s" },
189 "036" => { T=>"S", M=>"[%s] Interface '%s::%s' load error" },
190 "037" => { T=>"S", M=>"[%s] Interface '%s::%s' aborted, %s" },
191 "038" => { T=>"E", M=>"[%s] Syslog Facility invalid, must be 'local0' to 'local7'" },
192 "039" => { T=>"E", M=>"[%s] Syslog Service invalid, must contains 'alphanumeric' characters" },
193 "040" => { T=>"E", M=>"[%s] Log File invalid, must contains 'alphanumeric' characters" },
194 "041" => { T=>"E", M=>"[%s] Values Format error, must be arrayref" },
195 "042" => { T=>"E", M=>"[%s] Conflict/Duplicate Format error, must be hashref" },
196 "043" => { T=>"E", M=>"[%s] Limit is missing" },
197 "044" => { T=>"E", M=>"[%s] Buffer hashkey invalid, buffer is not hashref" },
198 "045" => { T=>"E", M=>"[%s] Buffer hashkey not mapped" },
199 "046" => { T=>"E", M=>"[%s] Buffer hashkey must be scalaref or arrayref" },
200 "047" => { T=>"E", M=>"[%s] Buffer arrayref Off not allowed for multiple field list" },
201 "048" => { T=>"E", M=>"[%s] Buffer hashindex must be arrayref" },
202 "049" => { T=>"E", M=>"[%s] Cursor_order invalid" },
203 "050" => { T=>"E", M=>"[%s] Buffer reverse invalid, buffer is not arrayref" },
204 "099" => { T=>"S", M=>"[%s] %s" },
205 );
206  
207 4 our $errstr = ""; # last message
208 4 our $err = 0; # last return code
209  
210 4 1;
211  
212 ################################################################################
213 ## action: create object
214 ## return:
215 ## null falure to loaded, system error
216 ## bless is successful loaded
217  
218 sub new()
219 {
220 3 ▶ my $class = shift; $class = ref($class) || $class || $SQL_SIMPLE_CLASS;
Subroutine new: called CC=53 SCAR=62.3
Pod undocumented
Condition33%2/6
ref $class || $class || $SQL::SimpleOps::SQL_SIMPLE_CLASS
l!l&&r!l&&!r
300
ref $class or $class
l!l&&r!l&&!r
030
MC/DC0%0/3
ref $class || $class || $SQL::SimpleOps::SQL_SIMPLE_CLASS
ref $class $class $SQL::SimpleOps::SQL_SIMPLE_CLASS
Truth table25%1/4
A or B || C
A= ref $classB= $classC= $SQL::SimpleOps::SQL_SIMPLE_CLASS
ABCresult
1XX1
01X1
0011
0000
221 3 my $self = {};
222  
223 3 $self->{argv} = {@_};
224  
225 ## checking for configfile
226 3 ▶ if (defined($self->{argv}{configfile}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"configfile"}) 0 3 3
227 {
228 0 ▶ if (!stat($self->{argv}{configfile}))
Branch: 1 branch
BranchTrueFalseTotal
unless (stat $self->{"argv"}{"configfile"}) 0 0 0
229 {
230 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"011",$self->{argv}{configfile});
231 0 return undef;
232 }
233 0 my $fh = new IO::File($self->{argv}{configfile});
234 0 ▶ if (!defined($fh))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 0 0
235 {
236 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"026",$!);
237 0 return undef;
238 }
239 0 require JSON;
240 0 ▶ my $st; while (!$fh->eof) { $st .= <$fh>; }; undef($fh);
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh->eof) 0 0 0
241 0 my $pt = new JSON(); $self->{argv} = $pt->decode($st); undef($pt);
242 }
243  
244 ## defaults
245 3 ▶ $self->{argv}{interface} = "dbi" if (!defined($self->{argv}{interface}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"interface"} 3 0 3
246 3 ▶ $self->{argv}{quote} = "'" if (!defined($self->{argv}{quote}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"quote"} 3 0 3
247 3 ▶ $self->{argv}{connect} = 1 if (!defined($self->{argv}{connect}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"connect"} 0 3 3
248 3 ▶ $self->{argv}{message_log} = SQL_SIMPLE_LOG_STD if (!defined($self->{argv}{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"message_log"} 1 2 3
249 3 ▶ $self->{argv}{port} = "" if (!defined($self->{argv}{port}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"port"} 3 0 3
250  
251 ## check interfaces
252 3 ▶ if (!grep(/^$self->{argv}{interface}$/i,"dbi"))
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$self->{"argv"}{"interface"}$/i, "dbi") 0 3 3
253 {
254 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"003");
255 0 return undef;
256 }
257  
258 ## check driver
259 3 ▶ if (!defined($self->{argv}{driver}) || $self->{argv}{driver} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"argv"}{"driver"} or $self->{"argv"}{"driver"} eq "") 0 3 3
Condition33%1/3
not defined $self->{"argv"}{"driver"} or $self->{"argv"}{"driver"} eq ""
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $self->{"argv"}{"driver"} or $self->{"argv"}{"driver"} eq ""
not defined $self->{"argv"}{"driver"} $self->{"argv"}{"driver"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $self->{"argv"}{"driver"}B= $self->{"argv"}{"driver"} eq ""
ABresult
1X1
011
000
260 {
261 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"004");
262 0 return undef;
263 }
264  
265 ## check database
266 3 ▶ if (!defined($self->{argv}{db}) || $self->{argv}{db} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"argv"}{"db"} or $self->{"argv"}{"db"} eq "") 0 3 3
Condition33%1/3
not defined $self->{"argv"}{"db"} or $self->{"argv"}{"db"} eq ""
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $self->{"argv"}{"db"} or $self->{"argv"}{"db"} eq ""
not defined $self->{"argv"}{"db"} $self->{"argv"}{"db"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $self->{"argv"}{"db"}B= $self->{"argv"}{"db"} eq ""
ABresult
1X1
011
000
267 {
268 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"001");
269 0 return undef;
270 }
271  
272 ## check aliases table
273 3 ▶ if (defined($self->{argv}{tables}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"tables"}) 1 2 3
274 {
275 1 ▶ if (ref($self->{argv}{tables}) ne "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"argv"}{"tables"} ne "HASH") 0 1 1
276 {
277 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"030");
278 0 return undef;
279 }
280 1 foreach my $table(keys(%{$self->{argv}{tables}}))
281 {
282 3 ▶ if (!defined($self->{argv}{tables}{$table}{name}) || $self->{argv}{tables}{$table}{name} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"argv"}{"tables"}{$table}{"name"} or $self->{"argv"}{"tables"}{$table}{"name"} eq "") 0 3 3
Condition33%1/3
not defined $self->{"argv"}{"tables"}{$table}{"name"} or $self->{"argv"}{"tables"}{$table}{"name"} eq ""
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $self->{"argv"}{"tables"}{$table}{"name"} or $self->{"argv"}{"tables"}{$table}{"name"} eq ""
not defined $self->{"argv"}{"tables"}{$table}{"name"} $self->{"argv"}{"tables"}{$table}{"name"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $self->{"argv"}{"tables"}{$table}{"name"}B= $self->{"argv"}{"tables"}{$table}{"name"} eq ""
ABresult
1X1
011
000
283 {
284 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"034",$table);
285 0 return undef;
286 }
287 3 ▶ if (defined($self->{init}{table_realname}{$self->{argv}{tables}{$table}{name}}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"init"}{"table_realname"}{$self->{"argv"}{"tables"}{$table}{"name"}}) 0 3 3
288 {
289 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"034",$table);
290 0 return undef;
291 }
292 3 ▶ if (defined($self->{argv}{tables}{$self->{argv}{tables}{$table}{name}}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"tables"}{$self->{"argv"}{"tables"}{$table}{"name"}}) 0 3 3
293 {
294 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"034",$table);
295 0 return undef;
296 }
297 3 $self->{init}{table_realname}{$self->{argv}{tables}{$table}{name}} = $table;
298 3 ▶ if (defined($self->{argv}{tables}{$table}{cols}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"tables"}{$table}{"cols"}) 2 1 3
299 {
300 2 ▶ if (ref($self->{argv}{tables}{$table}{cols}) ne "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"argv"}{"tables"}{$table}{"cols"} ne "HASH") 0 2 2
301 {
302 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"031",$table);
303 0 return undef;
304 }
305 2 my $myTable = $self->{argv}{tables}{$table}{name};
306 2 foreach my $field(keys(%{$self->{argv}{tables}{$table}{cols}}))
307 {
308 6 ▶ if ($self->{argv}{tables}{$table}{cols}{$field} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"tables"}{$table}{"cols"}{$field} eq "") 0 6 6
309 {
310 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"032",$field);
311 0 return undef;
312 }
313 6 push(@{$self->{init}{fields_xref}{$field}},[$table,$self->{argv}{tables}{$table}{cols}{$field}]);
314 }
315 }
316 }
317 }
318  
319 ## check syslog options
320 3 ▶ if (defined($self->{argv}{message_syslog_facility}) && !($self->{argv}{message_syslog_facility} =~ /^local[0-7]$/i))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"message_syslog_facility"} and not $self->{"argv"}{"message_syslog_facility"} =~ /^local[0-7]$/i) 0 3 3
Condition33%1/3
defined $self->{"argv"}{"message_syslog_facility"} and not $self->{"argv"}{"message_syslog_facility"} =~ /^local[0-7]$/i
!ll&&!rl&&r
300
MC/DC0%0/2
defined $self->{"argv"}{"message_syslog_facility"} and not $self->{"argv"}{"message_syslog_facility"} =~ /^local[0-7]$/i
defined $self->{"argv"}{"message_syslog_facility"} not $self->{"argv"}{"message_syslog_facility"} =~ /^local[0-7]$/i
Truth table33%1/3
A and not(B)
A= defined $self->{"argv"}{"message_syslog_facility"}B= not $self->{"argv"}{"message_syslog_facility"} =~ /^local[0-7]$/i
ABresult
0X0
100
111
321 {
322 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"038",$self->{argv}{message_syslog_facility});
323 0 return undef;
324 }
325 3 ▶ if (defined($self->{argv}{message_syslog_service}) && ($self->{argv}{message_syslog_service} =~ s/[a-zA-Z0-9\-\_]//g))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"message_syslog_service"} and $self->{"argv"}{"message_syslog_service"} =~ s/[a-zA-Z0-9\-\_]//g) 0 3 3
Condition33%1/3
defined $self->{"argv"}{"message_syslog_service"} and $self->{"argv"}{"message_syslog_service"} =~ s/[a-zA-Z0-9\-\_]//g
!ll&&!rl&&r
300
MC/DC0%0/2
defined $self->{"argv"}{"message_syslog_service"} and $self->{"argv"}{"message_syslog_service"} =~ s/[a-zA-Z0-9\-\_]//g
defined $self->{"argv"}{"message_syslog_service"} $self->{"argv"}{"message_syslog_service"} =~ s/[a-zA-Z0-9\-\_]//g
Truth table33%1/3
A and B
A= defined $self->{"argv"}{"message_syslog_service"}B= $self->{"argv"}{"message_syslog_service"} =~ s/[a-zA-Z0-9\-\_]//g
ABresult
0X0
100
111
326 {
327 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"039",$self->{argv}{message_syslog_service});
328 0 return undef;
329 }
330 3 ▶ if (defined($self->{argv}{sql_save_name}) && ($self->{argv}{sql_save_name} =~ s/[a-zA-Z0-9\-\_]//g))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"sql_save_name"} and $self->{"argv"}{"sql_save_name"} =~ s/[a-zA-Z0-9\-\_]//g) 0 3 3
Condition33%1/3
defined $self->{"argv"}{"sql_save_name"} and $self->{"argv"}{"sql_save_name"} =~ s/[a-zA-Z0-9\-\_]//g
!ll&&!rl&&r
300
MC/DC0%0/2
defined $self->{"argv"}{"sql_save_name"} and $self->{"argv"}{"sql_save_name"} =~ s/[a-zA-Z0-9\-\_]//g
defined $self->{"argv"}{"sql_save_name"} $self->{"argv"}{"sql_save_name"} =~ s/[a-zA-Z0-9\-\_]//g
Truth table33%1/3
A and B
A= defined $self->{"argv"}{"sql_save_name"}B= $self->{"argv"}{"sql_save_name"} =~ s/[a-zA-Z0-9\-\_]//g
ABresult
0X0
100
111
331 {
332 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"040",$self->{argv}{sql_save_name});
333 0 return undef;
334 }
335  
336 ## interface defaults values
337 3 $self->{argv}{interface} = uc($self->{argv}{interface});
338 3 ▶ $self->{argv}{interface_options}{RaiseError} = 0 if (!defined($self->{argv}{interface_options}{RaiseError}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"interface_options"}{"RaiseError"} 3 0 3
339 3 ▶ $self->{argv}{interface_options}{PrintError} = 0 if (!defined($self->{argv}{interface_options}{PrintError}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"interface_options"}{"PrintError"} 3 0 3
340  
341 ## standards plugins
342 3 ▶ if (grep(/^$self->{argv}{driver}$/i,"mysql","mariadb")) {$self->{init}{plugin_id} = "MySQL";}
Branch: 3 branches
BranchTrueFalseTotal
if (grep /^$self->{'argv'}{'driver'}$/i, 'mysql', 'mariadb') { } 0 3 3
elsif (grep /^$self->{'argv'}{'driver'}$/i, 'pg', 'postgres', 'postsql', 'pgsql') { } 0 3 3
elsif (grep /^$self->{'argv'}{'driver'}$/i, 'sqlite', 'sqlite3') { } 3 0 3
343 0 elsif (grep(/^$self->{argv}{driver}$/i,"pg","postgres","postsql","pgsql")) {$self->{init}{plugin_id} = "PG";}
344 3 elsif (grep(/^$self->{argv}{driver}$/i,"sqlite","sqlite3")) {$self->{init}{plugin_id} = "SQLite";}
345 0 else {$self->{init}{plugin_id} = $self->{argv}{driver};}
346  
347 ## load pluging
348 3 my $fn;
349 3 my $plugin = $SQL_SIMPLE_CLASS."::".$self->{argv}{interface}."::".$self->{init}{plugin_id};
350 3 foreach my $dir(@INC)
351 {
352 6 $fn = File::Spec->catdir($dir,split(/::/,$plugin)).".pm";
353 6 ▶ last if (stat($fn));
Branch: 1 branch
BranchTrueFalseTotal
if stat $fn 3 3 6
354 3 $fn = "";
355 }
356 3 ▶ if ($fn eq "")
Branch: 1 branch
BranchTrueFalseTotal
if ($fn eq "") 0 3 3
357 {
358 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"019",$self->{argv}{interface},$self->{init}{plugin_id});
359 0 return undef;
360 }
361 3 eval { require $fn; };
362 3 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
363 {
364 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"035",$self->{argv}{interface},$self->{init}{plugin_id},$@);
365 0 return undef;
366 }
367 3 $self->{init}{plugin_fh} = $plugin->new(sql_simple => $self);
368 3 ▶ if (!defined($self->{init}{plugin_fh}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init"}{"plugin_fh"}) 0 3 3
369 {
370 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"035",$self->{argv}{interface},$self->{init}{plugin_id},$@);
371 0 return undef;
372 }
373  
374 ## test server, the 'test_server' env must be defined on plugin
375 3 ▶ if ($self->{init}{test_server})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"test_server"}) 0 3 3
376 {
377 0 ▶ if ($self->{argv}{server} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"server"} eq "") 0 0 0
378 {
379 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"002");
380 0 return undef;
381 }
382 0 ▶ if ($self->{argv}{port} ne "" && (($self->{argv}{port} =~ /^\D+$/) || ($self->{argv}{port} < 1 || $self->{argv}{port} > 65535)))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"port"} ne "" and $self->{"argv"}{"port"} =~ /^\D+$/ || ($self->{"argv"}{"port"} < 1 || $self->{"argv"}{"port"} > 65535)) 0 0 0
Condition0%0/9
$self->{"argv"}{"port"} ne "" and $self->{"argv"}{"port"} =~ /^\D+$/ || ($self->{"argv"}{"port"} < 1 || $self->{"argv"}{"port"} > 65535)
!ll&&!rl&&r
000
$self->{"argv"}{"port"} =~ /^\D+$/ or ($self->{"argv"}{"port"} < 1 or $self->{"argv"}{"port"} > 65535)
l!l&&r!l&&!r
000
$self->{"argv"}{"port"} < 1 or $self->{"argv"}{"port"} > 65535
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->{"argv"}{"port"} ne "" and $self->{"argv"}{"port"} =~ /^\D+$/ || ($self->{"argv"}{"port"} < 1 || $self->{"argv"}{"port"} > 65535)
$self->{"argv"}{"port"} ne "" $self->{"argv"}{"port"} =~ /^\D+$/ $self->{"argv"}{"port"} < 1 $self->{"argv"}{"port"} > 65535
Truth table0%0/5
A and B or C or D
A= $self->{"argv"}{"port"} ne ""B= $self->{"argv"}{"port"} =~ /^\D+$/C= $self->{"argv"}{"port"} < 1D= $self->{"argv"}{"port"} > 65535
ABCDresult
0XXX0
10000
11XX1
101X1
10011
383 {
384 0 &_setMessage($self,"new",SQL_SIMPLE_RC_SYNTAX,"029");
385 0 return undef;
386 }
387 }
388  
389 ## new object
390 3 my $bless = bless($self,$class);
391 3 ▶ return undef if (!defined($bless));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bless 0 3 3
392  
393 ## my first connect
394 3 ▶ return undef if ($self->{argv}{connect} && $self->Open());
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"argv"}{"connect"} and $self->Open 0 3 3
Condition33%1/3
$self->{"argv"}{"connect"} and $self->Open
!ll&&!rl&&r
300
MC/DC0%0/2
$self->{"argv"}{"connect"} and $self->Open
$self->{"argv"}{"connect"} $self->Open
Truth table33%1/3
A and B
A= $self->{"argv"}{"connect"}B= $self->Open
ABresult
0X0
100
111
395  
396 ## successful
397 3 return $bless;
398 }
399  
400 ################################################################################
401 ## action: open database
402 ## return:
403 ## rc<0 syntax error
404 ## rc=0 successful
405 ## rc>0 sql return code
406  
407 sub Open()
408 {
409 2 ▶ my $self = shift;
Subroutine Open: called CC=4 SCAR=16.0
Pod documented
410  
411 2 $self->_resetSession();
412 2 ▶ if ($self->{init}{plugin_fh}->can('Open') && $self->{init}{plugin_fh}->Open())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("Open") and $self->{"init"}{"plugin_fh"}->Open) 0 2 2
Condition33%1/3
$self->{"init"}{"plugin_fh"}->can("Open") and $self->{"init"}{"plugin_fh"}->Open
!ll&&!rl&&r
020
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("Open") and $self->{"init"}{"plugin_fh"}->Open
$self->{"init"}{"plugin_fh"}->can("Open") $self->{"init"}{"plugin_fh"}->Open
Truth table33%1/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("Open")B= $self->{"init"}{"plugin_fh"}->Open
ABresult
0X0
100
111
413 {
414 0 $self->_setMessage("open",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
415 0 return SQL_SIMPLE_RC_SYNTAX;
416 }
417 2 ▶ if ($self->{argv}{interface} =~ /^dbi$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"interface"} =~ /^dbi$/i) 2 0 2
418 {
419 2 $self->{init}{dbh} = DBI->connect($self->{argv}{dsname}, $self->{argv}{login}, $self->{argv}{password}, \%{$self->{argv}{interface_options}});
420 2 $self->_setMessage("open");
421 2 return $self->getRC();
422 }
423 0 return SQL_SIMPLE_RC_SYNTAX;
424 }
425  
426 ################################################################################
427 ## action: create select command to inject as subquery
428 ## return:
429 ## rc<0 syntax error
430 ## rc=0 returns SQL STRING COMMAND
431 ## rc=1 sql error
432 ## rc=2 successful, no lines selected (no match or empty)
433  
434 sub SelectSubQuery()
435 {
436 4 ▶ my $self = shift;
Subroutine SelectSubQuery: called CC=1 SCAR=0.0
Pod documented
437 4 my $argv = {@_};
438  
439 4 $argv->{subquery} = 1;
440  
441 4 return $self->Select(%{$argv});
442 }
443  
444 ################################################################################
445 ## action: select as fetch command, buffers of lines based cursor
446 ## return:
447 ## rc<0 syntax error
448 ## rc=0 successful
449 ## rc=1 sql error
450 ## rc=2 successful, no lines selected (no match or empty)
451  
452 sub SelectCursor()
453 {
454 17 ▶ my $self = shift;
Subroutine SelectCursor: called CC=10 SCAR=26.0
Pod documented
455 17 my $argv = {@_};
456  
457 17 $self->_resetSession();
458 17 $self->_Dumper("selectcursor",$argv);
459 17 ▶ $self->Open() if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 17 17
460  
461 ## define the command in load
462 17 $self->{work}{command} = SQL_SIMPLE_ALIAS_SELECT;
463  
464 17 ▶ if ($self->{init}{plugin_fh}->can('SelectCursor') && $self->{init}{plugin_fh}->SelectCursor($argv))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("SelectCursor") and $self->{"init"}{"plugin_fh"}->SelectCursor($argv)) 0 17 17
Condition33%1/3
$self->{"init"}{"plugin_fh"}->can("SelectCursor") and $self->{"init"}{"plugin_fh"}->SelectCursor($argv)
!ll&&!rl&&r
1700
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("SelectCursor") and $self->{"init"}{"plugin_fh"}->SelectCursor($argv)
$self->{"init"}{"plugin_fh"}->can("SelectCursor") $self->{"init"}{"plugin_fh"}->SelectCursor($argv)
Truth table33%1/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("SelectCursor")B= $self->{"init"}{"plugin_fh"}->SelectCursor($argv)
ABresult
0X0
100
111
465 {
466 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
467 0 return SQL_SIMPLE_RC_SYNTAX;
468 }
469  
470 17 ▶ my $saved_message_log = $self->_setLogMessage($argv->{message_log}) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 17 17
471 17 ▶ my $saved_quote = $self->_setQuote($argv->{quote}) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 17 17
472 17 ▶ my $saved_sql_save = $self->_setSqlSave($argv->{sql_save}) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 17 17
473  
474 17 my $rc = $self->_SelectCursor(%{$argv});
475  
476 17 ▶ $self->setMessgeLog($saved_message_log) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 17 17
477 17 ▶ $self->_setQuote($saved_quote) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 17 17
478 17 ▶ $self->_setSqlSave($saved_sql_save) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 17 17
479  
480 17 return $rc;
481 }
482  
483 sub _SelectCursor()
484 {
485 17 ▶ my $self = shift;
Subroutine _SelectCursor: called CC=93 SCAR=72.3
486 17 my $argv = {@_};
487  
488 ## validate cursor-key
489 17 ▶ if (!defined($argv->{cursor_key})) { @{$self->{work}{cursor_key}} = []; }
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $argv->{'cursor_key'}) { } 0 17 17
elsif (ref $argv->{'cursor_key'} eq '') { } 9 8 17
elsif (ref $argv->{'cursor_key'} eq 'ARRAY') { } 8 0 8
490 9 elsif (ref($argv->{cursor_key}) eq "") { @{$self->{work}{cursor_key}} = ($argv->{cursor_key}); }
491 8 elsif (ref($argv->{cursor_key}) eq "ARRAY") { @{$self->{work}{cursor_key}} = @{$argv->{cursor_key}}; }
492 else
493 {
494 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"014");
495 0 return SQL_SIMPLE_RC_SYNTAX;
496 }
497  
498 ## validate cursor, must be similar type of cursor-key
499 17 ▶ if (!defined($argv->{cursor})) {}
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $argv->{'cursor'}) { } 17 0 17
elsif (ref $argv->{'cursor'} eq '' and @{$self->{'work'}{'cursor_key'};} == 1) { } 0 0 0
elsif (ref $argv->{'cursor'} eq 'ARRAY' and $self->{'work'}{'cursor_key'} == @{$argv->{'cursor'};} + 0) { } 0 0 0
500 0 ▶ elsif (ref($argv->{cursor}) eq "" && @{$self->{work}{cursor_key}} == 1) {}
Condition0%0/3
ref $argv->{"cursor"} eq "" and @{$self->{"work"}{"cursor_key"};} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
ref $argv->{"cursor"} eq "" and @{$self->{"work"}{"cursor_key"};} == 1
ref $argv->{"cursor"} eq "" @{$self->{"work"}{"cursor_key"};} == 1
Truth table0%0/3
A and B
A= ref $argv->{"cursor"} eq ""B= @{$self->{"work"}{"cursor_key"};} == 1
ABresult
0X0
100
111
501 0 ▶ elsif (ref($argv->{cursor}) eq "ARRAY" && $self->{work}{cursor_key} == @{$argv->{cursor}}+0) {}
Condition0%0/3
ref $argv->{"cursor"} eq "ARRAY" and $self->{"work"}{"cursor_key"} == @{$argv->{"cursor"};} + 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $argv->{"cursor"} eq "ARRAY" and $self->{"work"}{"cursor_key"} == @{$argv->{"cursor"};} + 0
ref $argv->{"cursor"} eq "ARRAY" $self->{"work"}{"cursor_key"} == @{$argv->{"cursor"};} + 0
Truth table0%0/3
A and B
A= ref $argv->{"cursor"} eq "ARRAY"B= $self->{"work"}{"cursor_key"} == @{$argv->{"cursor"};} + 0
ABresult
0X0
100
111
502 else
503 {
504 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"013");
505 0 return SQL_SIMPLE_RC_SYNTAX;
506 }
507  
508 ## enforce cursor as top if missed
509 17 ▶ $argv->{cursor_command} = SQL_SIMPLE_CURSOR_TOP if (!defined($argv->{cursor_command}) || $argv->{cursor_command} eq "");
Branch: 1 branch
BranchTrueFalseTotal
if not defined $argv->{"cursor_command"} or $argv->{"cursor_command"} eq "" 3 14 17
Condition66%2/3
not defined $argv->{"cursor_command"} or $argv->{"cursor_command"} eq ""
l!l&&r!l&&!r
3014
MC/DC50%1/2
not defined $argv->{"cursor_command"} or $argv->{"cursor_command"} eq ""
not defined $argv->{"cursor_command"} $argv->{"cursor_command"} eq ""
Truth table66%2/3
not(A) or B
A= not defined $argv->{"cursor_command"}B= $argv->{"cursor_command"} eq ""
ABresult
1X1
011
000
510  
511 17 ▶ if ($argv->{cursor_command} != SQL_SIMPLE_CURSOR_TOP && $argv->{cursor_command} != SQL_SIMPLE_CURSOR_LAST)
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{"cursor_command"} != 1 and $argv->{"cursor_command"} != 4) 9 8 17
Condition100%3/3
$argv->{"cursor_command"} != 1 and $argv->{"cursor_command"} != 4
!ll&&!rl&&r
629
MC/DC100%2/2
$argv->{"cursor_command"} != 1 and $argv->{"cursor_command"} != 4
$argv->{"cursor_command"} != 1 $argv->{"cursor_command"} != 4
Truth table100%3/3
A and B
A= $argv->{"cursor_command"} != 1B= $argv->{"cursor_command"} != 4
ABresult
0X0
100
111
512 {
513 ## if im not using cursor the cursor_info is required
514 9 ▶ if (!defined($argv->{cursor}) || $argv->{cursor} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $argv->{"cursor"} or $argv->{"cursor"} eq "") 9 0 9
Condition33%1/3
not defined $argv->{"cursor"} or $argv->{"cursor"} eq ""
l!l&&r!l&&!r
900
MC/DC0%0/2
not defined $argv->{"cursor"} or $argv->{"cursor"} eq ""
not defined $argv->{"cursor"} $argv->{"cursor"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $argv->{"cursor"}B= $argv->{"cursor"} eq ""
ABresult
1X1
011
000
515 {
516 9 ▶ if (!defined($argv->{cursor_info}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argv->{"cursor_info"}) 0 9 9
517 {
518 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"013");
519 0 return SQL_SIMPLE_RC_SYNTAX;
520 }
521  
522 ## getting the last and first cursors
523 9 my ($first,$last);
524 9 ▶ if (ref($argv->{cursor_info}) eq "HASH")
Branch: 3 branches
BranchTrueFalseTotal
if (ref $argv->{'cursor_info'} eq 'HASH') { } 9 0 9
elsif (ref $argv->{'cursor_info'} eq 'ARRAY') { } 0 0 0
elsif (ref $argv->{'cursor_info'} eq 'SCALAR') { } 0 0 0
525 {
526 9 ($first,$last) = ($argv->{cursor_info}{first},$argv->{cursor_info}{last});
527 }
528 elsif (ref($argv->{cursor_info}) eq "ARRAY")
529 {
530 0 ($first,$last) = ($argv->{cursor_info}[2],$argv->{cursor_info}[3]);
531 }
532 elsif (ref($argv->{cursor_info}) eq "SCALAR")
533 {
534 ## scalar cursor_info mismatch with multiple keys
535 0 ▶ if (@{$self->{work}{cursor_key}} > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"work"}{"cursor_key"};} > 1) 0 0 0
536 {
537 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"013");
538 0 return SQL_SIMPLE_RC_SYNTAX;
539 }
540 0 my @a=split(" ",$argv->{cursor_info}); ($first,$last) = ($a[2],$a[3]);
541 }
542 else
543 {
544 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"013");
545 0 return SQL_SIMPLE_RC_SYNTAX;
546 }
547  
548 ## adjusting cursor if cursor_key is array
549 9 ▶ if (ref($argv->{cursor_key}) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $argv->{"cursor_key"} eq "ARRAY") 4 5 9
550 {
551 4 ▶ $first = [] if (ref($first) ne "ARRAY");
Branch: 1 branch
BranchTrueFalseTotal
if ref $first ne "ARRAY" 0 4 4
552 4 ▶ $last = [] if (ref($last) ne "ARRAY");
Branch: 1 branch
BranchTrueFalseTotal
if ref $last ne "ARRAY" 0 4 4
553 }
554  
555 ## adjusting cursor
556 9 ▶ if ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_NEXT)
Branch: 3 branches
BranchTrueFalseTotal
if ($argv->{'cursor_command'} == 3) { } 3 6 9
elsif ($argv->{'cursor_command'} == 2) { } 3 3 6
elsif ($argv->{'cursor_command'} == 5) { } 3 0 3
557 {
558 3 $argv->{cursor} = $last;
559 3 ▶ $argv->{cursor_command} = SQL_SIMPLE_CURSOR_TOP if (!defined($last));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last 1 2 3
560 }
561 elsif ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_BACK)
562 {
563 3 $argv->{cursor} = $first;
564 3 ▶ $argv->{cursor_command} = SQL_SIMPLE_CURSOR_LAST if (!defined($first));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 1 2 3
565 }
566 elsif ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_RELOAD)
567 {
568 3 $argv->{cursor} = $first;
569 }
570 }
571
572 ## enforce rerun last command if exists and request is reload
573 9 ▶ if ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_RELOAD)
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{"cursor_command"} == 5) 3 6 9
574 {
575 3 $self->{work}{cursor_command_reload} = 1;
576 3 ▶ if (ref($argv->{cursor_info}) eq "HASH")
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'cursor_info'} eq 'HASH') { } 3 0 3
elsif (ref $argv->{'cursor_info'} eq 'ARRAY') { } 0 0 0
577 {
578 3 ▶ $argv->{cursor_command} = $argv->{cursor_info}{previouscmd} if (defined($argv->{cursor_info}{previouscmd}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"cursor_info"}{"previouscmd"} 0 3 3
579 }
580 elsif (ref($argv->{cursor_info}) eq "ARRAY")
581 {
582 0 ▶ $argv->{cursor_command} = $argv->{cursor_info}[ @{$argv->{cursor_info}}-1 ] if (@{$argv->{cursor_info}} >= 5);
Branch: 1 branch
BranchTrueFalseTotal
if @{$argv->{"cursor_info"};} >= 5 0 0 0
583 }
584 else
585 {
586 0 my @a = split(" ",$argv->{cursor_info});
587 0 ▶ my $b = (@{$self->{work}{cursor_key}} < 2) ? 2 : @{$self->{work}{cursor_key}} * 2;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'work'}{'cursor_key'};} < 2 ? : 0 0 0
588 0 ▶ $argv->{cursor_command} = $a[@a-1] if (@a > (2 + $b));
Branch: 1 branch
BranchTrueFalseTotal
if @a > 2 + $b 0 0 0
589 }
590 }
591 }
592  
593 ## validade where
594 17 ▶ if (defined($argv->{where}) && ref($argv->{where}) ne "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"where"} and ref $argv->{"where"} ne "ARRAY") 0 17 17
Condition66%2/3
defined $argv->{"where"} and ref $argv->{"where"} ne "ARRAY"
!ll&&!rl&&r
1520
MC/DC0%0/2
defined $argv->{"where"} and ref $argv->{"where"} ne "ARRAY"
defined $argv->{"where"} ref $argv->{"where"} ne "ARRAY"
Truth table66%2/3
A and B
A= defined $argv->{"where"}B= ref $argv->{"where"} ne "ARRAY"
ABresult
0X0
100
111
595 {
596 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"021");
597 0 return SQL_SIMPLE_RC_SYNTAX;
598 }
599  
600 ## have order by?
601 17 my @order;
602 17 ▶ if (!defined($argv->{order_by})) {}
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $argv->{'order_by'}) { } 17 0 17
elsif (ref $argv->{'order_by'} eq 'ARRAY') { } 0 0 0
elsif (ref $argv->{'order_by'} eq 'HASH') { } 0 0 0
elsif (ref $argv->{'order_by'} eq '') { } 0 0 0
603 0 elsif (ref($argv->{order_by}) eq "ARRAY") { @order = @{$argv->{order_by}}; }
604 0 elsif (ref($argv->{order_by}) eq "HASH") { @order = ($argv->{order_by}); }
605 0 elsif (ref($argv->{order_by}) eq "") { @order = ($argv->{order_by}); }
606 else
607 {
608 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"009");
609 0 return SQL_SIMPLE_RC_SYNTAX;
610 }
611  
612 ## test the type of cursor and adjust where clause
613 17 ▶ if ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_TOP)
Branch: 4 branches
BranchTrueFalseTotal
if ($argv->{'cursor_command'} == 1) { } 7 10 17
elsif ($argv->{'cursor_command'} == 2) { } 2 8 10
elsif ($argv->{'cursor_command'} == 3 or $argv->{'cursor_command'} == 5) { } 5 3 8
elsif ($argv->{'cursor_command'} == 4) { } 3 0 3
614 {
615 7 my @o;
616 7 ▶ foreach my $key( (ref($argv->{cursor_key}) eq "ARRAY") ? @{$argv->{cursor_key}} : $argv->{cursor_key} )
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 3 4 7
617 {
618 10 push(@o,{$key => SQL_SIMPLE_ORDER_ASC});
619 }
620 7 unshift(@order,@o);
621 }
622 elsif ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_BACK)
623 {
624 2 ▶ my $oper = ($self->{work}{cursor_command_reload}) ? "<=" : "<";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'work'}{'cursor_command_reload'} ? : 0 2 2
625 2 ▶ if (ref($argv->{cursor_key}) ne "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $argv->{'cursor_key'} ne 'ARRAY') { } 1 1 2
626 {
627 1 unshift(@order,{$argv->{cursor_key} => SQL_SIMPLE_ORDER_DESC});
628 1 unshift(@{$argv->{where}}, $argv->{cursor_key} => [ $oper, $argv->{cursor} ]);
629 }
630 else
631 {
632 1 my @w;
633 my @o;
634 1 ▶ for (my $i=0; $i < @{$argv->{cursor_key}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$argv->{"cursor_key"};}) 2 1 3
635 {
636 2 push(@o,{$argv->{cursor_key}[$i] => SQL_SIMPLE_ORDER_DESC});
637 2 my @s;
638 2 ▶ for (my $j=0; $j < $i; $j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $i) 1 2 3
639 {
640 1 push(@s,$argv->{cursor_key}[$j] => $argv->{cursor}[$j]);
641 }
642 2 push(@s,$argv->{cursor_key}[$i] => [ $oper, $argv->{cursor}[$i]]);
643 2 ▶ push(@w,"or") if (@w);
Branch: 1 branch
BranchTrueFalseTotal
if @w 1 1 2
644 2 push(@w,\@s);
645 }
646 1 ▶ push(@{$argv->{where}},(@{$argv->{where}}) ? [\@w] : \@w);
Branch: 1 branch
BranchTrueFalseTotal
@{$argv->{'where'};} ? : 0 1 1
647 1 unshift(@order,@o);
648 }
649 }
650 ▶ elsif ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_NEXT || $argv->{cursor_command} == SQL_SIMPLE_CURSOR_RELOAD)
Condition100%3/3
$argv->{"cursor_command"} == 3 or $argv->{"cursor_command"} == 5
l!l&&r!l&&!r
233
MC/DC100%2/2
$argv->{"cursor_command"} == 3 or $argv->{"cursor_command"} == 5
$argv->{"cursor_command"} == 3 $argv->{"cursor_command"} == 5
Truth table100%3/3
A or B
A= $argv->{"cursor_command"} == 3B= $argv->{"cursor_command"} == 5
ABresult
1X1
011
000
651 {
652 5 ▶ my $oper = ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_RELOAD || $self->{work}{cursor_command_reload}) ? ">=" : ">";
Branch: 1 branch
BranchTrueFalseTotal
$argv->{'cursor_command'} == 5 || $self->{'work'}{'cursor_command_reload'} ? : 3 2 5
Condition66%2/3
$argv->{"cursor_command"} == 5 or $self->{"work"}{"cursor_command_reload"}
l!l&&r!l&&!r
302
MC/DC50%1/2
$argv->{"cursor_command"} == 5 or $self->{"work"}{"cursor_command_reload"}
$argv->{"cursor_command"} == 5 $self->{"work"}{"cursor_command_reload"}
Truth table66%2/3
A or B
A= $argv->{"cursor_command"} == 5B= $self->{"work"}{"cursor_command_reload"}
ABresult
1X1
011
000
653 5 ▶ if (ref($argv->{cursor_key}) ne "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $argv->{'cursor_key'} ne 'ARRAY') { } 2 3 5
654 {
655 2 unshift(@order,{$argv->{cursor_key} => SQL_SIMPLE_ORDER_ASC});
656 2 unshift(@{$argv->{where}}, $argv->{cursor_key} => [ $oper, $argv->{cursor} ]);
657 }
658 else
659 {
660 3 my @w;
661 my @o;
662 3 ▶ for (my $i=0; $i < @{$argv->{cursor_key}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$argv->{"cursor_key"};}) 6 3 9
663 {
664 6 push(@o,{$argv->{cursor_key}[$i] => SQL_SIMPLE_ORDER_ASC});
665 6 my @s;
666 6 ▶ for (my $j=0; $j < $i; $j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $i) 3 6 9
667 {
668 3 push(@s,$argv->{cursor_key}[$j] => $argv->{cursor}[$j]);
669 }
670 6 push(@s,$argv->{cursor_key}[$i] => [ $oper, $argv->{cursor}[$i]]);
671 6 ▶ push(@w,"or") if (@w);
Branch: 1 branch
BranchTrueFalseTotal
if @w 3 3 6
672 6 push(@w,\@s);
673 }
674 3 ▶ push(@{$argv->{where}},(@{$argv->{where}}) ? [\@w] : \@w);
Branch: 1 branch
BranchTrueFalseTotal
@{$argv->{'where'};} ? : 1 2 3
675 3 unshift(@order,@o);
676 }
677 }
678 elsif ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_LAST)
679 {
680 3 my @o;
681 3 ▶ foreach my $key( (ref($argv->{cursor_key}) eq "ARRAY") ? @{$argv->{cursor_key}} : $argv->{cursor_key} )
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 1 2 3
682 {
683 4 push(@o,{$key => SQL_SIMPLE_ORDER_DESC});
684 }
685 3 unshift(@order,@o);
686 }
687 else
688 {
689 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"015");
690 0 return SQL_SIMPLE_RC_SYNTAX;
691 }
692 17 $argv->{order_by} = \@order;
693  
694 ## validate cursor_order option
695 17 ▶ if (!defined($argv->{cursor_order})) { }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $argv->{'cursor_order'}) { } 17 0 17
elsif ($argv->{'cursor_order'} eq 'ASC' or $argv->{'cursor_order'} eq 'DESC') { } 0 0 0
696 ▶ elsif ($argv->{cursor_order} eq SQL_SIMPLE_ORDER_ASC || $argv->{cursor_order} eq SQL_SIMPLE_ORDER_DESC)
Condition0%0/3
$argv->{"cursor_order"} eq "ASC" or $argv->{"cursor_order"} eq "DESC"
l!l&&r!l&&!r
000
MC/DC0%0/2
$argv->{"cursor_order"} eq "ASC" or $argv->{"cursor_order"} eq "DESC"
$argv->{"cursor_order"} eq "ASC" $argv->{"cursor_order"} eq "DESC"
Truth table0%0/3
A or B
A= $argv->{"cursor_order"} eq "ASC"B= $argv->{"cursor_order"} eq "DESC"
ABresult
1X1
011
000
697 {
698 0 $self->{work}{cursor_order} = ($argv->{cursor_order} eq $SQL_SIMPLE_CURSOR_ORDER->{$argv->{cursor_command}})+0;
699 }
700 else
701 {
702 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"049");
703 0 return SQL_SIMPLE_RC_SYNTAX;
704 }
705  
706 ## validate limits
707 17 ▶ if (!defined($argv->{limit}) || $argv->{limit} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $argv->{"limit"} or $argv->{"limit"} eq "") 0 17 17
Condition33%1/3
not defined $argv->{"limit"} or $argv->{"limit"} eq ""
l!l&&r!l&&!r
0017
MC/DC0%0/2
not defined $argv->{"limit"} or $argv->{"limit"} eq ""
not defined $argv->{"limit"} $argv->{"limit"} eq ""
Truth table33%1/3
not(A) or B
A= not defined $argv->{"limit"}B= $argv->{"limit"} eq ""
ABresult
1X1
011
000
708 {
709 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"043");
710 0 return SQL_SIMPLE_RC_SYNTAX;
711 }
712  
713 ## define notfound if not exists
714 17 ▶ $argv->{notfound} = 1 if (!defined($argv->{notfound}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $argv->{"notfound"} 17 0 17
715  
716 ## execute and save cursor info
717 17 ▶ return $self->{init}{cursor}{rc} if ($self->{init}{cursor}{rc} = $self->_Select(%{$argv}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"init"}{"cursor"}{"rc"} = $self->_Select(%{$argv;}) 17 0 17
718  
719 0 $self->{init}{cursor}{lines} = $self->getRows();
720 0 ▶ if (!$self->{init}{cursor}{lines})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"init"}{"cursor"}{"lines"}) 0 0 0
721 {
722 0 $self->{init}{cursor}{first} = [];
723 0 $self->{init}{cursor}{last} = [];
724 }
725  
726 ## return cursor info
727 0 ▶ if (!defined($argv->{cursor_info})) {}
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $argv->{'cursor_info'}) { } 0 0 0
elsif (ref $argv->{'cursor_info'} eq 'HASH') { } 0 0 0
elsif (ref $argv->{'cursor_info'} eq 'ARRAY') { } 0 0 0
elsif (ref $argv->{'cursor_info'} eq 'SCALAR') { } 0 0 0
728 elsif (ref($argv->{cursor_info}) eq "HASH")
729 {
730 0 $argv->{cursor_info}->{rc} = $self->{init}{cursor}{rc};
731 0 $argv->{cursor_info}->{lines} = $self->{init}{cursor}{lines};
732  
733 0 ▶ if ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_BACK || $argv->{cursor_command} == SQL_SIMPLE_CURSOR_LAST)
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{'cursor_command'} == 2 or $argv->{'cursor_command'} == 4) { } 0 0 0
Condition0%0/3
$argv->{"cursor_command"} == 2 or $argv->{"cursor_command"} == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$argv->{"cursor_command"} == 2 or $argv->{"cursor_command"} == 4
$argv->{"cursor_command"} == 2 $argv->{"cursor_command"} == 4
Truth table0%0/3
A or B
A= $argv->{"cursor_command"} == 2B= $argv->{"cursor_command"} == 4
ABresult
1X1
011
000
734 {
735 0 ▶ $argv->{cursor_info}{first} = (ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{last} : $self->{init}{cursor}{last}[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
736 0 ▶ $argv->{cursor_info}{last} = (ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{first} : $self->{init}{cursor}{first}[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
737 }
738 else
739 {
740 0 ▶ $argv->{cursor_info}{first} = (ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{first} :$self->{init}{cursor}{first}[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
741 0 ▶ $argv->{cursor_info}{last} = (ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{last} : $self->{init}{cursor}{last}[0];
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
742 }
743 0 $argv->{cursor_info}{previouscmd} = $argv->{cursor_command};
744 }
745 elsif (ref($argv->{cursor_info}) eq "ARRAY")
746 {
747 0 $argv->{cursor_info} = [];
748 0 push(@{$argv->{cursor_info}},$self->{init}{cursor}{rc},$self->{init}{cursor}{lines});
749 0 ▶ if ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_BACK || $argv->{cursor_command} == SQL_SIMPLE_CURSOR_LAST)
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{'cursor_command'} == 2 or $argv->{'cursor_command'} == 4) { } 0 0 0
Condition0%0/3
$argv->{"cursor_command"} == 2 or $argv->{"cursor_command"} == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$argv->{"cursor_command"} == 2 or $argv->{"cursor_command"} == 4
$argv->{"cursor_command"} == 2 $argv->{"cursor_command"} == 4
Truth table0%0/3
A or B
A= $argv->{"cursor_command"} == 2B= $argv->{"cursor_command"} == 4
ABresult
1X1
011
000
750 {
751 0 ▶ push(@{$argv->{cursor_info}},(ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{last} : $self->{init}{cursor}{last}[0]);
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
752 0 ▶ push(@{$argv->{cursor_info}},(ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{first} : $self->{init}{cursor}{first}[0]);
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
753 }
754 else
755 {
756 0 ▶ push(@{$argv->{cursor_info}},(ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{first} :$self->{init}{cursor}{first}[0]);
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
757 0 ▶ push(@{$argv->{cursor_info}},(ref($argv->{cursor_key}) eq "ARRAY") ? $self->{init}{cursor}{last} : $self->{init}{cursor}{last}[0]);
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
758 }
759 0 push(@{$argv->{cursor_info}},$argv->{cursor_command});
760 }
761 elsif (ref($argv->{cursor_info}) eq "SCALAR")
762 {
763 0 my @a;
764 0 ▶ if ($argv->{cursor_command} == SQL_SIMPLE_CURSOR_BACK || $argv->{cursor_command} == SQL_SIMPLE_CURSOR_LAST)
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{'cursor_command'} == 2 or $argv->{'cursor_command'} == 4) { } 0 0 0
Condition0%0/3
$argv->{"cursor_command"} == 2 or $argv->{"cursor_command"} == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$argv->{"cursor_command"} == 2 or $argv->{"cursor_command"} == 4
$argv->{"cursor_command"} == 2 $argv->{"cursor_command"} == 4
Truth table0%0/3
A or B
A= $argv->{"cursor_command"} == 2B= $argv->{"cursor_command"} == 4
ABresult
1X1
011
000
765 {
766 push(@a,
767 0 ▶ (ref($argv->{cursor_key}) eq "ARRAY") ? join(" ",@{$self->{init}{cursor}{last}}) : $self->{init}{cursor}{last}[0],
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
768 0 ▶ (ref($argv->{cursor_key}) eq "ARRAY") ? join(" ",@{$self->{init}{cursor}{first}}) : $self->{init}{cursor}{first}[0],
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
769 );
770 }
771 else
772 {
773 push(@a,
774 0 ▶ (ref($argv->{cursor_key}) eq "ARRAY") ? join(" ",@{$self->{init}{cursor}{first}}) : $self->{init}{cursor}{first}[0],
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
775 0 ▶ (ref($argv->{cursor_key}) eq "ARRAY") ? join(" ",@{$self->{init}{cursor}{last}}) : $self->{init}{cursor}{last}[0],
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'cursor_key'} eq 'ARRAY' ? : 0 0 0
776 );
777 }
778 0 ${$argv->{cursor_info}} = join(" ",$self->{init}{cursor}{rc},$self->{init}{cursor}{lines},@a,$argv->{cursor_command});
779 }
780 0 return SQL_SIMPLE_RC_OK;
781 }
782  
783 ################################################################################
784 ## action: select command
785 ## return:
786 ## rc<0 syntax error
787 ## rc=0 successful
788 ## rc=1 sql error
789 ## rc=2 no selected found (no match where found)
790  
791 sub Select()
792 {
793 195 ▶ my $self = shift;
Subroutine Select: called CC=13 SCAR=27.4
Pod documented
794 195 my $argv = {@_};
795  
796 195 ▶ $argv->{make_only} = 1 if ($argv->{subquery});
Branch: 1 branch
BranchTrueFalseTotal
if $argv->{"subquery"} 8 187 195
797  
798 195 $self->_resetSession();
799 195 $self->_Dumper("select",$argv);
800 195 ▶ $self->Open() if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 195 195
801  
802 ## define the command in load
803 195 $self->{work}{command} = SQL_SIMPLE_ALIAS_SELECT;
804  
805 195 ▶ if ($self->{init}{plugin_fh}->can('Select') && $self->{init}{plugin_fh}->Select($argv))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("Select") and $self->{"init"}{"plugin_fh"}->Select($argv)) 0 195 195
Condition33%1/3
$self->{"init"}{"plugin_fh"}->can("Select") and $self->{"init"}{"plugin_fh"}->Select($argv)
!ll&&!rl&&r
19500
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("Select") and $self->{"init"}{"plugin_fh"}->Select($argv)
$self->{"init"}{"plugin_fh"}->can("Select") $self->{"init"}{"plugin_fh"}->Select($argv)
Truth table33%1/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("Select")B= $self->{"init"}{"plugin_fh"}->Select($argv)
ABresult
0X0
100
111
806 {
807 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
808 0 return SQL_SIMPLE_RC_SYNTAX;
809 }
810  
811 195 ▶ my $saved_message_log = $self->_setLogMessage($argv->{message_log}) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 195 195
812 195 ▶ my $saved_quote = $self->_setQuote($argv->{quote}) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 195 195
813 195 ▶ my $saved_sql_save = $self->_setSqlSave($argv->{sql_save}) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 1 194 195
814  
815 195 my $rc = $self->_Select(%{$argv});
816  
817 195 ▶ $self->setMessgeLog($saved_message_log) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 195 195
818 195 ▶ $self->_setQuote($saved_quote) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 195 195
819 195 ▶ $self->_setSqlSave($saved_sql_save) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 1 194 195
820  
821 195 ▶ return "\\(". ( ($self->getRC()==0) ? $self->getLastSQL() : "**".$self->getMessage()."**" ) .")" if ($argv->{subquery});
Branch: 2 branches
BranchTrueFalseTotal
if $argv->{"subquery"} 8 187 195
$self->getRC == 0 ? : 8 0 8
822 187 return $rc;
823 }
824  
825 sub _Select()
826 {
827 212 ▶ my $self = shift;
Subroutine _Select: called CC=90 SCAR=52.9
828 212 my $argv = {@_};
829  
830 212 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_checkTablesEntries("select",$argv) != SQL_SIMPLE_RC_OK);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_checkTablesEntries("select", $argv) != 0 0 212 212
831  
832 ## testing buffer options
833 212 ▶ if (!defined($argv->{buffer})){}
Branch: 7 branches
BranchTrueFalseTotal
if (not defined $argv->{'buffer'}) { } 212 0 212
elsif (ref $argv->{'buffer'} eq 'ARRAY') { } 0 0 0
elsif (defined $argv->{'buffer_reverse'}) { } 0 0 0
elsif (ref $argv->{'buffer'} ne 'HASH') { } 0 0 0
elsif (not defined $argv->{'buffer_hashkey'}) { } 0 0 0
elsif (not defined $argv->{'buffer_hashindex'}) { } 0 0 0
elsif (ref $argv->{'buffer_hashindex'} ne 'ARRAY') { } 0 0 0
834 ## buffer array options
835 elsif (ref($argv->{buffer}) eq "ARRAY"){}
836 elsif (defined($argv->{buffer_reverse}))
837 {
838 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"050");
839 0 return SQL_SIMPLE_RC_SYNTAX;
840 }
841 ## others buffers type
842 elsif (ref($argv->{buffer}) ne "HASH"){}
843 ## buffer hash options
844 elsif (!defined($argv->{buffer_hashkey})){}
845 elsif (!defined($argv->{buffer_hashindex})){}
846 elsif (ref($argv->{buffer_hashindex}) ne "ARRAY")
847 {
848 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"048");
849 0 return SQL_SIMPLE_RC_SYNTAX;
850 }
851  
852 ## testing fields
853 212 my @fields_work;
854 my %fields_distinct;
855 212 my %fields_aliases;
856  
857 212 ▶ if (defined($argv->{fields}))
Branch: 2 branches
BranchTrueFalseTotal
if (defined $argv->{'fields'}) { } 199 13 212
elsif (defined $self->{'argv'}{'tables'}) { } 6 7 13
858 {
859 199 my $fields_argv;
860 199 ▶ if (ref($argv->{fields}) eq "ARRAY") { $fields_argv = $argv->{fields}; }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'fields'} eq 'ARRAY') { } 188 11 199
elsif (ref $argv->{'fields'} eq '') { } 11 0 11
861 11 elsif (ref($argv->{fields}) eq "") { $fields_argv = [ $argv->{fields} ]; }
862 else
863 {
864 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"007");
865 0 return SQL_SIMPLE_RC_SYNTAX;
866 }
867 199 ▶ if (@{$fields_argv} != 1 || $fields_argv->[0] ne "*")
Branch: 1 branch
BranchTrueFalseTotal
if (@{$fields_argv;} != 1 or $fields_argv->[0] ne "*") 196 3 199
Condition100%3/3
@{$fields_argv;} != 1 or $fields_argv->[0] ne "*"
l!l&&r!l&&!r
571393
MC/DC100%2/2
@{$fields_argv;} != 1 or $fields_argv->[0] ne "*"
@{$fields_argv;} != 1 $fields_argv->[0] ne "*"
Truth table100%3/3
A or B
A= @{$fields_argv;} != 1B= $fields_argv->[0] ne "*"
ABresult
1X1
011
000
868 {
869 196 ▶ for (my $ix=0; $ix < @{$fields_argv}; $ix++)
Branch: 1 branch
BranchTrueFalseTotal
if ($ix < @{$fields_argv;}) 279 179 458
870 {
871 279 my $field = $fields_argv->[$ix];
872 279 my $distinct;
873 my $alias;
874 279 ▶ if (ref($field) eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 80 199 279
875 {
876 80 $alias = $field;
877 80 ($fields_aliases{$alias}{f},$fields_aliases{$alias}{a}) = %{$field};
878 80 $field = $fields_aliases{$alias}{f};
879 80 $self->{work}{field_alias}{$fields_aliases{$alias}{a}} = $fields_aliases{$alias}{f};
880 80 $self->{work}{field_realname}{$fields_aliases{$alias}{f}} = $fields_aliases{$alias}{a};
881 80 ▶ $self->{work}{field_cols}{$1}{$fields_aliases{$alias}{a}} = $2 if ($fields_aliases{$alias}{f} =~ /^(.*?)\.(.*?)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $fields_aliases{$alias}{"f"} =~ /^(.*?)\.(.*?)$/ 51 29 80
882 }
883 279 ▶ if ($field =~ /^distinct$/i)
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ /^distinct$/i) { } 3 276 279
elsif ($field =~ /^distinct\s+(.*)/i) { } 0 276 276
884 {
885 3 $field = $fields_argv->[++$ix];
886 3 $distinct = 1;
887 }
888 elsif ($field =~ /^distinct\s+(.*)/i)
889 {
890 0 $field = $1;
891 0 $distinct = 1;
892 }
893 279 ▶ if (!($field =~ /^\\/))
Branch: 1 branch
BranchTrueFalseTotal
unless ($field =~ /^\\/) 276 3 279
894 {
895 276 ▶ my $value = ($field =~ /^(.*?)\((.*?)\,(.*)\)/) ? $2 : ($field =~ /^(.*?)\((.*)\)/) ? $2 : $field;
Branch: 2 branches
BranchTrueFalseTotal
$field =~ /^(.*?)\((.*?)\,(.*)\)/ ? : 1 275 276
$field =~ /^(.*?)\((.*)\)/ ? : 18 257 275
896 276 ▶ if ($value =~ /^(.*)\.(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(.*)\.(.*)$/) 129 147 276
897 {
898 129 ▶ if (!grep(/^$1$/,@{$self->{work}{tables_valids}}))
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$1$/, @{$$self{"work"}{"tables_valids"};}) 17 112 129
899 {
900 17 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"010",$field);
901 17 return SQL_SIMPLE_RC_SYNTAX;
902 }
903 }
904 }
905 262 ▶ push(@fields_work,$alias || $field);
Condition66%2/3
$alias || $field
l!l&&r!l&&!r
721900
MC/DC0%0/2
$alias || $field
$alias $field
Truth table66%2/3
A || B
A= $aliasB= $field
ABresult
1X1
011
000
906 262 ▶ $fields_distinct{$field} = 1 if ($distinct);
Branch: 1 branch
BranchTrueFalseTotal
if $distinct 3 259 262
907 }
908 }
909 }
910 elsif (defined($self->{argv}{tables}))
911 {
912 6 ▶ if (@{$self->{work}{tables_inuse}} > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'work'}{'tables_inuse'};} > 1) { } 1 5 6
913 {
914 1 my $any=0;
915 1 foreach my $table(@{$self->{work}{tables_inuse}})
916 {
917 2 my $temp;
918 2 ▶ if (!defined($self->{argv}{tables}{$table}) || !defined($self->{argv}{tables}{$table}{cols}))
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'argv'}{'tables'}{$table} && defined $self->{'argv'}{'tables'}{$table}{'cols'}) { } 2 0 2
Condition33%1/3
defined $self->{'argv'}{'tables'}{$table} && defined $self->{'argv'}{'tables'}{$table}{'cols'}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $self->{'argv'}{'tables'}{$table} && defined $self->{'argv'}{'tables'}{$table}{'cols'}
defined $self->{'argv'}{'tables'}{$table} defined $self->{'argv'}{'tables'}{$table}{'cols'}
Truth table33%1/3
A && B
A= defined $self->{'argv'}{'tables'}{$table}B= defined $self->{'argv'}{'tables'}{$table}{'cols'}
ABresult
0X0
100
111
919 {
920 2 ▶ if (!defined($self->{init}{table_realname}{$table}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init"}{"table_realname"}{$table}) 2 0 2
921 {
922 2 $any=1;
923 2 next;
924 }
925 0 $temp = $self->{init}{table_realname}{$table};
926 }
927 else
928 {
929 0 $temp = $table;
930 }
931 0 foreach my $field(sort(keys(%{$self->{argv}{tables}{$temp}{cols}})))
932 {
933 0 push(@fields_work,$table.".".$field);
934 }
935 }
936 1 ▶ if ($any && @fields_work)
Branch: 1 branch
BranchTrueFalseTotal
if ($any and @fields_work) 0 1 1
Condition33%1/3
$any and @fields_work
!ll&&!rl&&r
010
MC/DC0%0/2
$any and @fields_work
$any @fields_work
Truth table33%1/3
A and B
A= $anyB= @fields_work
ABresult
0X0
100
111
937 {
938 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"010","*");
939 0 return SQL_SIMPLE_RC_SYNTAX;
940 }
941 }
942 else
943 {
944 5 ▶ my $temp = (!defined($self->{init}{table_realname}{$self->{work}{tables_inuse}[0]})) ? $self->{work}{tables_inuse}[0] : $self->{init}{table_realname}{$self->{work}{tables_inuse}[0]};
Branch: 1 branch
BranchTrueFalseTotal
!defined($self->{'init'}{'table_realname'}{$self->{'work'}{'tables_inuse'}[0]}) ? : 3 2 5
945 5 ▶ if (defined($self->{argv}{tables}{$temp}) && defined($self->{argv}{tables}{$temp}{cols}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"tables"}{$temp} and defined $self->{"argv"}{"tables"}{$temp}{"cols"}) 2 3 5
Condition66%2/3
defined $self->{"argv"}{"tables"}{$temp} and defined $self->{"argv"}{"tables"}{$temp}{"cols"}
!ll&&!rl&&r
302
MC/DC50%1/2
defined $self->{"argv"}{"tables"}{$temp} and defined $self->{"argv"}{"tables"}{$temp}{"cols"}
defined $self->{"argv"}{"tables"}{$temp} defined $self->{"argv"}{"tables"}{$temp}{"cols"}
Truth table66%2/3
A and B
A= defined $self->{"argv"}{"tables"}{$temp}B= defined $self->{"argv"}{"tables"}{$temp}{"cols"}
ABresult
0X0
100
111
946 {
947 2 push(@fields_work,sort(keys(%{$self->{argv}{tables}{$temp}{cols}})));
948 }
949 }
950 }
951 ## testing groupby
952 195 my @group_work;
953 195 ▶ if (defined($argv->{group_by}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"group_by"}) 15 180 195
954 {
955 15 ▶ if (ref($argv->{group_by}) eq "") { @group_work = ($argv->{group_by}); }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'group_by'} eq '') { } 0 15 15
elsif (ref $argv->{'group_by'} eq 'ARRAY') { } 15 0 15
956 15 elsif (ref($argv->{group_by}) eq "ARRAY") { push(@group_work,@{$argv->{group_by}}); }
957 else
958 {
959 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"008");
960 0 return SQL_SIMPLE_RC_SYNTAX;
961 }
962 }
963
964 ## testing orderby
965 195 my @order_work;
966 195 ▶ if (defined($argv->{order_by}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"order_by"}) 42 153 195
967 {
968 42 ▶ if (ref($argv->{order_by}) eq "") { @order_work = ($argv->{order_by}); }
Branch: 3 branches
BranchTrueFalseTotal
if (ref $argv->{'order_by'} eq '') { } 2 40 42
elsif (ref $argv->{'order_by'} eq 'HASH') { } 2 38 40
elsif (ref $argv->{'order_by'} eq 'ARRAY') { } 38 0 38
969 2 elsif (ref($argv->{order_by}) eq "HASH") { @order_work = ($argv->{order_by}); }
970 elsif (ref($argv->{order_by}) eq "ARRAY")
971 {
972 38 push(@order_work,@{$argv->{order_by}});
973 }
974 else
975 {
976 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"009");
977 0 return SQL_SIMPLE_RC_SYNTAX;
978 }
979 }
980
981 ## making fields
982 195 ▶ my $middle = ($self->{init}{alias_with_as}) ? " AS " : " ";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'init'}{'alias_with_as'} ? : 0 195 195
983 195 my @fields;
984 195 my $table = $self->{work}{tables_inuse}[0];
985 195 ▶ if (@fields_work)
Branch: 1 branch
BranchTrueFalseTotal
if (@fields_work) { } 181 14 195
986 {
987 181 foreach my $field(@fields_work)
988 {
989 268 my $alias;
990 268 ▶ my $distinct = ($fields_distinct{$field}) ? "DISTINCT " : "";
Branch: 1 branch
BranchTrueFalseTotal
$fields_distinct{$field} ? : 3 265 268
991 ## field is hash?
992 268 ▶ if (defined($fields_aliases{$field}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields_aliases{$field}) 72 196 268
993 {
994 72 $alias = $fields_aliases{$field}{a};
995 72 $field = $fields_aliases{$field}{f};
996 }
997 ## is escape?
998 268 ▶ if ($field =~ /^\\(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^\\(.*)/) 3 265 268
999 {
1000 3 ▶ ($alias) ?
Branch: 1 branch
BranchTrueFalseTotal
$alias ? : 1 2 3
1001 push(@fields,$distinct.$1.$middle.$alias) :
1002 push(@fields,$distinct.$1);
1003 3 next;
1004 }
1005 ## have function?
1006 265 my $field_a;
1007 my $field_b;
1008 265 ▶ if ($field =~ /^(.*?)\((.*?)\,(.*)\)/)
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ /^(.*?)\((.*?)\,(.*)\)/) { } 1 264 265
elsif ($field =~ /^(.*?)\((.*)\)/) { } 18 246 264
1009 {
1010 1 $field_a = $1."(";
1011 1 $field = $2;
1012 1 $field_b = ",".$3.")";
1013 }
1014 elsif ($field =~ /^(.*?)\((.*)\)/)
1015 {
1016 18 $field_a = $1."(";
1017 18 $field = $2;
1018 18 $field_b = ")";
1019 }
1020 else
1021 {
1022 246 $field_a = "";
1023 246 $field_b = "";
1024 }
1025 ## translate field
1026 265 ▶ if ($field =~ /^(.*)\.(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^(.*)\.(.*)$/) { } 112 153 265
1027 {
1028 112 my $realn = $self->_getAliasCols(1,$field,SQL_SIMPLE_ALIAS_SELECT);
1029 112 ▶ my $table = (!defined($self->{init}{table_realname}{$1})) ? $1 : $self->{init}{table_realname}{$1};
Branch: 1 branch
BranchTrueFalseTotal
!defined($self->{'init'}{'table_realname'}{$1}) ? : 102 10 112
1030 112 my $field = $2;
1031 112 ▶ if ($realn =~ /^.*\..*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($realn =~ /^.*\..*$/) { } 88 24 112
1032 {
1033 88 ▶ ($alias) ?
Branch: 2 branches
BranchTrueFalseTotal
$alias ? : 28 60 88
$table . '.' . $field ne $realn ? : 26 34 60
1034 push(@fields,$distinct.$field_a.$realn.$field_b.$middle.$alias) :
1035 ($table.".".$field ne $realn) ?
1036 push(@fields,$distinct.$field_a.$realn.$field_b.$middle.$field) :
1037 push(@fields,$distinct.$field_a.$realn.$field_b);
1038 }
1039 else
1040 {
1041 24 ▶ ($alias) ?
Branch: 2 branches
BranchTrueFalseTotal
$alias ? : 15 9 24
$field ne $realn ? : 4 5 9
1042 push(@fields,$distinct.$field_a.$table.".".$realn.$field_b.$middle.$alias) :
1043 ($field ne $realn) ?
1044 push(@fields,$distinct.$field_a.$table.".".$realn.$field_b.$middle.$field) :
1045 push(@fields,$distinct.$field_a.$table.".".$realn.$field_b);
1046 }
1047 }
1048 else
1049 {
1050 153 ▶ if (@{$self->{work}{tables_inuse}} == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'work'}{'tables_inuse'};} == 1) { } 127 26 153
1051 {
1052 127 my $realn = $self->_getAliasCols(2,$field,SQL_SIMPLE_ALIAS_SELECT);
1053 127 ▶ ($alias) ?
Branch: 2 branches
BranchTrueFalseTotal
$alias ? : 18 109 127
$field ne $realn ? : 58 51 109
1054 push(@fields,$distinct.$field_a.$realn.$field_b.$middle.$alias) :
1055 ($field ne $realn) ?
1056 push(@fields,$distinct.$field_a.$realn.$field_b.$middle.$field) :
1057 push(@fields,$distinct.$field_a.$field.$field_b);
1058 }
1059 else
1060 {
1061 26 ▶ if ($alias)
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) { } 10 16 26
1062 {
1063 10 push(@fields,$distinct.$field_a.$field.$field_b.$middle.$alias);
1064 }
1065 else
1066 {
1067 16 foreach my $table(@{$self->{work}{tables_inuse}})
1068 {
1069 32 my $realn = $self->_getAliasCols(3,$field,SQL_SIMPLE_ALIAS_SELECT);
1070 32 ▶ if ($realn ne $field)
Branch: 1 branch
BranchTrueFalseTotal
if ($realn ne $field) 0 32 32
1071 {
1072 0 $alias = $field;
1073 0 $field = $realn;
1074 0 last;
1075 }
1076 }
1077 16 ▶ ($alias) ?
Branch: 1 branch
BranchTrueFalseTotal
$alias ? : 0 16 16
1078 push(@fields,$distinct.$field_a.$field.$field_b.$middle.$alias):
1079 push(@fields,$distinct.$field_a.$field.$field_b);
1080 }
1081 }
1082 }
1083 }
1084 }
1085 else
1086 {
1087 14 push(@fields,"*");
1088 }
1089  
1090 ## make where
1091 195 my $where;
1092 195 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhere("select",$argv->{where},\$where));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhere("select", $argv->{"where"}, \$where) 0 195 195
1093  
1094 ## make group_by
1095 195 ▶ for (my $i=0; $i < @group_work; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @group_work) 22 195 217
1096 {
1097 22 ▶ $group_work[$i] = ($group_work[$i] =~ /^(.*)\.(.*)$/) ?
Branch: 1 branch
BranchTrueFalseTotal
$group_work[$i] =~ /^(.*)\.(.*)$/ ? : 13 9 22
1098 $self->_getAliasCols(4,$group_work[$i],SQL_SIMPLE_ALIAS_GROUPBY+SQL_SIMPLE_ALIAS_FQDN) :
1099 $self->_getAliasCols(5,$group_work[$i],SQL_SIMPLE_ALIAS_GROUPBY);
1100 }
1101  
1102 ## make having
1103 195 my $having;
1104 195 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhere("select",$argv->{having},\$having));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhere("select", $argv->{"having"}, \$having) 0 195 195
1105  
1106 ## make order
1107 195 my @order;
1108 195 ▶ while (@order_work)
Branch: 1 branch
BranchTrueFalseTotal
if (@order_work) 56 195 251
1109 {
1110 56 my $field = shift(@order_work);
1111 56 ▶ if (ref($field) eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq 'HASH') { } 48 8 56
1112 {
1113 48 foreach my $_id(sort(keys(%{$field})))
1114 {
1115 48 $self->_SelectOrderBy(\@order,$table,$_id,$field->{$_id});
1116 }
1117 }
1118 8 else { $self->_SelectOrderBy(\@order,$table,$field); }
1119 }
1120  
1121 ## make tables
1122 195 my @tables;
1123 195 foreach my $table(@{$self->{work}{tables_inuse}})
1124 {
1125 261 push(@tables,$self->_getAliasTable($table,$argv));
1126 }
1127  
1128 ## build sql command
1129 195 my $sql = "SELECT ".join(", ",@fields)." FROM ".join(", ",@tables);
1130 195 ▶ $sql .= " WHERE ".$where if ($where);
Branch: 1 branch
BranchTrueFalseTotal
if $where 70 125 195
1131 195 ▶ $sql .= " GROUP BY ".join(", ",@group_work) if (@group_work);
Branch: 1 branch
BranchTrueFalseTotal
if @group_work 15 180 195
1132 195 ▶ $sql .= " HAVING ".$having if ($having);
Branch: 1 branch
BranchTrueFalseTotal
if $having 4 191 195
1133 195 ▶ $sql .= " ORDER BY ".join(", ",@order) if (@order);
Branch: 1 branch
BranchTrueFalseTotal
if @order 42 153 195
1134 195 ▶ $sql .= " LIMIT ".$argv->{limit} if (defined($argv->{limit}) && $argv->{limit} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"limit"} and $argv->{"limit"} > 0 16 179 195
Condition100%3/3
defined $argv->{"limit"} and $argv->{"limit"} > 0
!ll&&!rl&&r
178116
MC/DC100%2/2
defined $argv->{"limit"} and $argv->{"limit"} > 0
defined $argv->{"limit"} $argv->{"limit"} > 0
Truth table100%3/3
A and B
A= defined $argv->{"limit"}B= $argv->{"limit"} > 0
ABresult
0X0
100
111
1135  
1136 ## cross check cursor_key v buffer_hashkey
1137 195 $self->{work}{cursor_key_vs_hashkey} = 0;
1138 195 ▶ if (defined($argv->{buffer_hashkey}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"buffer_hashkey"}) 0 195 195
1139 {
1140 0 $self->{work}{buffer_hashkey} = [];
1141 0 ▶ foreach my $key( (ref($argv->{buffer_hashkey}) eq "ARRAY") ? @{$argv->{buffer_hashkey}} : ($argv->{buffer_hashkey}) )
Branch: 1 branch
BranchTrueFalseTotal
ref $argv->{'buffer_hashkey'} eq 'ARRAY' ? : 0 0 0
1142 {
1143 0 push(@{$self->{work}{buffer_hashkey}},$key);
1144 0 ▶ $self->{work}{cursor_key_vs_hashkey}++ if (defined($self->{work}{cursor_key}) && grep(/^$key$/,@{$self->{work}{cursor_key}}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"work"}{"cursor_key"} and grep /^$key$/, @{$$self{"work"}{"cursor_key"};} 0 0 0
Condition0%0/3
defined $self->{"work"}{"cursor_key"} and grep /^$key$/, @{$$self{"work"}{"cursor_key"};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"work"}{"cursor_key"} and grep /^$key$/, @{$$self{"work"}{"cursor_key"};}
defined $self->{"work"}{"cursor_key"} grep /^$key$/, @{$$self{"work"}{"cursor_key"};}
Truth table0%0/3
A and B
A= defined $self->{"work"}{"cursor_key"}B= grep /^$key$/, @{$$self{"work"}{"cursor_key"};}
ABresult
0X0
100
111
1145 }
1146 }
1147  
1148 ## execute
1149 return SQL_SIMPLE_RC_ERROR if ($self->_Call(
1150 command => $sql,
1151 command_type => 0, # (ZERO is read)
1152 buffer => $argv->{buffer},
1153 buffer_options => $argv->{buffer_options},
1154 buffer_hashkey => $argv->{buffer_hashkey},
1155 buffer_arrayref => $argv->{buffer_arrayref},
1156 buffer_hashindex => $argv->{buffer_hashindex},
1157 buffer_reverse => $argv->{buffer_reverse},
1158 buffer_fields => @fields+0,
1159 cursor => $argv->{cursor},
1160 cursor_command => $argv->{cursor_command},
1161 cursor_key => $argv->{cursor_key},
1162 cursor_order => $argv->{cursor_order},
1163 make_only => $argv->{make_only},
1164 flush => $argv->{flush},
1165 sql_save => $argv->{sql_save},
1166 195 ▶ ));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_Call("command", $sql, "command_type", 0, "buffer", $argv->{"buffer"}, "buffer_options", $argv->{"buffer_options"}, "buffer_hashkey", $argv->{"buffer_hashkey"}, "buffer_arrayref", $argv->{"buffer_arrayref"}, "buffer_hashindex", $argv->{"buffer_hashindex"}, "buffer_reverse", $argv->{"buffer_reverse"}, "buffer_fields", @fields + 0, "cursor", $argv->{"cursor"}, "cursor_command", $argv->{"cursor_command"}, "cursor_key", $argv->{"cursor_key"}, "cursor_order", $argv->{"cursor_order"}, "make_only", $argv->{"make_only"}, "flush", $argv->{"flush"}, "sql_save", $argv->{"sql_save"}) 195 0 195
1167 0 ▶ return SQL_SIMPLE_RC_OK if ($self->getRows());
Branch: 1 branch
BranchTrueFalseTotal
if $self->getRows 0 0 0
1168 0 ▶ return SQL_SIMPLE_RC_OK if ($argv->{notfound});
Branch: 1 branch
BranchTrueFalseTotal
if $argv->{"notfound"} 0 0 0
1169  
1170 0 $self->_setMessage("select",SQL_SIMPLE_RC_SYNTAX,"012");
1171 0 return SQL_SIMPLE_RC_EMPTY;
1172 }
1173  
1174 sub _SelectOrderBy()
1175 {
1176 56 ▶ my $self = shift;
Subroutine _SelectOrderBy: called CC=5 SCAR=16.1
1177 56 my $array = shift;
1178 56 my $table = shift;
1179 56 my $field = shift;
1180 56 my $order = shift;
1181  
1182 56 ▶ if ($field =~ /^(.*?)\.(.*?)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^(.*?)\.(.*?)$/) { } 41 15 56
1183 {
1184 41 $field = $self->_getAliasCols(6,$field,SQL_SIMPLE_ALIAS_ORDERBY+SQL_SIMPLE_ALIAS_FQDN);
1185 }
1186 else
1187 {
1188 15 $field = $self->_getAliasCols(7,$field,SQL_SIMPLE_ALIAS_ORDERBY);
1189 }
1190 56 ▶ if ($order)
Branch: 1 branch
BranchTrueFalseTotal
if ($order) 48 8 56
1191 {
1192 48 $order = uc($order);
1193 48 ▶ $field .= " ".(($order eq SQL_SIMPLE_ORDER_ASC) ? 'ASC' : ($order eq SQL_SIMPLE_ORDER_DESC) ? 'DESC' : 'USING '.$order);
Branch: 2 branches
BranchTrueFalseTotal
$order eq 'ASC' ? : 33 15 48
$order eq 'DESC' ? : 15 0 15
1194 }
1195 56 push(@{$array},$field);
1196 }
1197  
1198 ################################################################################
1199 ## action: delete
1200 ## return:
1201 ## rc<0 syntax error
1202 ## rc=0 successful
1203 ## rc=1 sql error
1204 ## rc=2 no selected found (no match where found)
1205  
1206 sub Delete()
1207 {
1208 15 ▶ my $self = shift;
Subroutine Delete: called CC=12 SCAR=27.7
Pod documented
1209 15 my $argv = {@_};
1210  
1211 15 $self->_resetSession();
1212 15 $self->_Dumper("delete",$argv);
1213 15 ▶ $self->Open() if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 2 13 15
1214  
1215 ## define the command in load
1216 15 $self->{work}{command} = SQL_SIMPLE_ALIAS_DELETE;
1217  
1218 15 ▶ if ($self->{init}{plugin_fh}->can('Delete') && $self->{init}{plugin_fh}->Delete($argv))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("Delete") and $self->{"init"}{"plugin_fh"}->Delete($argv)) 0 15 15
Condition33%1/3
$self->{"init"}{"plugin_fh"}->can("Delete") and $self->{"init"}{"plugin_fh"}->Delete($argv)
!ll&&!rl&&r
1500
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("Delete") and $self->{"init"}{"plugin_fh"}->Delete($argv)
$self->{"init"}{"plugin_fh"}->can("Delete") $self->{"init"}{"plugin_fh"}->Delete($argv)
Truth table33%1/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("Delete")B= $self->{"init"}{"plugin_fh"}->Delete($argv)
ABresult
0X0
100
111
1219 {
1220 0 $self->_setMessage("delete",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
1221 0 return SQL_SIMPLE_RC_SYNTAX;
1222 }
1223  
1224 15 ▶ my $saved_commit = $self->_setCommit($argv->{commit}) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 15 15
1225 15 ▶ my $saved_message_log = $self->_setLogMessage($argv->{message_log}) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 15 15
1226 15 ▶ my $saved_quote = $self->_setQuote($argv->{quote}) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 15 15
1227 15 ▶ my $saved_sql_save = $self->_setSqlSave($argv->{sql_save}) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 15 15
1228  
1229 15 my $rc = $self->_Delete(%{$argv});
1230  
1231 15 ▶ $self->_setCommit($saved_commit) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 15 15
1232 15 ▶ $self->setMessgeLog($saved_message_log) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 15 15
1233 15 ▶ $self->_setQuote($saved_quote) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 15 15
1234 15 ▶ $self->_setSqlSave($saved_sql_save) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 15 15
1235  
1236 15 return $rc;
1237 }
1238  
1239 sub _Delete()
1240 {
1241 15 ▶ my $self = shift;
Subroutine _Delete: called CC=10 SCAR=29.8
1242 15 my $argv = {@_};
1243  
1244 15 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_checkTablesEntries("delete",$argv) != SQL_SIMPLE_RC_OK);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_checkTablesEntries("delete", $argv) != 0 0 15 15
1245  
1246 ## make where
1247 15 my $where;
1248 15 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhere("delete",$argv->{where},\$where));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhere("delete", $argv->{"where"}, \$where) 0 15 15
1249 15 ▶ if ((!defined($where) || $where eq "") && !$argv->{force})
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($where) || $where eq "" and not $argv->{"force"}) 0 15 15
Condition66%4/6
!defined($where) || $where eq "" and not $argv->{"force"}
!ll&&!rl&&r
1050
not defined $where or $where eq ""
l!l&&r!l&&!r
5010
MC/DC0%0/3
!defined($where) || $where eq "" and not $argv->{"force"}
not defined $where $where eq "" not $argv->{"force"}
Truth table40%2/5
not(A) or B and not(C)
A= not defined $whereB= $where eq ""C= not $argv->{"force"}
ABCresult
00X0
1X00
0100
1X11
0111
1250 {
1251 0 $self->_setMessage("delete",SQL_SIMPLE_RC_SYNTAX,"016");
1252 0 return SQL_SIMPLE_RC_SYNTAX;
1253 }
1254  
1255 ## build sql command
1256 15 my $sql = "DELETE FROM ".join(", ",@{$self->{work}{tables_inuse}});
1257 15 ▶ $sql .= " WHERE ".$where if ($where);
Branch: 1 branch
BranchTrueFalseTotal
if $where 10 5 15
1258  
1259 return SQL_SIMPLE_RC_ERROR if ($self->_Call(
1260 command => $sql,
1261 command_type => 1, # (NOT_ZERO is update)
1262 buffer => $argv->{buffer},
1263 buffer_options => $argv->{buffer_options},
1264 buffer_hashkey => $argv->{buffer_hashkey},
1265 buffer_arrayref => $argv->{buffer_arrayref},
1266 make_only => $argv->{make_only},
1267 flush => $argv->{flush},
1268 sql_save => $argv->{sql_save},
1269 15 ▶ ));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_Call("command", $sql, "command_type", 1, "buffer", $argv->{"buffer"}, "buffer_options", $argv->{"buffer_options"}, "buffer_hashkey", $argv->{"buffer_hashkey"}, "buffer_arrayref", $argv->{"buffer_arrayref"}, "make_only", $argv->{"make_only"}, "flush", $argv->{"flush"}, "sql_save", $argv->{"sql_save"}) 15 0 15
1270 0 ▶ return SQL_SIMPLE_RC_OK if ($argv->{notfound});
Branch: 1 branch
BranchTrueFalseTotal
if $argv->{"notfound"} 0 0 0
1271 0 ▶ if ($self->getRows() == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getRows == 0) 0 0 0
1272 {
1273 0 $self->_setMessage("delete",SQL_SIMPLE_RC_SYNTAX,"012");
1274 0 return SQL_SIMPLE_RC_EMPTY;
1275 }
1276 0 return SQL_SIMPLE_RC_OK;
1277 }
1278  
1279 ################################################################################
1280 ## action: insert
1281 ## return:
1282 ## rc<0 syntax error
1283 ## rc=0 successful
1284 ## rc=1 sql error
1285 ## rc=2 no selected found (no match where found)
1286  
1287 sub Insert()
1288 {
1289 22 ▶ my $self = shift;
Subroutine Insert: called CC=12 SCAR=28.3
Pod documented
1290 22 my $argv = {@_};
1291  
1292 22 $self->_resetSession();
1293 22 $self->_Dumper("insert",$argv);
1294 22 ▶ $self->Open() if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 22 22
1295  
1296 ## define the command in load
1297 22 $self->{work}{command} = SQL_SIMPLE_ALIAS_INSERT;
1298  
1299 22 ▶ if ($self->{init}{plugin_fh}->can('Insert') && $self->{init}{plugin_fh}->Insert($argv))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("Insert") and $self->{"init"}{"plugin_fh"}->Insert($argv)) 0 22 22
Condition33%1/3
$self->{"init"}{"plugin_fh"}->can("Insert") and $self->{"init"}{"plugin_fh"}->Insert($argv)
!ll&&!rl&&r
2200
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("Insert") and $self->{"init"}{"plugin_fh"}->Insert($argv)
$self->{"init"}{"plugin_fh"}->can("Insert") $self->{"init"}{"plugin_fh"}->Insert($argv)
Truth table33%1/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("Insert")B= $self->{"init"}{"plugin_fh"}->Insert($argv)
ABresult
0X0
100
111
1300 {
1301 0 $self->_setMessage("insert",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
1302 0 return SQL_SIMPLE_RC_SYNTAX;
1303 }
1304  
1305 22 ▶ my $saved_commit = $self->_setCommit($argv->{commit}) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 22 22
1306 22 ▶ my $saved_message_log = $self->_setLogMessage($argv->{message_log}) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 22 22
1307 22 ▶ my $saved_quote = $self->_setQuote($argv->{quote}) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 22 22
1308 22 ▶ my $saved_sql_save = $self->_setSqlSave($argv->{sql_save}) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 22 22
1309  
1310 22 my $rc = $self->_Insert(%{$argv});
1311  
1312 22 ▶ $self->_setCommit($saved_commit) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 22 22
1313 22 ▶ $self->setMessgeLog($saved_message_log) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 22 22
1314 22 ▶ $self->_setQuote($saved_quote) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 22 22
1315 22 ▶ $self->_setSqlSave($saved_sql_save) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 22 22
1316  
1317 22 return $rc;
1318 }
1319  
1320 sub _Insert()
1321 {
1322 22 ▶ my $self = shift;
Subroutine _Insert: called CC=27 SCAR=46.2
1323 22 my $argv = {@_};
1324  
1325 22 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_checkTablesEntries("insert",$argv) != SQL_SIMPLE_RC_OK);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_checkTablesEntries("insert", $argv) != 0 0 22 22
1326  
1327 ## check mandatory options
1328 22 ▶ if (!defined($argv->{fields}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argv->{"fields"}) 0 22 22
1329 {
1330 0 $self->_setMessage("insert",SQL_SIMPLE_RC_SYNTAX,"017");
1331 0 return SQL_SIMPLE_RC_SYNTAX;
1332 }
1333  
1334 ## hash: fields=> { fld => value }
1335 ## array: fields=> [ fld1,fld2 }, values=> [ val1,val2 ]
1336 22 ▶ if (ref($argv->{fields}) eq "HASH") {}
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'fields'} eq 'HASH') { } 11 11 22
elsif (ref $argv->{'fields'} eq 'ARRAY') { } 11 0 11
1337 elsif (ref($argv->{fields}) eq "ARRAY")
1338 {
1339 11 ▶ if (!defined($argv->{values}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argv->{"values"}) 0 11 11
1340 {
1341 0 $self->_setMessage("insert",SQL_SIMPLE_RC_SYNTAX,"027");
1342 0 return SQL_SIMPLE_RC_SYNTAX;
1343 }
1344 11 ▶ if (ref($argv->{values}) ne "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $argv->{"values"} ne "ARRAY") 0 11 11
1345 {
1346 0 $self->_setMessage("insert",SQL_SIMPLE_RC_SYNTAX,"041");
1347 0 return SQL_SIMPLE_RC_SYNTAX;
1348 }
1349 }
1350 else
1351 {
1352 0 $self->_setMessage("insert",SQL_SIMPLE_RC_SYNTAX,"018");
1353 0 return SQL_SIMPLE_RC_SYNTAX;
1354 }
1355  
1356 ## validat conflict option
1357 22 ▶ if (defined($argv->{conflict}) && ref($argv->{conflict}) ne "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"conflict"} and ref $argv->{"conflict"} ne "HASH") 0 22 22
Condition33%1/3
defined $argv->{"conflict"} and ref $argv->{"conflict"} ne "HASH"
!ll&&!rl&&r
2200
MC/DC0%0/2
defined $argv->{"conflict"} and ref $argv->{"conflict"} ne "HASH"
defined $argv->{"conflict"} ref $argv->{"conflict"} ne "HASH"
Truth table33%1/3
A and B
A= defined $argv->{"conflict"}B= ref $argv->{"conflict"} ne "HASH"
ABresult
0X0
100
111
1358 {
1359 0 $self->_setMessage("insert",SQL_SIMPLE_RC_SYNTAX,"042");
1360 0 return SQL_SIMPLE_RC_SYNTAX;
1361 }
1362  
1363 ## making fields
1364 22 my @fields;
1365 my @values;
1366  
1367 ## format: fields => { ... }
1368 22 ▶ if (ref($argv->{fields}) eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $argv->{'fields'} eq 'HASH') { } 11 11 22
1369 {
1370 ## mapping field and value
1371 11 my @value_;
1372 11 foreach my $field(sort(keys(%{$argv->{fields}})))
1373 {
1374 16 push(@fields,$self->_getAliasCols(8,$field,SQL_SIMPLE_ALIAS_INSERT));
1375 16 ▶ push(@value_,(!defined($argv->{fields}{$field})) ? "NULL" : $self->{argv}{quote}.$self->_escapeQuote($argv->{fields}{$field}).$self->{argv}{quote});
Branch: 1 branch
BranchTrueFalseTotal
!defined($argv->{'fields'}{$field}) ? : 3 13 16
1376 }
1377 11 @values = ("(".join(",",@value_).")");
1378 }
1379 ## format: fields => [ ... ]
1380 else
1381 {
1382 ## mapping field
1383 11 foreach my $field(@{$argv->{fields}})
1384 {
1385 16 push(@fields,$self->_getAliasCols(9,$field,SQL_SIMPLE_ALIAS_INSERT));
1386 }
1387 11 my @value_;
1388 11 foreach my $value(@{$argv->{values}})
1389 {
1390 ## format: fields => [ col => val ]
1391 22 ▶ if (ref($value) ne "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value ne 'ARRAY') { } 22 0 22
1392 {
1393 22 ▶ push(@value_,(!defined($value)) ? "NULL" : $self->{argv}{quote}.$self->_escapeQuote($value).$self->{argv}{quote});
Branch: 1 branch
BranchTrueFalseTotal
!defined($value) ? : 6 16 22
1394 }
1395 ## format: fields => [ col => [ val1, ... ] ], field must be 1
1396 else
1397 {
1398 0 my @value2;
1399 0 foreach my $value2(@{$value})
1400 {
1401 0 ▶ push(@value2,(!defined($value2)) ? "NULL" : $self->{argv}{quote}.$self->_escapeQuote($value2).$self->{argv}{quote});
Branch: 1 branch
BranchTrueFalseTotal
!defined($value2) ? : 0 0 0
1402 }
1403 0 push(@values,"(".join(",",@value2).")");
1404 }
1405 }
1406 11 ▶ push(@values, (@fields == 1) ? "(".join("),(",@value_).")" : "(".join(",",@value_).")" ) if (@value_);
Branch: 2 branches
BranchTrueFalseTotal
if @value_ 11 0 11
@fields == 1 ? : 8 3 11
1407 }
1408  
1409 ## build sql
1410 22 my $sql = "INSERT INTO ".join(", ",@{$self->{work}{tables_inuse}})." (".join(",",@fields).") VALUES ".join(",",@values);
1411 22 ▶ if (defined($argv->{conflict}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"conflict"}) 0 22 22
1412 {
1413 0 my @conflict;
1414 0 foreach my $field(sort(keys(%{$argv->{conflict}})))
1415 {
1416 ($argv->{conflict}{$field} =~ /^\\(.*)/) ?
1417 push(@conflict,$self->_getAliasCols(10,$field,SQL_SIMPLE_ALIAS_INSERT)." = ".$1):
1418 0 ▶ push(@conflict,$self->_getAliasCols(11,$field,SQL_SIMPLE_ALIAS_INSERT)." = ".$self->{argv}{quote}.$self->_escapeQuote($argv->{conflict}{$field}).$self->{argv}{quote});
Branch: 1 branch
BranchTrueFalseTotal
$argv->{'conflict'}{$field} =~ /^\\(.*)/ ? : 0 0 0
1419 }
1420 $sql .= ($self->{init}{plugin_id} =~ /^mysql/i || $self->{init}{plugin_id} =~ /^mariadb/i) ?
1421 " ON DUPLICATE KEY UPDATE ".join(", ",@conflict) :
1422 0 ▶ " ON CONFLICT ".(($argv->{conflict_key})?"(".$self->_getAliasCols(12,$argv->{conflict_key},SQL_SIMPLE_ALIAS_INSERT).") ":"")."DO UPDATE SET ".join(", ",@conflict);
Branch: 2 branches
BranchTrueFalseTotal
$self->{'init'}{'plugin_id'} =~ /^mysql/i || $self->{'init'}{'plugin_id'} =~ /^mariadb/i ? : 0 0 0
$argv->{'conflict_key'} ? : 0 0 0
Condition0%0/3
$self->{"init"}{"plugin_id"} =~ /^mysql/i or $self->{"init"}{"plugin_id"} =~ /^mariadb/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"init"}{"plugin_id"} =~ /^mysql/i or $self->{"init"}{"plugin_id"} =~ /^mariadb/i
$self->{"init"}{"plugin_id"} =~ /^mysql/i $self->{"init"}{"plugin_id"} =~ /^mariadb/i
Truth table0%0/3
A or B
A= $self->{"init"}{"plugin_id"} =~ /^mysql/iB= $self->{"init"}{"plugin_id"} =~ /^mariadb/i
ABresult
1X1
011
000
1423 }
1424  
1425 ## execute
1426 return SQL_SIMPLE_RC_ERROR if ($self->_Call(
1427 command => $sql,
1428 command_type => 1, # (NOT_ZERO is update)
1429 buffer => $argv->{buffer},
1430 buffer_options => $argv->{buffer_options},
1431 buffer_hashkey => $argv->{buffer_hashkey},
1432 buffer_arrayref => $argv->{buffer_arrayref},
1433 make_only => $argv->{make_only},
1434 flush => $argv->{flush},
1435 sql_save => $argv->{sql_save},
1436 22 ▶ ));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_Call("command", $sql, "command_type", 1, "buffer", $argv->{"buffer"}, "buffer_options", $argv->{"buffer_options"}, "buffer_hashkey", $argv->{"buffer_hashkey"}, "buffer_arrayref", $argv->{"buffer_arrayref"}, "make_only", $argv->{"make_only"}, "flush", $argv->{"flush"}, "sql_save", $argv->{"sql_save"}) 22 0 22
1437 0 return SQL_SIMPLE_RC_OK;
1438 }
1439  
1440 ################################################################################
1441 ## action: update
1442 ## return:
1443 ## rc<0 syntax error
1444 ## rc=0 successful
1445 ## rc=1 sql error
1446 ## rc=2 no selected found (no match where found)
1447  
1448 sub Update()
1449 {
1450 40 ▶ my $self = shift;
Subroutine Update: called CC=12 SCAR=28.3
Pod documented
1451 40 my $argv = {@_};
1452  
1453 40 $self->_resetSession();
1454 40 $self->_Dumper("update",$argv);
1455 40 ▶ $self->Open() if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 40 40
1456  
1457 ## define the command in load
1458 40 $self->{work}{command} = SQL_SIMPLE_ALIAS_UPDATE;
1459  
1460 40 ▶ if ($self->{init}{plugin_fh}->can('Update') && $self->{init}{plugin_fh}->Update($argv))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("Update") and $self->{"init"}{"plugin_fh"}->Update($argv)) 0 40 40
Condition33%1/3
$self->{"init"}{"plugin_fh"}->can("Update") and $self->{"init"}{"plugin_fh"}->Update($argv)
!ll&&!rl&&r
4000
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("Update") and $self->{"init"}{"plugin_fh"}->Update($argv)
$self->{"init"}{"plugin_fh"}->can("Update") $self->{"init"}{"plugin_fh"}->Update($argv)
Truth table33%1/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("Update")B= $self->{"init"}{"plugin_fh"}->Update($argv)
ABresult
0X0
100
111
1461 {
1462 0 $self->_setMessage("update",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
1463 0 return SQL_SIMPLE_RC_SYNTAX;
1464 }
1465  
1466 40 ▶ my $saved_commit = $self->_setCommit($argv->{commit}) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 40 40
1467 40 ▶ my $saved_message_log = $self->_setLogMessage($argv->{message_log}) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 40 40
1468 40 ▶ my $saved_quote = $self->_setQuote($argv->{quote}) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 40 40
1469 40 ▶ my $saved_sql_save = $self->_setSqlSave($argv->{sql_save}) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 40 40
1470  
1471 40 my $rc = $self->_Update(%{$argv});
1472  
1473 40 ▶ $self->_setCommit($saved_commit) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 40 40
1474 40 ▶ $self->setMessgeLog($saved_message_log) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 40 40
1475 40 ▶ $self->_setQuote($saved_quote) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 40 40
1476 40 ▶ $self->_setSqlSave($saved_sql_save) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 40 40
1477  
1478 40 return $rc;
1479 }
1480  
1481 sub _Update()
1482 {
1483 40 ▶ my $self = shift;
Subroutine _Update: called CC=19 SCAR=33.8
1484 40 my $argv = {@_};
1485  
1486 40 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_checkTablesEntries("update",$argv) != SQL_SIMPLE_RC_OK);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_checkTablesEntries("update", $argv) != 0 0 40 40
1487  
1488 ## check mandatory options
1489 40 ▶ if (!defined($argv->{fields}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argv->{"fields"}) 0 40 40
1490 {
1491 0 $self->_setMessage("update",SQL_SIMPLE_RC_SYNTAX,"017");
1492 0 return SQL_SIMPLE_RC_SYNTAX;
1493 }
1494 40 ▶ if (ref($argv->{fields}) ne "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $argv->{"fields"} ne "HASH") 0 40 40
1495 {
1496 0 $self->_setMessage("update",SQL_SIMPLE_RC_SYNTAX,"018");
1497 0 return SQL_SIMPLE_RC_SYNTAX;
1498 }
1499  
1500 ## make fields
1501 40 my $ident = 0;
1502 40 my @fields;
1503 40 foreach my $field(sort(keys(%{$argv->{fields}})))
1504 {
1505 54 my $realn = $self->_getAliasCols(13,$field,SQL_SIMPLE_ALIAS_UPDATE);
1506 54 ▶ $ident = 1 if ($realn =~ /^.*\..*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $realn =~ /^.*\..*$/ 22 32 54
1507  
1508 54 ▶ if (!defined($argv->{fields}{$field}))
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $argv->{'fields'}{$field}) { } 2 52 54
elsif ($argv->{'fields'}{$field} =~ /^\\(.*)/) { } 1 51 52
1509 {
1510 2 push(@fields,$realn." = NULL");
1511 }
1512 elsif ($argv->{fields}{$field} =~ /^\\(.*)/)
1513 {
1514 1 my $value = $1;
1515 1 push(@fields,$realn." = ".$value);
1516 }
1517 else
1518 {
1519 ## validate functions as arguments
1520 51 $self->_checkFunctions(\$argv->{fields}{$field},SQL_SIMPLE_ALIAS_UPDATE);
1521 51 push(@fields,$realn." = ".$self->{argv}{quote}.$self->_escapeQuote($argv->{fields}{$field}).$self->{argv}{quote});
1522 }
1523 }
1524  
1525 ## make tables
1526 40 my @tables;
1527 40 foreach my $table(@{$self->{work}{tables_inuse}})
1528 {
1529 51 my $_table = $self->_getAliasTable($table,$argv);
1530  
1531 ## remove alias if not required
1532 51 ▶ $_table = $1 if (!$ident && $_table =~ /^(.*?)\s+.*?$/);
Branch: 1 branch
BranchTrueFalseTotal
if not $ident and $_table =~ /^(.*?)\s+.*?$/ 19 32 51
Condition100%3/3
not $ident and $_table =~ /^(.*?)\s+.*?$/
!ll&&!rl&&r
24819
MC/DC100%2/2
not $ident and $_table =~ /^(.*?)\s+.*?$/
not $ident $_table =~ /^(.*?)\s+.*?$/
Truth table100%3/3
not(A) and B
A= not $identB= $_table =~ /^(.*?)\s+.*?$/
ABresult
0X0
100
111
1533  
1534 51 push(@tables,$_table);
1535 }
1536  
1537 ## make where
1538 40 my $where;
1539 40 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhere("update",$argv->{where},\$where));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhere("update", $argv->{"where"}, \$where) 0 40 40
1540 40 ▶ if ((!defined($where) || $where eq "") && !$argv->{force})
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($where) || $where eq "" and not $argv->{"force"}) 0 40 40
Condition66%4/6
!defined($where) || $where eq "" and not $argv->{"force"}
!ll&&!rl&&r
15250
not defined $where or $where eq ""
l!l&&r!l&&!r
25015
MC/DC0%0/3
!defined($where) || $where eq "" and not $argv->{"force"}
not defined $where $where eq "" not $argv->{"force"}
Truth table40%2/5
not(A) or B and not(C)
A= not defined $whereB= $where eq ""C= not $argv->{"force"}
ABCresult
00X0
1X00
0100
1X11
0111
1541 {
1542 0 $self->_setMessage("update",SQL_SIMPLE_RC_SYNTAX,"016");
1543 0 return SQL_SIMPLE_RC_SYNTAX;
1544 }
1545  
1546 ## formata o sql
1547 40 my $sql = "UPDATE ".join(", ",@tables)." SET ".join(", ",@fields);
1548 40 ▶ $sql .= " WHERE ".$where if ($where);
Branch: 1 branch
BranchTrueFalseTotal
if $where 15 25 40
1549  
1550 ## execute
1551 return SQL_SIMPLE_RC_ERROR if ($self->_Call(
1552 command => $sql,
1553 command_type => 1, # (NOT_ZERO is update)
1554 buffer => $argv->{buffer},
1555 buffer_options => $argv->{buffer_options},
1556 buffer_hashkey => $argv->{buffer_hashkey},
1557 buffer_arrayref => $argv->{buffer_arrayref},
1558 make_only => $argv->{make_only},
1559 flush => $argv->{flush},
1560 sql_save => $argv->{sql_save},
1561 40 ▶ ));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_Call("command", $sql, "command_type", 1, "buffer", $argv->{"buffer"}, "buffer_options", $argv->{"buffer_options"}, "buffer_hashkey", $argv->{"buffer_hashkey"}, "buffer_arrayref", $argv->{"buffer_arrayref"}, "make_only", $argv->{"make_only"}, "flush", $argv->{"flush"}, "sql_save", $argv->{"sql_save"}) 40 0 40
1562 0 ▶ return SQL_SIMPLE_RC_OK if ($argv->{notfound});
Branch: 1 branch
BranchTrueFalseTotal
if $argv->{"notfound"} 0 0 0
1563 0 ▶ if ($self->getRows() == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getRows == 0) 0 0 0
1564 {
1565 0 $self->_setMessage("update",SQL_SIMPLE_RC_SYNTAX,"012");
1566 0 return SQL_SIMPLE_RC_EMPTY;
1567 }
1568 0 return SQL_SIMPLE_RC_OK;
1569 }
1570  
1571 ################################################################################
1572 ## action: wait db connect
1573 ## return:
1574 ## rc<0 syntax error
1575 ## rc=0 successful
1576 ## rc>0 sql command error
1577  
1578 sub Wait()
1579 {
1580 0 ▶ my $self = shift;
Subroutine Wait: not called CC=9 SCAR=45.0
Pod undocumented
1581 0 my $argv= {@_};
1582  
1583 0 $self->_Dumper("wait",$argv);
1584  
1585 0 ▶ my $count = 1 if (!defined($argv->{count}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $argv->{"count"} 0 0 0
1586 0 ▶ my $sleep = 5 if (!defined($argv->{interval}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $argv->{"interval"} 0 0 0
1587  
1588 0 ▶ return SQL_SIMPLE_RC_SYNTAX if ($count =~ /^\D+$/);
Branch: 1 branch
BranchTrueFalseTotal
if $count =~ /^\D+$/ 0 0 0
1589 0 ▶ return SQL_SIMPLE_RC_SYNTAX if ($sleep =~ /^\D+$/);
Branch: 1 branch
BranchTrueFalseTotal
if $sleep =~ /^\D+$/ 0 0 0
1590  
1591 0 ▶ while ($count-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($count-- > 0) 0 0 0
1592 {
1593 0 ▶ last if (!$self->Open());
Branch: 1 branch
BranchTrueFalseTotal
unless $self->Open 0 0 0
1594  
1595 0 ▶ sleep($sleep) if ($count && $sleep);
Branch: 1 branch
BranchTrueFalseTotal
if $count and $sleep 0 0 0
Condition0%0/3
$count and $sleep
!ll&&!rl&&r
000
MC/DC0%0/2
$count and $sleep
$count $sleep
Truth table0%0/3
A and B
A= $countB= $sleep
ABresult
0X0
100
111
1596 }
1597 0 return $self->getRC();
1598 }
1599  
1600 ################################################################################
1601 ## action: execute sql command
1602 ## return:
1603 ## rc<0 syntax error
1604 ## rc=0 successful
1605 ## rc>0 sql command error
1606 #
1607 ## callback example:
1608 ## sub myfunc()
1609 ## {
1610 ## my $ref = shift; # input field hash info
1611 ## my $options = shift; # options args
1612 ## return 0; # if ok to continue than return ZERO
1613 ## return 1; # if aboort needed than return NOT_ZERO
1614 ## }
1615  
1616 sub Call()
1617 {
1618 0 ▶ my $self = shift;
Subroutine Call: not called CC=13 SCAR=52.0
Pod documented
1619 0 my $argv = {@_};
1620  
1621 0 $self->_resetSession();
1622 0 $self->_Dumper("call",$argv);
1623 0 ▶ $self->Open() if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 0 0
1624  
1625 ## define the command in load
1626  
1627 0 ▶ if ($self->{init}{plugin_fh}->can('Call') && $self->{init}{plugin_fh}->Call($argv))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("Call") and $self->{"init"}{"plugin_fh"}->Call($argv)) 0 0 0
Condition0%0/3
$self->{"init"}{"plugin_fh"}->can("Call") and $self->{"init"}{"plugin_fh"}->Call($argv)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("Call") and $self->{"init"}{"plugin_fh"}->Call($argv)
$self->{"init"}{"plugin_fh"}->can("Call") $self->{"init"}{"plugin_fh"}->Call($argv)
Truth table0%0/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("Call")B= $self->{"init"}{"plugin_fh"}->Call($argv)
ABresult
0X0
100
111
1628 {
1629 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
1630 0 return SQL_SIMPLE_RC_SYNTAX;
1631 }
1632 0 ▶ if ($argv->{command} eq "")
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{"command"} eq "") 0 0 0
1633 {
1634 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"023");
1635 0 return SQL_SIMPLE_RC_SYNTAX;
1636 }
1637  
1638 0 ▶ my $saved_commit = $self->_setCommit($argv->{commit}) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 0 0
1639 0 ▶ my $saved_message_log = $self->_setLogMessage($argv->{message_log}) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 0 0
1640 0 ▶ my $saved_quote = $self->_setQuote($argv->{quote}) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 0 0
1641 0 ▶ my $saved_sql_save = $self->_setSqlSave($argv->{sql_save}) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 0 0
1642  
1643 0 my $rc = $self->_Call(%{$argv});
1644  
1645 0 ▶ $self->_setCommit($saved_commit) if (defined($argv->{commit}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"commit"} 0 0 0
1646 0 ▶ $self->setMessgeLog($saved_message_log) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 0 0
1647 0 ▶ $self->_setQuote($saved_quote) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 0 0
1648 0 ▶ $self->_setSqlSave($saved_sql_save) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 0 0 0
1649  
1650 0 return $rc;
1651 }
1652  
1653 sub _Call()
1654 {
1655 272 ▶ my $self = shift;
Subroutine _Call: called CC=74 SCAR=84.4
1656 272 my $argv = {@_};
1657  
1658 272 $self->_setLastSQL($argv->{command});
1659  
1660 ## save command (call-sql_save is prior that new-sql_save
1661 272 ▶ if ((defined($argv->{sql_save}) && $argv->{sql_save}) || (defined($self->{argv}{sql_save}) && $self->{argv}{sql_save} && $argv->{command_type}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"sql_save"} and $argv->{"sql_save"} or defined $self->{"argv"}{"sql_save"} and $self->{"argv"}{"sql_save"} and $argv->{"command_type"}) 1 271 272
Condition58%7/12
defined $argv->{"sql_save"} and $argv->{"sql_save"} or defined $self->{"argv"}{"sql_save"} and $self->{"argv"}{"sql_save"} and $argv->{"command_type"}
l!l&&r!l&&!r
10271
defined $argv->{"sql_save"} and $argv->{"sql_save"}
!ll&&!rl&&r
27101
defined $self->{"argv"}{"sql_save"} and $self->{"argv"}{"sql_save"} and $argv->{"command_type"}
!ll&&!rl&&r
27100
defined $self->{"argv"}{"sql_save"} and $self->{"argv"}{"sql_save"}
!ll&&!rl&&r
248230
MC/DC0%0/5
defined $argv->{"sql_save"} and $argv->{"sql_save"} or defined $self->{"argv"}{"sql_save"} and $self->{"argv"}{"sql_save"} and $argv->{"command_type"}
defined $argv->{"sql_save"} $argv->{"sql_save"} defined $self->{"argv"}{"sql_save"} $self->{"argv"}{"sql_save"} $argv->{"command_type"}
Truth table11%1/9
A and B or C and D and E
A= defined $argv->{"sql_save"}B= $argv->{"sql_save"}C= defined $self->{"argv"}{"sql_save"}D= $self->{"argv"}{"sql_save"}E= $argv->{"command_type"}
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
1662 {
1663 1 ▶ return SQL_SIMPLE_RC_ERROR if ($self->Save($argv->{command}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->Save($argv->{"command"}) 0 1 1
1664 }
1665  
1666 ## return if makeonly
1667 272 ▶ return SQL_SIMPLE_RC_ERROR if ($argv->{make_only});
Branch: 1 branch
BranchTrueFalseTotal
if $argv->{"make_only"} 272 0 272
1668  
1669 ## mandatory
1670 0 ▶ if (!defined($self->{init}{dbh}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"init"}{"dbh"}) 0 0 0
1671 {
1672 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"022");
1673 0 return SQL_SIMPLE_RC_SYNTAX;
1674 }
1675 0 ▶ my $flush_buffer = (!defined($argv->{flush}) || $argv->{flush}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!defined($argv->{'flush'}) || $argv->{'flush'} ? : 0 0 0
Condition0%0/3
not defined $argv->{"flush"} or $argv->{"flush"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $argv->{"flush"} or $argv->{"flush"}
not defined $argv->{"flush"} $argv->{"flush"}
Truth table0%0/3
not(A) or B
A= not defined $argv->{"flush"}B= $argv->{"flush"}
ABresult
1X1
011
000
1676 0 my $type;
1677  
1678 ## define type of return data
1679 0 ▶ if (!defined($argv->{buffer})) {}
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $argv->{'buffer'}) { } 0 0 0
elsif (ref $argv->{'buffer'} eq 'HASH') { } 0 0 0
1680 elsif (ref($argv->{buffer}) eq "HASH")
1681 {
1682 0 ▶ if (!defined($argv->{buffer_hashkey})) { $type=1; }
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $argv->{'buffer_hashkey'}) { } 0 0 0
elsif (ref $argv->{'buffer_hashkey'} eq 'ARRAY') { } 0 0 0
elsif (ref $argv->{'buffer_hashkey'} eq 'SCALAR') { } 0 0 0
elsif (ref $argv->{'buffer_hashkey'} eq '') { } 0 0 0
1683 0 ▶ elsif (ref($argv->{buffer_hashkey}) eq "ARRAY") { $type = (@{$argv->{buffer_hashkey}} > 1) ? 6 : 5; }
Branch: 1 branch
BranchTrueFalseTotal
@{$argv->{'buffer_hashkey'};} > 1 ? : 0 0 0
1684 0 elsif (ref($argv->{buffer_hashkey}) eq "SCALAR") { $type=5; }
1685 0 elsif (ref($argv->{buffer_hashkey}) eq "") { $type=5; }
1686 else
1687 {
1688 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"046");
1689 0 return SQL_SIMPLE_RC_SYNTAX;
1690 }
1691 0 ▶ if ($flush_buffer)
Branch: 1 branch
BranchTrueFalseTotal
if ($flush_buffer) 0 0 0
1692 {
1693 0 undef(%{$argv->{buffer}});;
1694 0 ▶ undef(@{$argv->{buffer_hashindex}}) if (defined($argv->{buffer_hashindex}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"buffer_hashindex"} 0 0 0
1695 }
1696 }
1697 else
1698 {
1699 0 ▶ if (ref($argv->{buffer}) eq "ARRAY")
Branch: 3 branches
BranchTrueFalseTotal
if (ref $argv->{'buffer'} eq 'ARRAY') { } 0 0 0
elsif (ref $argv->{'buffer'} eq 'CODE') { } 0 0 0
elsif (ref $argv->{'buffer'} eq 'SCALAR') { } 0 0 0
1700 {
1701 0 ▶ if (defined($argv->{buffer_arrayref}) && !$argv->{buffer_arrayref})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{'buffer_arrayref'} and not $argv->{'buffer_arrayref'}) { } 0 0 0
Condition0%0/3
defined $argv->{"buffer_arrayref"} and not $argv->{"buffer_arrayref"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $argv->{"buffer_arrayref"} and not $argv->{"buffer_arrayref"}
defined $argv->{"buffer_arrayref"} not $argv->{"buffer_arrayref"}
Truth table0%0/3
A and not(B)
A= defined $argv->{"buffer_arrayref"}B= not $argv->{"buffer_arrayref"}
ABresult
0X0
100
111
1702 {
1703 0 ▶ if ($argv->{buffer_fields} != 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{"buffer_fields"} != 1) 0 0 0
1704 {
1705 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"047");
1706 0 return SQL_SIMPLE_RC_SYNTAX;
1707 }
1708 0 $type=7;
1709 }
1710 0 else { $type=2; }
1711 0 ▶ undef(@{$argv->{buffer}}) if ($flush_buffer);
Branch: 1 branch
BranchTrueFalseTotal
if $flush_buffer 0 0 0
1712 }
1713 0 elsif (ref($argv->{buffer}) eq "CODE") { $type=3; }
1714 0 elsif (ref($argv->{buffer}) eq "SCALAR") { $type=4; }
1715 else
1716 {
1717 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"024");
1718 0 return SQL_SIMPLE_RC_SYNTAX;
1719 }
1720  
1721 ## test buffer_hashkey
1722 0 ▶ if (defined($argv->{buffer_hashkey}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"buffer_hashkey"}) 0 0 0
1723 {
1724 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"044");
1725 0 return SQL_SIMPLE_RC_SYNTAX;
1726 }
1727 }
1728  
1729 ## run-PreFetch if exists
1730 0 ▶ if ($self->{init}{plugin_fh}->can('PreFetch') && $self->{init}{plugin_fh}->PreFetch($argv))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init"}{"plugin_fh"}->can("PreFetch") and $self->{"init"}{"plugin_fh"}->PreFetch($argv)) 0 0 0
Condition0%0/3
$self->{"init"}{"plugin_fh"}->can("PreFetch") and $self->{"init"}{"plugin_fh"}->PreFetch($argv)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"init"}{"plugin_fh"}->can("PreFetch") and $self->{"init"}{"plugin_fh"}->PreFetch($argv)
$self->{"init"}{"plugin_fh"}->can("PreFetch") $self->{"init"}{"plugin_fh"}->PreFetch($argv)
Truth table0%0/3
A and B
A= $self->{"init"}{"plugin_fh"}->can("PreFetch")B= $self->{"init"}{"plugin_fh"}->PreFetch($argv)
ABresult
0X0
100
111
1731 {
1732 0 $self->_setMessage("prefetch",SQL_SIMPLE_RC_SYNTAX,"037",$self->{argv}{interface},$self->{argv}{driver},$self->getMessage());
1733 0 return SQL_SIMPLE_RC_SYNTAX;
1734 }
1735  
1736 ## prepare command
1737 0 $argv->{command} =~ s/^\s+|\s+$//;
1738 0 ▶ my $sth = $self->{init}{dbh}->prepare($argv->{command}.( ($argv->{command} =~ /\;$/) ? "":";") );
Branch: 1 branch
BranchTrueFalseTotal
$argv->{'command'} =~ /\;$/ ? : 0 0 0
1739  
1740 ## enforce cursor_order if not defined
1741 0 ▶ $self->{work}{cursor_order} = 1 if (!defined($self->{work}{cursor_order}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"work"}{"cursor_order"} 0 0 0
1742  
1743 ## execute command
1744 0 ▶ if (defined($sth))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sth) { } 0 0 0
1745 {
1746 0 $sth->execute(); # send command to run
1747 0 $self->_setMessage("call"); # save the current status
1748  
1749 ## scan the fields
1750 0 ▶ if (defined($argv->{buffer}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"buffer"}) 0 0 0
1751 {
1752 0 ▶ if ($sth->{NUM_OF_FIELDS})
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->{"NUM_OF_FIELDS"}) 0 0 0
1753 {
1754 0 $self->{init}{cursor}{first} = [];
1755 0 my $ref_saved;
1756 0 ▶ while (my $ref = $sth->fetchrow_hashref())
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = $sth->fetchrow_hashref) 0 0 0
1757 {
1758 ## get first keys elements
1759 0 ▶ if (defined($self->{work}{cursor_key}) && @{$self->{work}{cursor_key}})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"cursor_key"} and @{$self->{"work"}{"cursor_key"};}) 0 0 0
Condition0%0/3
defined $self->{"work"}{"cursor_key"} and @{$self->{"work"}{"cursor_key"};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"work"}{"cursor_key"} and @{$self->{"work"}{"cursor_key"};}
defined $self->{"work"}{"cursor_key"} @{$self->{"work"}{"cursor_key"};}
Truth table0%0/3
A and B
A= defined $self->{"work"}{"cursor_key"}B= @{$self->{"work"}{"cursor_key"};}
ABresult
0X0
100
111
1760 {
1761 0 ▶ if (!@{$self->{init}{cursor}{first}})
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"init"}{"cursor"}{"first"};}) 0 0 0
1762 {
1763 0 foreach my $key(@{$self->{work}{cursor_key}})
1764 {
1765 0 push(@{$self->{init}{cursor}{first}},$ref->{$key});
1766 }
1767 }
1768 }
1769  
1770 ## move data
1771 0 ▶ if ($type == 1) { %{$argv->{buffer}} = %{$ref}; }
Branch: 7 branches
BranchTrueFalseTotal
if ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
elsif ($type == 5) { } 0 0 0
elsif ($type == 6) { } 0 0 0
elsif ($type == 7) { } 0 0 0
1772 elsif ($type == 2)
1773 {
1774 0 ▶ if (!$argv->{buffer_reverse})
Branch: 1 branch
BranchTrueFalseTotal
if (not $argv->{'buffer_reverse'}) { } 0 0 0
1775 {
1776 0 ▶ ($self->{work}{cursor_order}) ? push(@{$argv->{buffer}},$ref): unshift(@{$argv->{buffer}},$ref);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'work'}{'cursor_order'} ? : 0 0 0
1777 }
1778 else
1779 {
1780 0 ▶ ($self->{work}{cursor_order}) ? unshift(@{$argv->{buffer}},$ref): push(@{$argv->{buffer}},$ref);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'work'}{'cursor_order'} ? : 0 0 0
1781 }
1782 }
1783 0 ▶ elsif ($type == 3) { last if (&{$argv->{buffer}}($ref,$argv->{buffer_options})); }
Branch: 1 branch
BranchTrueFalseTotal
if &{$argv->{"buffer"};}($ref, $argv->{"buffer_options"}) 0 0 0
1784 0 elsif ($type == 4) { foreach my $id(keys(%{$ref})) { ${$argv->{buffer}} = $ref->{$id}; }}
1785 elsif ($type == 5)
1786 {
1787 ## save value before remove
1788 0 my $val = $ref->{ $self->{work}{buffer_hashkey}[0] };
1789 0 ▶ $self->{work}{cursor_last_saved}{ $self->{work}{buffer_hashkey}[0] } = $val if ($self->{work}{cursor_key_vs_hashkey});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"work"}{"cursor_key_vs_hashkey"} 0 0 0
1790
1791 ## create hashindex if required
1792 0 ▶ (($self->{work}{cursor_order}) ? push(@{$argv->{buffer_hashindex}},$val) : unshift(@{$argv->{buffer_hashindex}},$val)) if (defined($argv->{buffer_hashindex}));
Branch: 2 branches
BranchTrueFalseTotal
if defined $argv->{"buffer_hashindex"} 0 0 0
$self->{'work'}{'cursor_order'} ? : 0 0 0
1793  
1794 ## remove hashkey from the data buffer
1795 0 delete($ref->{ $self->{work}{buffer_hashkey}[0] });
1796  
1797 ## move data to buffer (hashkey + 1 field data)
1798 0 ▶ if ($argv->{buffer_fields} == 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($argv->{'buffer_fields'} == 2) { } 0 0 0
1799 {
1800 0 my @k = each(%{$ref});
1801 0 $argv->{buffer}->{ $val } = $ref->{$k[0]};
1802 }
1803 else
1804 {
1805 0 $argv->{buffer}->{ $val } = $ref;
1806 }
1807 }
1808 elsif ($type == 6)
1809 {
1810 0 my $addr = $argv->{buffer};
1811 0 my @keys;
1812 0 foreach my $key(@{$argv->{buffer_hashkey}})
1813 {
1814 0 ▶ if (!defined($ref->{$key}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ref->{$key}) 0 0 0
1815 {
1816 0 $self->_setMessage("call",SQL_SIMPLE_RC_SYNTAX,"045");
1817 0 return SQL_SIMPLE_RC_SYNTAX;
1818 }
1819
1820 ## save value before remove if match with cursor_key
1821 0 ▶ $self->{work}{cursor_last_saved}{$key} = $ref->{$key} if ($self->{work}{cursor_key_vs_hashkey});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"work"}{"cursor_key_vs_hashkey"} 0 0 0
1822
1823 ## create temporary hashindex if required
1824 0 ▶ push(@keys,$ref->{$key}) if (defined($argv->{buffer_hashindex}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"buffer_hashindex"} 0 0 0
1825  
1826 ## switch index over index
1827 0 ▶ $addr->{$ref->{$key}} = {} if (!defined($addr->{$ref->{$key}}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$addr{$ref->{$key}} 0 0 0
1828 0 $addr = $addr->{$ref->{$key}};
1829  
1830 ## remove hashkey from the data
1831 0 delete($ref->{$key});
1832 }
1833 ## create hashindex if required
1834 0 ▶ (($self->{work}{cursor_order}) ? push(@{$argv->{buffer_hashindex}},\@keys) : unshift(@{$argv->{buffer_hashindex}},\@keys)) if (defined($argv->{buffer_hashindex}));
Branch: 2 branches
BranchTrueFalseTotal
if defined $argv->{"buffer_hashindex"} 0 0 0
$self->{'work'}{'cursor_order'} ? : 0 0 0
1835  
1836 ## move data to buffer
1837 0 ▶ %{$addr} = (keys(%{$ref}) != 1) ? %{$ref} : $ref->{ each(%{$ref}) };
Branch: 1 branch
BranchTrueFalseTotal
keys %{$ref;} != 1 ? : 0 0 0
1838 }
1839 elsif ($type == 7)
1840 {
1841 0 my @key = keys(%{$ref});
1842 0 ▶ if (!$argv->{buffer_reverse})
Branch: 1 branch
BranchTrueFalseTotal
if (not $argv->{'buffer_reverse'}) { } 0 0 0
1843 {
1844 0 ▶ ($self->{work}{cursor_order}) ? push(@{$argv->{buffer}},$ref->{ $key[0] }) : unshift(@{$argv->{buffer}},$ref->{ $key[0] });
Branch: 1 branch
BranchTrueFalseTotal
$self->{'work'}{'cursor_order'} ? : 0 0 0
1845 }
1846 else
1847 {
1848 0 ▶ ($self->{work}{cursor_order}) ? unshift(@{$argv->{buffer}},$ref->{ $key[0] }) : push(@{$argv->{buffer}},$ref->{ $key[0] });
Branch: 1 branch
BranchTrueFalseTotal
$self->{'work'}{'cursor_order'} ? : 0 0 0
1849 }
1850 }
1851 0 $ref_saved = $ref;
1852 }
1853  
1854 ## get last keys elements
1855 0 ▶ if ($ref_saved && defined($self->{work}{cursor_key}) && @{$self->{work}{cursor_key}})
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_saved and defined $self->{"work"}{"cursor_key"} and @{$self->{"work"}{"cursor_key"};}) 0 0 0
Condition0%0/6
$ref_saved and defined $self->{"work"}{"cursor_key"} and @{$self->{"work"}{"cursor_key"};}
!ll&&!rl&&r
000
$ref_saved and defined $self->{"work"}{"cursor_key"}
!ll&&!rl&&r
000
MC/DC0%0/3
$ref_saved and defined $self->{"work"}{"cursor_key"} and @{$self->{"work"}{"cursor_key"};}
$ref_saved defined $self->{"work"}{"cursor_key"} @{$self->{"work"}{"cursor_key"};}
Truth table0%0/4
A and B and C
A= $ref_savedB= defined $self->{"work"}{"cursor_key"}C= @{$self->{"work"}{"cursor_key"};}
ABCresult
0XX0
10X0
1100
1111
1856 {
1857 0 $self->{init}{cursor}{last} = [];
1858 0 foreach my $key(@{$self->{work}{cursor_key}})
1859 {
1860 0 ▶ push(@{$self->{init}{cursor}{last}},(defined($ref_saved->{$key})) ? $ref_saved->{$key} : $self->{work}{cursor_last_saved}{$key});
Branch: 1 branch
BranchTrueFalseTotal
defined $ref_saved->{$key} ? : 0 0 0
1861 }
1862 }
1863 }
1864 }
1865 0 $self->{init}{rows} = $sth->rows(); # get number of extracted lines
1866  
1867 ## close and commit (if need)
1868 0 $sth->finish();
1869 }
1870 else
1871 {
1872 0 $self->_setMessage("call");
1873 }
1874 0 undef($sth);
1875  
1876 ## force commit if required
1877 0 ▶ $self->_Commit(%{$argv}) if ($self->{argv}->{commit} && $argv->{command_type});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"argv"}{"commit"} and $argv->{"command_type"} 0 0 0
Condition0%0/3
$self->{"argv"}{"commit"} and $argv->{"command_type"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"argv"}{"commit"} and $argv->{"command_type"}
$self->{"argv"}{"commit"} $argv->{"command_type"}
Truth table0%0/3
A and B
A= $self->{"argv"}{"commit"}B= $argv->{"command_type"}
ABresult
0X0
100
111
1878 0 return $self->getRC();
1879 }
1880  
1881 ################################################################################
1882 ## action: commit command
1883 ## return:
1884 ## rc=0 successful
1885 ## rc>0 sql command error
1886  
1887 sub Commit()
1888 {
1889 0 ▶ my $self = shift;
Subroutine Commit: not called CC=2 SCAR=17.9
Pod undocumented
1890 0 my $argv = {@_};
1891  
1892 0 $self->_resetSession();
1893 0 $self->_Dumper("commit",$argv);
1894  
1895 0 ▶ return SQL_SIMPLE_RC_OK if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 0 0
1896 0 return $self->_Commit(%{$argv});
1897 }
1898  
1899 sub _Commit()
1900 {
1901 0 ▶ my $self = shift;
Subroutine _Commit: not called CC=1 SCAR=6.9
1902 0 my $argv = {@_};
1903  
1904 return $self->_Call(
1905 command => "commit",
1906 command_type => 0, # (ZERO to eliminate the LOOP)
1907 make_only => $argv->{make_only},
1908 flush => $argv->{flush},
1909 sql_save => $argv->{sql_save},
1910 0 );
1911 }
1912  
1913 ################################################################################
1914 ## action: disconnect database
1915 ## return:
1916 ## rc=0 successful
1917 ## rc>0 sql command error
1918  
1919 sub Close()
1920 {
1921 2 ▶ my $self = shift;
Subroutine Close: called CC=2 SCAR=7.0
Pod undocumented
1922  
1923 2 ▶ return SQL_SIMPLE_RC_OK if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 2 2
1924  
1925 2 my $rc = $self->{init}{dbh}->disconnect();
1926  
1927 2 $self->_setMessage("close");
1928  
1929 2 undef($self->{init}{dbh});
1930  
1931 2 return $self->getRC();
1932 }
1933  
1934 ##############################################################################
1935 ## action: save the current sql command
1936 ## return:
1937 ## rc=0, successful
1938 ## rc=1, system error (mkdir/openfile)
1939  
1940 sub Save()
1941 {
1942 1 ▶ my $self = shift;
Subroutine Save: called CC=13 SCAR=31.0
Pod undocumented
1943 1 my @sqls = @_;
1944  
1945 1 $self->_Dumper("save",\@sqls);
1946 1 ▶ $self->{init}{sql_save_ix} = 0 if (!defined($self->{init}{sql_save_ix}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"sql_save_ix"} 1 0 1
1947 1 ▶ $self->{init}{sql_save_name} = "sql" if (!defined($self->{init}{sql_save_name}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"sql_save_name"} 1 0 1
1948 $self->{init}{sql_save_dir} =
1949 (defined($self->{argv}{sql_save_dir})) ? $self->{argv}{sql_save_dir} :
1950 ($^O ne 'MSWin32') ? File::Spec->catdir("","var","spool","sql") :
1951 1 ▶ File::Spec->catdir("","windows","temp") if (!defined($self->{init}{sql_save_dir}));
Branch: 3 branches
BranchTrueFalseTotal
unless defined $self->{"init"}{"sql_save_dir"} 1 0 1
defined $self->{'argv'}{'sql_save_dir'} ? : 1 0 1
$^O ne 'MSWin32' ? : 0 0 0
1952  
1953 1 require Date::Calc;
1954 1 require File::Path;
1955 1 require IO::File;
1956  
1957 1 my $today = sprintf("%04s%02s%02s",Date::Calc::Today());
1958 my $path = ($self->{argv}{sql_save_bydate}) ?
1959 File::Spec->catdir($self->{init}{sql_save_dir},substr($today,0,4),substr($today,0,6),$today) :
1960 1 ▶ $self->{init}{sql_save_dir};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'argv'}{'sql_save_bydate'} ? : 1 0 1
1961  
1962 1 ▶ if (!stat($path))
Branch: 1 branch
BranchTrueFalseTotal
unless (stat $path) 1 0 1
1963 {
1964 1 eval { &File::Path::mkpath($path); };
1965 1 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
1966 {
1967 0 $self->_setMessage("save",SQL_SIMPLE_RC_ERROR,"025",$@);
1968 0 ▶ return ($self->{argv}{sql_save_ignore}) ? SQL_SIMPLE_RC_OK : SQL_SIMPLE_RC_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'argv'}{'sql_save_ignore'} ? : 0 0 0
1969 }
1970 }
1971  
1972 1 ▶ $self->{init}{sql_save_logfile} = File::Spec->catpath("", $path,$self->{init}{sql_save_name}.".".($self->{argv}{db}||"public").".".$today.".".$$.".".(++$self->{init}{sql_save_ix}));
Condition50%1/2
$self->{'argv'}{'db'} || 'public'
l!l
10
MC/DC0%0/1
$self->{'argv'}{'db'} || 'public'
$self->{'argv'}{'db'}
Truth table50%1/2
A
A= $self->{'argv'}{'db'}
Aresult
11
00
1973 1 my $fh = IO::File->new(">".$self->{init}{sql_save_logfile});
1974 1 ▶ if (!defined($fh))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fh) 0 1 1
1975 {
1976 0 $self->_setMessage("save",SQL_SIMPLE_RC_ERROR,"026",$!);
1977 0 ▶ return ($self->{argv}{sql_save_ignore}) ? SQL_SIMPLE_RC_OK : SQL_SIMPLE_RC_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'argv'}{'sql_save_ignore'} ? : 0 0 0
1978 }
1979  
1980 1 print $fh join("\n",@sqls),"\n";
1981 1 close($fh);
1982 1 undef($fh);
1983 1 return SQL_SIMPLE_RC_OK;
1984 }
1985  
1986 ################################################################################
1987 ## action: where clause formater, used by: select, insert, delete, update
1988 ## return:
1989 ## rc<0 syntax error
1990 ## rc=0 successful
1991  
1992 sub getWhere()
1993 {
1994  
1995 47 ▶ my $self = shift;
Subroutine getWhere: called CC=3 SCAR=11.2
Pod documented
1996 47 my $argv = {@_};
1997  
1998 47 $self->{work}{tables_inuse} = [];
1999 47 ▶ if (ref($argv->{table}) eq "ARRAY"){ push(@{$self->{work}{tables_inuse}},@{$argv->{table}}); }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'table'} eq 'ARRAY') { } 9 38 47
elsif (ref $argv->{'table'} eq '') { } 38 0 38
2000 38 elsif (ref($argv->{table}) eq "") { push(@{$self->{work}{tables_inuse}},$argv->{table}); }
2001 else
2002 {
2003 0 $self->_setMessage("getWhere",SQL_SIMPLE_RC_SYNTAX,"006");
2004 0 return SQL_SIMPLE_RC_SYNTAX;
2005 }
2006 47 return $self->_getWhere("where",$argv->{where},$argv->{buffer});
2007 }
2008  
2009 sub _getWhere()
2010 {
2011 492 ▶ my $self = shift;
Subroutine _getWhere: called CC=3 SCAR=11.0
2012 492 my $command = shift;
2013 492 my $where = shift;
2014 492 my $buffer = shift;
2015  
2016 ## return dummy where
2017 492 ▶ return SQL_SIMPLE_RC_OK if (!$where);
Branch: 1 branch
BranchTrueFalseTotal
unless $where 346 146 492
2018  
2019 ## format where
2020 146 my @where_local;
2021 146 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhereRecursive($command,0,$where,\@where_local));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhereRecursive($command, 0, $where, \@where_local) 0 146 146
2022  
2023 ## return the where clause
2024 146 ${$buffer} = join(" ",@where_local);
2025 146 return SQL_SIMPLE_RC_OK;
2026 }
2027  
2028 sub _getWhereRecursive()
2029 {
2030 174 ▶ my $self = shift;
Subroutine _getWhereRecursive: called CC=95 SCAR=52.1
2031 174 my $command = shift;
2032 174 my $level = shift;
2033 174 my $where = shift;
2034 174 my $buffer = shift;
2035  
2036 ## return error if argvs is empty, format error
2037 174 ▶ if ($where eq "")
Branch: 1 branch
BranchTrueFalseTotal
if ($where eq "") 0 174 174
2038 {
2039 0 $self->_setMessage($command,SQL_SIMPLE_RC_SYNTAX,"020");
2040 0 return SQL_SIMPLE_RC_SYNTAX;
2041 }
2042 174 ▶ if (ref($where) eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where eq "") 0 174 174
2043 {
2044 0 push(@{$buffer},$where);
2045 0 return 0;
2046 }
2047 ## return error if value1 is not array or value type
2048 174 ▶ if (ref($where) ne "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where ne "ARRAY") 0 174 174
2049 {
2050 0 $self->_setMessage($command,SQL_SIMPLE_RC_SYNTAX,"021");
2051 0 return SQL_SIMPLE_RC_SYNTAX;
2052 }
2053 ## format where
2054 174 my @where_tmp;
2055 174 my $oper_pend = 0;
2056 174 my $oper_text;
2057  
2058 174 ▶ for (my $ix=0; $ix < @{$where};)
Branch: 1 branch
BranchTrueFalseTotal
if ($ix < @{$where;}) 253 173 426
2059 {
2060 253 ▶ undef(@where_tmp) if (@where_tmp && join('',@where_tmp) eq '');
Branch: 1 branch
BranchTrueFalseTotal
if @where_tmp and join("", @where_tmp) eq "" 0 253 253
Condition66%2/3
@where_tmp and join("", @where_tmp) eq ""
!ll&&!rl&&r
174790
MC/DC0%0/2
@where_tmp and join("", @where_tmp) eq ""
@where_tmp join("", @where_tmp) eq ""
Truth table66%2/3
A and B
A= @where_tmpB= join("", @where_tmp) eq ""
ABresult
0X0
100
111
2061  
2062 ###############################################################
2063 ## value1
2064  
2065 253 my $value1 = $where->[$ix++];
2066  
2067 253 ▶ if (ref($value1) ne "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value1 ne "") 28 225 253
2068 {
2069 28 my @where_aux;
2070 28 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhereRecursive($command,$level+1,$value1,\@where_aux));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhereRecursive($command, $level + 1, $value1, \@where_aux) 0 28 28
2071  
2072 ## append if have valid clauses
2073 28 ▶ if (@where_aux)
Branch: 1 branch
BranchTrueFalseTotal
if (@where_aux) 28 0 28
2074 {
2075 ## valida se requer AND/OR
2076 28 ▶ push(@where_tmp,$oper_text||"AND") if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 15 13 28
Condition80%4/5
$oper_pend and @where_tmp
!ll&&!rl&&r
13015
$oper_text || 'AND'
l!l
141
MC/DC50%1/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
MC/DC100%1/1
$oper_text || 'AND'
$oper_text
Truth table66%2/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
Truth table100%2/2
A
A= $oper_text
Aresult
11
00
2077 ## salva o where recursivo
2078 28 push(@where_tmp,join(" ",@where_aux));
2079 28 $oper_pend = 1;
2080 }
2081 28 next;
2082 }
2083  
2084 ## check and/or logical connector
2085 225 ▶ if ($value1 =~ /^(and|\&\&|or|\|\|)$/i)
Branch: 2 branches
BranchTrueFalseTotal
if ($value1 =~ /^(and|\&\&|or|\|\|)$/i) { } 16 209 225
elsif ($oper_pend != 2) { } 201 8 209
2086 {
2087 16 ▶ $oper_text = uc($value1) if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 16 0 16
Condition33%1/3
$oper_pend and @where_tmp
!ll&&!rl&&r
0016
MC/DC0%0/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
Truth table33%1/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
2088 16 $oper_pend = 2;
2089 16 next;
2090 }
2091 201 elsif ($oper_pend != 2) { $oper_text = "AND"; }
2092  
2093 ## process value if not escape
2094 209 ▶ if (!($value1 =~ /^\\(.*)/))
Branch: 1 branch
BranchTrueFalseTotal
if (not $value1 =~ /^\\(.*)/) { } 209 0 209
2095 {
2096 ## validate functions as arguments
2097 209 ▶ if ($self->_checkFunctions(\$value1,SQL_SIMPLE_ALIAS_WHERE))
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_checkFunctions(\$value1, 16)) { } 13 196 209
elsif (@{$self->{'work'}{'tables_inuse'};} == 1) { } 135 61 196
elsif ($value1 =~ /^(.*?)\.(.*?)$/ and grep(/^$1$/, @{$$self{'work'}{'tables_inuse'};}) || defined $self->{'init'}{'table_realname'}{$1}) { } 46 15 61
elsif (defined $self->{'work'}{'field_alias'}{$value1}) { } 2 13 15
2098 {}
2099 ## adjusts for single tables
2100 196 elsif (@{$self->{work}{tables_inuse}} == 1)
2101 {
2102 135 $value1 = $self->_getAliasCols(19,$value1,SQL_SIMPLE_ALIAS_WHERE);
2103 }
2104 ## adjusts for multiple tables
2105 57 ▶ elsif ($value1 =~ /^(.*?)\.(.*?)$/ && (grep(/^$1$/,@{$self->{work}{tables_inuse}}) || defined($self->{init}{table_realname}{$1})))
Condition83%5/6
$value1 =~ /^(.*?)\.(.*?)$/ and grep(/^$1$/, @{$$self{"work"}{"tables_inuse"};}) || defined $self->{"init"}{"table_realname"}{$1}
!ll&&!rl&&r
41146
grep /^$1$/, @{$$self{"work"}{"tables_inuse"};} or defined $self->{"init"}{"table_realname"}{$1}
l!l&&r!l&&!r
46011
MC/DC66%2/3
$value1 =~ /^(.*?)\.(.*?)$/ and grep(/^$1$/, @{$$self{"work"}{"tables_inuse"};}) || defined $self->{"init"}{"table_realname"}{$1}
$value1 =~ /^(.*?)\.(.*?)$/ grep /^$1$/, @{$$self{"work"}{"tables_inuse"};} defined $self->{"init"}{"table_realname"}{$1}
Truth table75%3/4
A and B or C
A= $value1 =~ /^(.*?)\.(.*?)$/B= grep /^$1$/, @{$$self{"work"}{"tables_inuse"};}C= defined $self->{"init"}{"table_realname"}{$1}
ABCresult
0XX0
1000
11X1
1011
2106 {
2107 46 $value1 = $self->_getAliasCols(20,$value1,SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN);
2108 }
2109 elsif (defined($self->{work}{field_alias}{$value1}))
2110 {
2111 2 $value1 = $self->_getAliasCols(28,$self->{work}{field_alias}{$value1},SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN);
2112 }
2113 ## others adjusts
2114 else
2115 {
2116 13 $value1 = $self->_getAliasCols(21,$value1,SQL_SIMPLE_ALIAS_WHERE);
2117 }
2118 }
2119 else
2120 {
2121 0 $value1 = $1;
2122 }
2123  
2124 ## finis where if no more values
2125 209 ▶ if ($ix >= @{$where})
Branch: 1 branch
BranchTrueFalseTotal
if ($ix >= @{$where;}) 1 208 209
2126 {
2127 1 ▶ push(@where_tmp,$oper_text||"AND") if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 1 0 1
Condition40%2/5
$oper_pend and @where_tmp
!ll&&!rl&&r
001
$oper_text || 'AND'
l!l
10
MC/DC0%0/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
MC/DC0%0/1
$oper_text || 'AND'
$oper_text
Truth table33%1/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
Truth table50%1/2
A
A= $oper_text
Aresult
11
00
2128 1 push(@where_tmp,$value1);
2129 1 last;
2130 }
2131  
2132 ###############################################################
2133 ## value2
2134  
2135 ## test value2, if required
2136 208 my $value2 = $where->[$ix++];
2137 208 my $quote = $self->{argv}{quote};
2138  
2139 208 $oper_pend = 1;
2140  
2141 ## value2 is array, multiple values
2142 208 ▶ if (ref($value2) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value2 eq "ARRAY") 66 142 208
2143 {
2144 66 my @_value2 = @{$value2};
2145 66 my $value2_b = "";
2146 66 my $value2_a = "";
2147 66 my $operator = $value2->[0];
2148 66 my $where_opr = "AND";
2149  
2150 ## value0 is escaped (not operator)
2151 66 ▶ if (!defined($operator)) { $operator = "="; }
Branch: 18 branches
BranchTrueFalseTotal
if (not defined $operator) { } 6 60 66
elsif ($operator =~ /^\\/) { } 1 59 60
elsif ($operator eq '=') { } 4 55 59
elsif ($operator eq '!') { } 25 30 55
elsif ($operator eq '!=') { } 0 30 30
elsif ($operator eq '<>') { } 0 30 30
elsif ($operator eq '<=') { } 0 30 30
elsif ($operator eq '<') { } 5 25 30
elsif ($operator eq '>=') { } 5 20 25
elsif ($operator eq '>') { } 5 15 20
elsif ($operator eq '%%') { } 1 14 15
elsif ($operator eq '^%') { } 2 12 14
elsif ($operator eq '%^') { } 2 10 12
elsif ($operator eq '^^') { } 1 9 10
elsif ($operator eq '!%%') { } 0 9 9
elsif ($operator eq '!^%') { } 2 7 9
elsif ($operator eq '!%^') { } 2 5 7
elsif ($operator eq '!^^') { } 0 5 5
2152 1 elsif ($operator =~ /^\\/) { $operator = "="; }
2153 4 elsif ($operator eq "=") { shift(@_value2); }
2154 25 elsif ($operator eq "!") { shift(@_value2); $operator = "!="; }
2155 0 elsif ($operator eq "!=") { shift(@_value2); $operator = "!="; }
2156 0 elsif ($operator eq "<>") { shift(@_value2); $operator = "!="; }
2157 0 elsif ($operator eq "<=") { shift(@_value2); }
2158 5 elsif ($operator eq "<") { shift(@_value2); }
2159 5 elsif ($operator eq ">=") { shift(@_value2); }
2160 5 elsif ($operator eq ">") { shift(@_value2); }
2161 1 ▶ elsif ($operator eq "%%") { shift(@_value2); $operator = "LIKE"; $value2_b = "%"; $value2_a = "%"; $where_opr = "OR" if (@_value2 > 1); }
Branch: 1 branch
BranchTrueFalseTotal
if @_value2 > 1 0 1 1
2162 2 ▶ elsif ($operator eq "^%") { shift(@_value2); $operator = "LIKE"; $value2_b = "%"; $where_opr = "OR" if (@_value2 > 1); }
Branch: 1 branch
BranchTrueFalseTotal
if @_value2 > 1 1 1 2
2163 2 ▶ elsif ($operator eq "%^") { shift(@_value2); $operator = "LIKE"; $value2_a = "%"; $where_opr = "OR" if (@_value2 > 1); }
Branch: 1 branch
BranchTrueFalseTotal
if @_value2 > 1 1 1 2
2164 1 ▶ elsif ($operator eq "^^") { shift(@_value2); $operator = "LIKE"; $where_opr = "OR" if (@_value2 > 1); }
Branch: 1 branch
BranchTrueFalseTotal
if @_value2 > 1 0 1 1
2165 0 elsif ($operator eq "!%%") { shift(@_value2); $operator = "NOT LIKE"; $value2_b = "%"; $value2_a = "%"; }
2166 2 elsif ($operator eq "!^%") { shift(@_value2); $operator = "NOT LIKE"; $value2_b = "%"; }
2167 2 elsif ($operator eq "!%^") { shift(@_value2); $operator = "NOT LIKE"; $value2_a = "%"; }
2168 0 elsif ($operator eq "!^^") { shift(@_value2); $operator = "NOT LIKE"; }
2169 5 else { $operator = "="; }
2170  
2171 ## construct condition
2172 66 ▶ if ($operator eq "=" || $operator eq "!=")
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "=" or $operator eq "!=") 41 25 66
Condition100%3/3
$operator eq "=" or $operator eq "!="
l!l&&r!l&&!r
162525
MC/DC100%2/2
$operator eq "=" or $operator eq "!="
$operator eq "=" $operator eq "!="
Truth table100%3/3
A or B
A= $operator eq "="B= $operator eq "!="
ABresult
1X1
011
000
2173 {
2174 41 ▶ if (@_value2 > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_value2 > 1) 8 33 41
2175 {
2176 8 ▶ for (my $i=0; $i < @_value2; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_value2) 21 8 29
2177 {
2178 21 ▶ if (!defined($_value2[$i]))
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $_value2[$i]) { } 0 21 21
elsif ($_value2[$i] =~ /^\\(.*)/) { } 2 19 21
2179 {
2180 0 $_value2[$i] = 'NULL';
2181 }
2182 elsif ($_value2[$i] =~ /^\\(.*)/)
2183 {
2184 2 my $v = $1;
2185 2 ▶ if ($v =~ /^(\(SELECT\s+.*\))$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ /^(\(SELECT\s+.*\))$/) { } 2 0 2
elsif ($v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{'work'}{'tables_valids'};}) { } 0 0 0
elsif (defined $self->{'work'}{'field_alias'}{$v}) { } 0 0 0
2186 {
2187 2 $_value2[$i] = $v;
2188 }
2189 0 ▶ elsif ($v =~ /^(.*?)\..*?$/ && grep(/^$1$/,@{$self->{work}{tables_valids}}))
Condition0%0/3
$v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
$v =~ /^(.*?)\..*?$/ grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
Truth table0%0/3
A and B
A= $v =~ /^(.*?)\..*?$/B= grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
ABresult
0X0
100
111
2190 {
2191 0 $_value2[$i] = $self->_getAliasCols(22,$v,SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN);
2192 }
2193 elsif (defined($self->{work}{field_alias}{$v}))
2194 {
2195 0 $_value2[$i] = $self->_getAliasCols(27,$self->{work}{field_alias}{$v},SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN);
2196 }
2197 else
2198 {
2199 0 $_value2[$i] = $v;
2200 }
2201 }
2202 else
2203 {
2204 19 $_value2[$i] = $quote.$self->_escapeQuote($_value2[$i]).$quote;
2205 }
2206 }
2207 8 $quote = "";
2208 8 ▶ my $not = ($operator eq "!=") ? " NOT" : "";
Branch: 1 branch
BranchTrueFalseTotal
$operator eq '!=' ? : 2 6 8
2209
2210 ## no _escapeQuote required, already done in value2 build
2211 8 ▶ push(@where_tmp,$oper_text||"AND") if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 1 7 8
Condition60%3/5
$oper_pend and @where_tmp
!ll&&!rl&&r
071
$oper_text || 'AND'
l!l
10
MC/DC50%1/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
MC/DC0%0/1
$oper_text || 'AND'
$oper_text
Truth table66%2/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
Truth table50%1/2
A
A= $oper_text
Aresult
11
00
2212 8 ▶ (@_value2 == 3 && $_value2[1] eq "'..'") ?
Branch: 1 branch
BranchTrueFalseTotal
@_value2 == 3 && $_value2[1] eq q['..'] ? : 5 3 8
Condition66%2/3
@_value2 == 3 and $_value2[1] eq "'..'"
!ll&&!rl&&r
305
MC/DC50%1/2
@_value2 == 3 and $_value2[1] eq "'..'"
@_value2 == 3 $_value2[1] eq "'..'"
Truth table66%2/3
A and B
A= @_value2 == 3B= $_value2[1] eq "'..'"
ABresult
0X0
100
111
2213 push(@where_tmp,$value1.$not." BETWEEN (".$quote.$_value2[0].$quote.",".$quote.$_value2[2].$quote.")"):
2214 push(@where_tmp,$value1.$not." IN (".$quote.join("$quote,$quote",@_value2).$quote.")");
2215 8 next;
2216 }
2217 }
2218  
2219 ## multiple conditions
2220 58 my @where_aux;
2221 58 foreach my $value(@_value2)
2222 {
2223 58 ▶ if (defined($value))
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value) { } 55 3 58
elsif ($operator eq '=') { } 0 3 3
2224 {
2225 55 ▶ if ($value =~ /^\\(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^\\(.*)/) { } 11 44 55
2226 {
2227 11 my $v = $1;
2228 11 ▶ if ($v =~ /^(\(SELECT\s+.*\))$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ /^(\(SELECT\s+.*\))$/) { } 4 7 11
elsif ($v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{'work'}{'tables_valids'};}) { } 0 7 7
elsif (defined $self->{'work'}{'field_alias'}{$v}) { } 0 7 7
2229 {
2230 4 ▶ if ($operator eq "=") { push(@where_aux,$value1." IN ".$1); }
Branch: 2 branches
BranchTrueFalseTotal
if ($operator eq '=') { } 0 4 4
elsif ($operator eq '!=') { } 4 0 4
2231 4 elsif ($operator eq "!=") { push(@where_aux,$value1." NOT IN ".$1); }
2232 0 else { push(@where_aux,$value1." ".$operator." ".$1); }
2233 }
2234 6 ▶ elsif ($v =~ /^(.*?)\..*?$/ && grep(/^$1$/,@{$self->{work}{tables_valids}}))
Condition66%2/3
$v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
!ll&&!rl&&r
160
MC/DC0%0/2
$v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
$v =~ /^(.*?)\..*?$/ grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
Truth table66%2/3
A and B
A= $v =~ /^(.*?)\..*?$/B= grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
ABresult
0X0
100
111
2235 {
2236 0 push(@where_aux,$value1." ".$operator." ".$self->_getAliasCols(23,$v,SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2237 }
2238 elsif (defined($self->{work}{field_alias}{$v}))
2239 {
2240 0 push(@where_aux,$value1." = ".$self->_getAliasCols(26,$self->{work}{field_alias}{$v},SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2241 }
2242 else
2243 {
2244 7 push(@where_aux,$value1." ".$operator." ".$v);
2245 }
2246 }
2247 else
2248 {
2249 44 push(@where_aux,$value1." ".$operator." ".$quote.$self->_escapeQuote($value2_a.$value.$value2_b).$quote);
2250 }
2251 }
2252 elsif ($operator eq "=")
2253 {
2254 0 push(@where_aux,$value1." IS NULL");
2255 }
2256 else
2257 {
2258 3 push(@where_aux,$value1." IS NOT NULL");
2259 }
2260 }
2261 58 ▶ if (@where_aux > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@where_aux > 1) 6 52 58
2262 {
2263 6 $where_aux[0] = "(".$where_aux[0];
2264 6 $where_aux[@where_aux-1] .= ")";
2265 }
2266 58 ▶ push(@where_tmp,$oper_text||"AND") if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 15 43 58
Condition60%3/5
$oper_pend and @where_tmp
!ll&&!rl&&r
04315
$oper_text || 'AND'
l!l
150
MC/DC50%1/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
MC/DC0%0/1
$oper_text || 'AND'
$oper_text
Truth table66%2/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
Truth table50%1/2
A
A= $oper_text
Aresult
11
00
2267 58 ▶ (@where_aux) ?
Branch: 1 branch
BranchTrueFalseTotal
@where_aux ? : 52 6 58
2268 push(@where_tmp,join(" ".$where_opr." ",@where_aux)) :
2269 push(@where_tmp,$value1." IS NULL");
2270 58 next;
2271 }
2272  
2273 ## enforce operands if required
2274 142 ▶ push(@where_tmp,$oper_text||"AND") if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 31 111 142
Condition60%3/5
$oper_pend and @where_tmp
!ll&&!rl&&r
011131
$oper_text || 'AND'
l!l
310
MC/DC50%1/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
MC/DC0%0/1
$oper_text || 'AND'
$oper_text
Truth table66%2/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
Truth table50%1/2
A
A= $oper_text
Aresult
11
00
2275  
2276 ## value2 is single value
2277 142 ▶ if (!defined($value2))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value2) 6 136 142
2278 {
2279 6 push(@where_tmp,$value1." IS NULL");
2280 6 next;
2281 }
2282 136 ▶ if (ref($value2) eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value2 eq "") 136 0 136
2283 {
2284 136 ▶ if ($value2 =~ /^\\(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($value2 =~ /^\\(.*)/) { } 29 107 136
2285 {
2286 29 my $v = $1;
2287 29 ▶ if ($v =~ /^(\(SELECT\s+(.*)\))$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ /^(\(SELECT\s+(.*)\))$/) { } 2 27 29
elsif ($v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{'work'}{'tables_valids'};}) { } 15 12 27
elsif (defined $self->{'work'}{'field_alias'}{$v}) { } 1 11 12
2288 {
2289 2 push(@where_tmp,$value1." IN ".$1);
2290 }
2291 23 ▶ elsif ($v =~ /^(.*?)\..*?$/ && grep(/^$1$/,@{$self->{work}{tables_valids}}))
Condition100%3/3
$v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
!ll&&!rl&&r
4815
MC/DC100%2/2
$v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
$v =~ /^(.*?)\..*?$/ grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
Truth table100%3/3
A and B
A= $v =~ /^(.*?)\..*?$/B= grep /^$1$/, @{$$self{"work"}{"tables_valids"};}
ABresult
0X0
100
111
2292 {
2293 15 push(@where_tmp,$value1." = ".$self->_getAliasCols(24,$v,SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2294 }
2295 elsif (defined($self->{work}{field_alias}{$v}))
2296 {
2297 1 push(@where_tmp,$value1." = ".$self->_getAliasCols(25,$self->{work}{field_alias}{$v},SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2298 }
2299 else
2300 {
2301 11 push(@where_tmp,$value1." = ".$v);
2302 }
2303 }
2304 else
2305 {
2306 107 push(@where_tmp,$value1." = ".$quote.$self->_escapeQuote($value2).$quote);
2307 }
2308 136 next;
2309 }
2310  
2311 ## return error if value2 is not array or value type
2312 0 $self->_setMessage($command,SQL_SIMPLE_RC_SYNTAX,"028");
2313 0 return SQL_SIMPLE_RC_SYNTAX;
2314 }
2315 174 ▶ if (@where_tmp)
Branch: 1 branch
BranchTrueFalseTotal
if (@where_tmp) 174 0 174
2316 {
2317 174 push(@{$buffer},join(" ",@where_tmp));
2318 174 ▶ if ($level && @where_tmp > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($level and @where_tmp > 1) 16 158 174
Condition100%3/3
$level and @where_tmp > 1
!ll&&!rl&&r
1461216
MC/DC100%2/2
$level and @where_tmp > 1
$level @where_tmp > 1
Truth table100%3/3
A and B
A= $levelB= @where_tmp > 1
ABresult
0X0
100
111
2319 {
2320 16 $buffer->[0] = "(".$buffer->[0];
2321 16 $buffer->[@{$buffer}-1] .= ")";
2322 }
2323 }
2324 174 return 0;
2325 }
2326  
2327 ##############################################################################
2328 ## action: get dbh entry point module
2329 ## return: current dbi drive pointer module
2330  
2331 sub getDBH()
2332 {
2333 0 ▶ return $_[0]->{init}{dbh};
Subroutine getDBH: not called CC=1 SCAR=6.9
Pod documented
2334 }
2335  
2336 ##############################################################################
2337 ## action: get last condition state
2338 ## return: last return code state
2339  
2340 sub getRC()
2341 {
2342 576 ▶ return $err;
Subroutine getRC: called CC=1 SCAR=0.0
Pod documented
2343 }
2344  
2345 ##############################################################################
2346 ## action: get last message state
2347 ## return: last system message
2348  
2349 sub getMessage()
2350 {
2351 17 ▶ return $errstr;
Subroutine getMessage: called CC=1 SCAR=0.0
Pod documented
2352 }
2353  
2354 ##############################################################################
2355 ## action: get number of extracted lines
2356 ## return: number of extracted lines
2357  
2358 sub getRows()
2359 {
2360 0 ▶ return $_[0]->{init}{rows};
Subroutine getRows: not called CC=1 SCAR=6.9
Pod documented
2361 }
2362  
2363 ##############################################################################
2364 ## action: get the last sql command
2365 ## return: last sql command
2366  
2367 sub getLastSQL()
2368 {
2369 289 ▶ return $_[0]->{init}{sql_command};
Subroutine getLastSQL: called CC=1 SCAR=0.0
Pod documented
2370 }
2371  
2372 ##############################################################################
2373 ## action: get the last cursor pointer
2374 ## return: cursor pointer
2375  
2376 sub getLastCursor()
2377 {
2378 0 ▶ my $self = shift;
Subroutine getLastCursor: not called CC=1 SCAR=6.9
Pod documented
2379 0 return %{$self->{init}{cursor}};
2380 }
2381  
2382 ##############################################################################
2383 ## action: get the last saved fileset
2384 ## return: last sql logfile
2385  
2386 sub getLastSave()
2387 {
2388 1 ▶ return $_[0]->{init}{sql_save_logfile};
Subroutine getLastSave: called CC=1 SCAR=0.0
Pod documented
2389 }
2390  
2391 ##############################################################################
2392 ## action: get the table's realname
2393 ## return: name of the table
2394  
2395 sub getAliasTable()
2396 {
2397 0 ▶ my $self = shift;
Subroutine getAliasTable: not called CC=1 SCAR=6.9
Pod documented
2398 0 return $self->_getAliasTable(@_,{schema=>defined($self->{init}{schema})});
2399 }
2400  
2401 sub _getAliasTable()
2402 {
2403 312 ▶ my $self = shift;
Subroutine _getAliasTable: called CC=2 SCAR=6.9
2404 312 my $table = shift;
2405 312 my $argv = shift;
2406  
2407 312 ▶ return $self->_getSchemaName($argv).$table." ".$self->{work}{tables_alias}{$table} if (defined($self->{work}{tables_alias}{$table}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"work"}{"tables_alias"}{$table} 205 107 312
2408 107 return $self->_getSchemaName($argv).$table;
2409 }
2410  
2411 ##############################################################################
2412 ## action: get the schema name if required
2413 ## return: name of the schema
2414  
2415 sub _getSchemaName()
2416 {
2417 312 ▶ my $self = shift;
Subroutine _getSchemaName: called CC=3 SCAR=15.1
2418 312 my $argv = shift;
2419  
2420 312 ▶ return "" if (!$argv->{schema});
Branch: 1 branch
BranchTrueFalseTotal
unless $argv->{"schema"} 312 0 312
2421 0 ▶ return "" if (!defined($self->{argv}{schema}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"schema"} 0 0 0
2422 0 return $self->{argv}{schema}.".";
2423 }
2424  
2425 ##############################################################################
2426 ## action: get the table's realname
2427 ## return: name of the table
2428  
2429 sub getAliasCols()
2430 {
2431 0 ▶ my $self = shift;
Subroutine getAliasCols: not called CC=1 SCAR=6.9
Pod documented
2432 0 return $self->_getAliasCols(0,@_);
2433 }
2434  
2435 ##############################################################################
2436 # 0x01 - return col_real wo/table
2437  
2438 sub _getAliasCols()
2439 {
2440 660 ▶ my $self = shift;
Subroutine _getAliasCols: called CC=26 SCAR=32.6
2441 660 my $mycall = shift;
2442 660 my $field = shift;
2443 660 my $result = shift;
2444  
2445 660 my $_table;
2446 my $_field;
2447  
2448 ## enforce prefered aliases if defined
2449 660 ▶ $field = $self->{work}{field_alias}{$field} if (defined($self->{work}{field_alias}{$field}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"work"}{"field_alias"}{$field} 6 654 660
2450  
2451 ## field have ident?
2452 660 ▶ if ($field =~ /^(.*?)\.(.*?)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^(.*?)\.(.*?)$/) { } 306 354 660
2453 {
2454 306 $_table = $1;
2455 306 $_field = $2;
2456 306 ▶ if (defined($self->{work}{field_cols}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}) 78 228 306
2457 {
2458 78 ▶ if (defined($self->{work}{field_cols}{$_table}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'work'}{'field_cols'}{$_table}) { } 66 12 78
2459 {
2460 66 ▶ if (defined($self->{work}{field_cols}{$_table}{$_field}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}{$_table}{$_field}) 4 62 66
2461 {
2462 4 $_field = $self->{work}{field_cols}{$_table}{$_field};
2463 }
2464 }
2465 else
2466 {
2467 12 ▶ if (defined($self->{work}{tables_alias}{$_table}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"tables_alias"}{$_table}) 6 6 12
2468 {
2469 6 my $a = $self->{work}{tables_alias}{$_table};
2470 6 ▶ if (defined($self->{work}{field_cols}{$a}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}{$a}) 6 0 6
2471 {
2472 6 ▶ if (defined($self->{work}{field_cols}{$a}{$_field}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}{$a}{$_field}) 2 4 6
2473 {
2474 2 $_field = $self->{work}{field_cols}{$a}{$_field};
2475 }
2476 }
2477 }
2478 }
2479  
2480 }
2481 306 ▶ if (!grep(/^$_table$/,@{$self->{work}{tables_inuse}}))
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$_table$/, @{$$self{"work"}{"tables_inuse"};}) 104 202 306
2482 {
2483 104 ▶ return $field if (!defined($self->{argv}{tables}) || !defined($self->{argv}{tables}{$_table}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"tables"} and defined $self->{"argv"}{"tables"}{$_table} 10 94 104
Condition66%2/3
defined $self->{"argv"}{"tables"} and defined $self->{"argv"}{"tables"}{$_table}
!ll&&!rl&&r
01094
MC/DC50%1/2
defined $self->{"argv"}{"tables"} and defined $self->{"argv"}{"tables"}{$_table}
defined $self->{"argv"}{"tables"} defined $self->{"argv"}{"tables"}{$_table}
Truth table66%2/3
A and B
A= defined $self->{"argv"}{"tables"}B= defined $self->{"argv"}{"tables"}{$_table}
ABresult
0X0
100
111
2484 94 $_table = $self->{argv}{tables}{$_table}{name};
2485 }
2486 296 ▶ $_field = $self->{argv}{tables}{ $self->{work}{tables_alias}{$_table} }{cols}{$_field} if (defined($self->{argv}{tables}) && defined($self->{work}{tables_alias}{$_table}) && defined($self->{argv}{tables}{ $self->{work}{tables_alias}{$_table} }{cols}{$_field}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"argv"}{"tables"} and defined $self->{"work"}{"tables_alias"}{$_table} and defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field} 124 172 296
Condition100%6/6
defined $self->{"argv"}{"tables"} and defined $self->{"work"}{"tables_alias"}{$_table} and defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
!ll&&!rl&&r
14527124
defined $self->{"argv"}{"tables"} and defined $self->{"work"}{"tables_alias"}{$_table}
!ll&&!rl&&r
7174151
MC/DC100%3/3
defined $self->{"argv"}{"tables"} and defined $self->{"work"}{"tables_alias"}{$_table} and defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
defined $self->{"argv"}{"tables"} defined $self->{"work"}{"tables_alias"}{$_table} defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
Truth table100%4/4
A and B and C
A= defined $self->{"argv"}{"tables"}B= defined $self->{"work"}{"tables_alias"}{$_table}C= defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
ABCresult
0XX0
10X0
1100
1111
2487 296 ▶ $result |= SQL_SIMPLE_ALIAS_FQDN if (@{$self->{work}{tables_inuse}} != 1);
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"work"}{"tables_inuse"};} != 1 212 84 296
2488 }
2489 else
2490 {
2491 354 $_field = $field;
2492  
2493 ## single table in use?
2494 354 ▶ if (@{$self->{work}{tables_inuse}} == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'work'}{'tables_inuse'};} == 1) { } 318 36 354
2495 {
2496 318 $_table = $self->{work}{tables_inuse}[0];
2497 318 ▶ $_field = $self->{argv}{tables}{ $self->{work}{tables_alias}{$_table} }{cols}{$_field} if (defined($self->{work}{tables_alias}{$_table}) && defined($self->{argv}{tables}{ $self->{work}{tables_alias}{$_table} }{cols}{$_field}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"work"}{"tables_alias"}{$_table} and defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field} 117 201 318
Condition100%3/3
defined $self->{"work"}{"tables_alias"}{$_table} and defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
!ll&&!rl&&r
17526117
MC/DC100%2/2
defined $self->{"work"}{"tables_alias"}{$_table} and defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
defined $self->{"work"}{"tables_alias"}{$_table} defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
Truth table100%3/3
A and B
A= defined $self->{"work"}{"tables_alias"}{$_table}B= defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
ABresult
0X0
100
111
2498 }
2499
2500 ## scan contents
2501 else
2502 {
2503 36 foreach my $t(@{$self->{work}{tables_inuse}})
2504 {
2505 ## ignore table if field not found
2506 72 ▶ next if ( defined($self->{work}{tables_alias}{$t}) && !defined($self->{argv}{tables}{ $self->{work}{tables_alias}{$t} }{cols}{$_field}) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"work"}{"tables_alias"}{$t} and not defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$t}}{"cols"}{$_field} 16 56 72
Condition100%3/3
defined $self->{"work"}{"tables_alias"}{$t} and not defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$t}}{"cols"}{$_field}
!ll&&!rl&&r
243216
MC/DC100%2/2
defined $self->{"work"}{"tables_alias"}{$t} and not defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$t}}{"cols"}{$_field}
defined $self->{"work"}{"tables_alias"}{$t} not defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$t}}{"cols"}{$_field}
Truth table100%3/3
A and not(B)
A= defined $self->{"work"}{"tables_alias"}{$t}B= not defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$t}}{"cols"}{$_field}
ABresult
0X0
100
111
2507  
2508 ## returns field as is if duplicated
2509 56 ▶ return $field if ($_table);
Branch: 1 branch
BranchTrueFalseTotal
if $_table 28 28 56
2510  
2511 ## define the table by alias
2512 28 $_table = $t;
2513 }
2514 }
2515 }
2516 622 ▶ if ($_table && $result & SQL_SIMPLE_ALIAS_FQDN)
Branch: 1 branch
BranchTrueFalseTotal
if ($_table and $result & 32768) 232 390 622
Condition100%3/3
$_table and $result & 32768
!ll&&!rl&&r
8382232
MC/DC100%2/2
$_table and $result & 32768
$_table $result & 32768
Truth table100%3/3
A and B
A= $_tableB= $result & 32768
ABresult
0X0
100
111
2517 {
2518 232 ▶ $_table = $self->{work}{tables_alias}{$_table} if (defined($self->{work}{tables_alias}{$_table}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"work"}{"tables_alias"}{$_table} 118 114 232
2519 232 return $_table.".".$_field;
2520 }
2521 390 return $_field;
2522 }
2523  
2524 ################################################################################
2525 ## action: validate functions and convert the fields named
2526  
2527 sub _checkFunctions()
2528 {
2529 260 ▶ my $self = shift;
Subroutine _checkFunctions: called CC=9 SCAR=22.0
2530 260 my $value1 = shift;
2531 260 my $result = shift;
2532  
2533 ## test if value is function
2534 260 my $fnc;
2535 260 my $op1 = ${$value1};
2536 260 my $op2 = '';
2537 260 my $lvl;
2538 260 ▶ while (($op1 =~ /^(.*?)\((.*)\)(.*)\)$/) || ($op1 =~ /^(.*?)\((.*)\)$/))
Branch: 1 branch
BranchTrueFalseTotal
if ($op1 =~ /^(.*?)\((.*)\)(.*)\)$/ or $op1 =~ /^(.*?)\((.*)\)$/) 15 260 275
Condition100%3/3
$op1 =~ /^(.*?)\((.*)\)(.*)\)$/ or $op1 =~ /^(.*?)\((.*)\)$/
l!l&&r!l&&!r
213260
MC/DC100%2/2
$op1 =~ /^(.*?)\((.*)\)(.*)\)$/ or $op1 =~ /^(.*?)\((.*)\)$/
$op1 =~ /^(.*?)\((.*)\)(.*)\)$/ $op1 =~ /^(.*?)\((.*)\)$/
Truth table100%3/3
A or B
A= $op1 =~ /^(.*?)\((.*)\)(.*)\)$/B= $op1 =~ /^(.*?)\((.*)\)$/
ABresult
1X1
011
000
2539 {
2540 15 $lvl++;
2541 15 $fnc .= $1."(";
2542 15 ▶ $op1 = $2.((defined($3)) ? ")" : "");
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 2 13 15
2543 15 ▶ $op2 .= (defined($3)) ? ")".$3 : ")";
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 2 13 15
2544 }
2545  
2546 ## process functions if mapped
2547 260 ▶ if ($lvl)
Branch: 1 branch
BranchTrueFalseTotal
if ($lvl) 13 247 260
2548 {
2549 13 ▶ if ($op1 =~ /^(.*?)\,(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($op1 =~ /^(.*?)\,(.*)$/) { } 2 11 13
2550 {
2551 2 my $o1 = $1;
2552 2 my $o2 = $2;
2553 2 ▶ if ($o1 =~ /^.*?\..*?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($o1 =~ /^.*?\..*?$/) { } 0 2 2
2554 {
2555 0 $op1 = $self->_getAliasCols(15,$o1,$result+SQL_SIMPLE_ALIAS_FQDN);
2556 }
2557 else
2558 {
2559 2 $op1 = $self->_getAliasCols(16,$o1,$result);
2560 }
2561 2 $op1 .= ",".$o2;
2562 }
2563 else
2564 {
2565 11 ▶ if ($op1 =~ /^.*?\..*?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($op1 =~ /^.*?\..*?$/) { } 2 9 11
2566 {
2567 2 $op1 = $self->_getAliasCols(17,$op1,$result+SQL_SIMPLE_ALIAS_FQDN);
2568 }
2569 else
2570 {
2571 9 $op1 = $self->_getAliasCols(18,$op1,$result);
2572 }
2573 }
2574 13 ${$value1} = $fnc.$op1.$op2;
2575 }
2576 260 return $lvl;
2577 }
2578  
2579 ################################################################################
2580 ## action: test the argv->{table} and create the tables_inuse list
2581  
2582 sub _checkTablesEntries()
2583 {
2584 289 ▶ my $self = shift;
Subroutine _checkTablesEntries: called CC=13 SCAR=27.4
2585 289 my $cmnd = shift;
2586 289 my $argv = shift;
2587  
2588 ## tables is missing?
2589 289 ▶ if (!defined($argv->{table}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argv->{"table"}) 0 289 289
2590 {
2591 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"005");
2592 0 return SQL_SIMPLE_RC_SYNTAX;
2593 }
2594  
2595 ## validate tables
2596 289 my $tables_work;
2597 289 ▶ if (ref($argv->{table}) eq "")
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'table'} eq '') { } 203 86 289
elsif (ref $argv->{'table'} eq 'ARRAY' and $self->{'work'}{'command'} == 8 || $self->{'work'}{'command'} == 2) { } 86 0 86
2598 {
2599 203 $tables_work = [$argv->{table}];
2600 }
2601 ▶ elsif (ref($argv->{table}) eq "ARRAY" && ($self->{work}{command} == SQL_SIMPLE_ALIAS_SELECT || $self->{work}{command} == SQL_SIMPLE_ALIAS_UPDATE))
Condition50%3/6
ref $argv->{"table"} eq "ARRAY" and $self->{"work"}{"command"} == 8 || $self->{"work"}{"command"} == 2
!ll&&!rl&&r
0086
$self->{"work"}{"command"} == 8 or $self->{"work"}{"command"} == 2
l!l&&r!l&&!r
75110
MC/DC0%0/3
ref $argv->{"table"} eq "ARRAY" and $self->{"work"}{"command"} == 8 || $self->{"work"}{"command"} == 2
ref $argv->{"table"} eq "ARRAY" $self->{"work"}{"command"} == 8 $self->{"work"}{"command"} == 2
Truth table50%2/4
A and B or C
A= ref $argv->{"table"} eq "ARRAY"B= $self->{"work"}{"command"} == 8C= $self->{"work"}{"command"} == 2
ABCresult
0XX0
1000
11X1
1011
2602 {
2603 86 $tables_work = $argv->{table};
2604 }
2605 else
2606 {
2607 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"006");
2608 0 return SQL_SIMPLE_RC_SYNTAX;
2609 }
2610  
2611 ## assign table as in use
2612 289 $self->{work}{tables_valids} = [];
2613 289 foreach my $table(@{$tables_work})
2614 {
2615 375 ▶ if (grep(/^$table$/,@{$self->{work}{tables_inuse}}))
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$table$/, @{$$self{"work"}{"tables_inuse"};}) 0 375 375
2616 {
2617 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"033",$table);
2618 0 return SQL_SIMPLE_RC_SYNTAX;
2619 }
2620 375 ▶ if (defined($self->{argv}{tables}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"tables"}) 313 62 375
2621 {
2622 ## defined as alias in content tables?
2623 313 ▶ if (defined($self->{argv}{tables}{$table}) && defined($self->{argv}{tables}{$table}{name}))
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'argv'}{'tables'}{$table} and defined $self->{'argv'}{'tables'}{$table}{'name'}) { } 163 150 313
elsif (defined $self->{'init'}{'table_realname'}{$table}) { } 70 80 150
Condition66%2/3
defined $self->{"argv"}{"tables"}{$table} and defined $self->{"argv"}{"tables"}{$table}{"name"}
!ll&&!rl&&r
1500163
MC/DC50%1/2
defined $self->{"argv"}{"tables"}{$table} and defined $self->{"argv"}{"tables"}{$table}{"name"}
defined $self->{"argv"}{"tables"}{$table} defined $self->{"argv"}{"tables"}{$table}{"name"}
Truth table66%2/3
A and B
A= defined $self->{"argv"}{"tables"}{$table}B= defined $self->{"argv"}{"tables"}{$table}{"name"}
ABresult
0X0
100
111
2624 {
2625 163 my $realname = $self->{argv}{tables}{$table}{name};
2626 163 ▶ if (defined($self->{work}{tables_alias}{$realname}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"tables_alias"}{$realname}) 0 163 163
2627 {
2628 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"033",$table);
2629 0 return SQL_SIMPLE_RC_SYNTAX;
2630 }
2631 163 push(@{$self->{work}{tables_inuse}},$realname);
2632 163 $self->{work}{tables_alias}{$realname} = $table;
2633 163 push(@{$self->{work}{tables_valids}},$table);
2634 163 next;
2635 }
2636 elsif (defined($self->{init}{table_realname}{$table}))
2637 {
2638 70 $self->{work}{tables_alias}{$table} = $self->{init}{table_realname}{$table};
2639 70 push(@{$self->{work}{tables_valids}},$self->{init}{table_realname}{$table});
2640 }
2641 }
2642 212 push(@{$self->{work}{tables_inuse}},$table);
2643 }
2644 289 push(@{$self->{work}{tables_valids}},@{$self->{work}{tables_inuse}});
2645 289 return SQL_SIMPLE_RC_OK;
2646 }
2647  
2648 ################################################################################
2649 ## action: set last command sql
2650 ## return: none
2651  
2652 sub _setLastSQL()
2653 {
2654 563 ▶ $_[0]->{init}{sql_command} = $_[1];
Subroutine _setLastSQL: called CC=1 SCAR=0.0
2655 }
2656  
2657 ################################################################################
2658 ## action: set commit
2659 ## return: old commit
2660  
2661 sub _setCommit()
2662 {
2663 0 ▶ my $self = shift;
Subroutine _setCommit: not called CC=2 SCAR=17.9
2664 0 my $save = $self->{argv}{commit};
2665 0 ▶ $self->{argv}{commit} = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2666 0 return $save;
2667 }
2668  
2669 ################################################################################
2670 ## action: set message_log
2671 ## return: old message_log
2672  
2673 sub _setLogMessage()
2674 {
2675 0 ▶ my $self = shift;
Subroutine _setLogMessage: not called CC=2 SCAR=17.9
2676 0 my $save = $self->{argv}{message_log};
2677 0 ▶ $self->{argv}{message_log} = shift || 0 ;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2678 0 return $save;
2679 }
2680  
2681 ################################################################################
2682 ## action: set sql_save
2683 ## return: old sql_save
2684  
2685 sub _setSqlSave()
2686 {
2687 2 ▶ my $self = shift;
Subroutine _setSqlSave: called CC=2 SCAR=6.9
2688 2 my $save = $self->{argv}{sql_save};
2689 2 ▶ $self->{argv}{sql_save} = shift || 0;
Condition100%2/2
shift() || 0
l!l
11
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
2690 2 return $save;
2691 }
2692  
2693 ################################################################################
2694 ## action: set quote character
2695 ## return: old quote chacracter
2696  
2697 sub _setQuote()
2698 {
2699 0 ▶ my $self = shift;
Subroutine _setQuote: not called CC=5 SCAR=34.0
2700 0 my $quote = shift;
2701 0 my $save = $self->{argv}{quote};
2702 0 ▶ $self->{argv}{quote} = $quote || "'" if ($quote eq "" || $quote eq '"' || $quote eq "'");
Branch: 1 branch
BranchTrueFalseTotal
if $quote eq "" or $quote eq "\"" or $quote eq "'" 0 0 0
Condition0%0/8
$quote eq "" or $quote eq "\"" or $quote eq "'"
l!l&&r!l&&!r
000
$quote eq "" or $quote eq "\""
l!l&&r!l&&!r
000
$quote || q[']
l!l
00
MC/DC0%0/3
$quote eq "" or $quote eq "\"" or $quote eq "'"
$quote eq "" $quote eq "\"" $quote eq "'"
MC/DC0%0/1
$quote || q[']
$quote
Truth table0%0/4
A or B or C
A= $quote eq ""B= $quote eq "\""C= $quote eq "'"
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/2
A
A= $quote
Aresult
11
00
2703 0 return $save;
2704 }
2705  
2706 ################################################################################
2707 ## action: escape quote in string
2708 ## return: string with escape (if exists)
2709  
2710 sub _escapeQuote()
2711 {
2712 250 ▶ my $self = shift;
Subroutine _escapeQuote: called CC=2 SCAR=7.0
2713 250 my $value = shift;
2714
2715 ## return if not quote
2716 250 ▶ return $value if ($self->{argv}{quote} eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"argv"}{"quote"} eq "" 0 250 250
2717
2718 ## escape and return
2719 250 $value =~ s/$self->{argv}{quote}/\\$self->{argv}{quote}/g;
2720 250 return $value;
2721 }
2722  
2723 ################################################################################
2724 ## action: cleanup the last session call
2725 ## return: return code
2726  
2727 sub _resetSession()
2728 {
2729 291 ▶ my $self = shift;
Subroutine _resetSession: called CC=1 SCAR=0.0
2730 291 $err = 0;
2731 291 $errstr = "";
2732 291 $self->_setLastSQL("");
2733 291 delete ($self->{work});
2734 291 $self->{work} = {};
2735 }
2736  
2737 ################################################################################
2738 ## action: set message state
2739 ## return: return code
2740  
2741 sub _setMessage()
2742 {
2743 21 ▶ my $self = shift;
Subroutine _setMessage: called CC=14 SCAR=38.1
2744 21 my $command = shift;
2745 21 my $rc = shift;
2746 21 my $code = shift;
2747 21 my @argv = @_;
2748  
2749 21 ▶ if (!defined($rc))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rc) 4 17 21
2750 {
2751 4 ▶ return $self->_setMessage($command,$self->{init}{dbh}->err+0,"099",$self->{init}{dbh}->errstr()) if (defined($self->{init}{dbh}) && $self->{init}{dbh}->err);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"init"}{"dbh"} and $self->{"init"}{"dbh"}->err 0 4 4
Condition33%1/3
defined $self->{"init"}{"dbh"} and $self->{"init"}{"dbh"}->err
!ll&&!rl&&r
040
MC/DC0%0/2
defined $self->{"init"}{"dbh"} and $self->{"init"}{"dbh"}->err
defined $self->{"init"}{"dbh"} $self->{"init"}{"dbh"}->err
Truth table33%1/3
A and B
A= defined $self->{"init"}{"dbh"}B= $self->{"init"}{"dbh"}->err
ABresult
0X0
100
111
2752 4 ▶ return $self->_setMessage($command,$DBI::err+0,"099",$DBI::errstr) if ($DBI::err);
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::err 0 4 4
2753  
2754 4 $err = 0;
2755 4 $errstr = "";
2756 4 return $err;
2757 }
2758  
2759 17 $err = $rc;
2760 $errstr = (defined($SQL_SIMPLE_TABLE_OF_MSGS{$code})) ?
2761 17 ▶ $code.$SQL_SIMPLE_TABLE_OF_MSGS{$code}{T}." ".sprintf($SQL_SIMPLE_TABLE_OF_MSGS{$code}{M},$command,@argv) :
Branch: 1 branch
BranchTrueFalseTotal
defined $SQL::SimpleOps::SQL_SIMPLE_TABLE_OF_MSGS{$code} ? : 17 0 17
2762 "999S [message] invalid message code '$code'";
2763  
2764 17 ▶ if ($self->{argv}{message_log})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"message_log"}) 0 17 17
2765 {
2766 0 ▶ print STDERR $errstr."\n" if ($self->{argv}{message_log} & SQL_SIMPLE_LOG_STD);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"argv"}{"message_log"} & 2 0 0 0
2767  
2768 0 ▶ if ($self->{argv}{message_log} & SQL_SIMPLE_LOG_SYS)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"message_log"} & 1) 0 0 0
2769 {
2770 0 require Sys::Syslog;
2771 0 ▶ openlog($self->{argv}{message_syslog_service} || "SQL-SimpleOps", "ndelay,pid", $self->{argv}{message_syslog_facility} || "local0");
Condition0%0/4
$self->{'argv'}{'message_syslog_service'} || 'SQL-SimpleOps'
l!l
00
$self->{'argv'}{'message_syslog_facility'} || 'local0'
l!l
00
MC/DC0%0/1
$self->{'argv'}{'message_syslog_service'} || 'SQL-SimpleOps'
$self->{'argv'}{'message_syslog_service'}
MC/DC0%0/1
$self->{'argv'}{'message_syslog_facility'} || 'local0'
$self->{'argv'}{'message_syslog_facility'}
Truth table0%0/2
A
A= $self->{'argv'}{'message_syslog_service'}
Aresult
11
00
Truth table0%0/2
A
A= $self->{'argv'}{'message_syslog_facility'}
Aresult
11
00
2772 syslog(
2773 ($SQL_SIMPLE_TABLE_OF_MSGS{$code}{T} eq "E") ? "error" :
2774 ($SQL_SIMPLE_TABLE_OF_MSGS{$code}{T} eq "S") ? "error" :
2775 0 ▶ ($SQL_SIMPLE_TABLE_OF_MSGS{$code}{T} eq "W") ? "warning" :
Branch: 3 branches
BranchTrueFalseTotal
$SQL::SimpleOps::SQL_SIMPLE_TABLE_OF_MSGS{$code}{'T'} eq 'E' ? : 0 0 0
$SQL::SimpleOps::SQL_SIMPLE_TABLE_OF_MSGS{$code}{'T'} eq 'S' ? : 0 0 0
$SQL::SimpleOps::SQL_SIMPLE_TABLE_OF_MSGS{$code}{'T'} eq 'W' ? : 0 0 0
2776 "info",
2777 $errstr
2778 );
2779 0 closelog();
2780 }
2781 }
2782 17 return $err;
2783 }
2784  
2785 ################################################################################
2786 ## action: enable/disable show dumper data at each call
2787 ## note: used for debug mode only.
2788  
2789 sub setDumper()
2790 {
2791 281 ▶ my $self = shift;
Subroutine setDumper: called CC=1 SCAR=0.0
Pod documented
2792 281 return $self->{init}{dumper} = shift;
2793 }
2794  
2795 sub _Dumper()
2796 {
2797 290 ▶ my $self = shift;
Subroutine _Dumper: called CC=2 SCAR=10.8
2798 290 my $call = shift;
2799 290 my $argv = shift;
2800  
2801 290 ▶ return if (!$self->{init}{dumper});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"init"}{"dumper"} 290 0 290
2802  
2803 0 require Data::Dumper;
2804 0 ▶ $Data::Dumper::Sortkeys = \sub { my ($hash) = @_; return [ (sort keys %$hash) ]; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2805  
2806 0 my $dumper = new Data::Dumper([$argv]);
2807  
2808 0 $dumper->Terse(1);
2809  
2810 0 print STDERR $call." = ".$dumper->Dump;
2811 }
2812  
2813 __END__
↑ Summary SimpleOps/DBI/MySQL.pm »