SimpleOps.pm

filter: Statementstmt 65.4% 898 / 1373 Branchbran 53.1% 524 / 986 Conditioncond 44.1% 116 / 263 MC/DCmcdc 25.6% 41 / 160 Subroutinesub 84.1% 69 / 82 Podpod 79.1% 19 / 24 totaltotal 57.7% 1667 / 2888 CC 610 SCAR 66.5
CC
610
Cov
59%
_Call
4624.3
_SelectCursor
1384.7
new
509.9
CRAP 775.9
↑ 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.095.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 2 ▶ my $self = shift;
Subroutine SelectSubQuery: called CC=1 SCAR=0.0
Pod documented
437 2 my $argv = {@_};
438  
439 2 $argv->{subquery} = 1;
440  
441 2 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 191 ▶ my $self = shift;
Subroutine Select: called CC=13 SCAR=27.4
Pod documented
794 191 my $argv = {@_};
795  
796 191 ▶ $argv->{make_only} = 1 if ($argv->{subquery});
Branch: 1 branch
BranchTrueFalseTotal
if $argv->{"subquery"} 6 185 191
797  
798 191 $self->_resetSession();
799 191 $self->_Dumper("select",$argv);
800 191 ▶ $self->Open() if (!defined($self->{init}{dbh}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"init"}{"dbh"} 0 191 191
801  
802 ## define the command in load
803 191 $self->{work}{command} = SQL_SIMPLE_ALIAS_SELECT;
804  
805 191 ▶ 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 191 191
Condition33%1/3
$self->{"init"}{"plugin_fh"}->can("Select") and $self->{"init"}{"plugin_fh"}->Select($argv)
!ll&&!rl&&r
19100
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 191 ▶ my $saved_message_log = $self->_setLogMessage($argv->{message_log}) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 191 191
812 191 ▶ my $saved_quote = $self->_setQuote($argv->{quote}) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 191 191
813 191 ▶ my $saved_sql_save = $self->_setSqlSave($argv->{sql_save}) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 1 190 191
814  
815 191 my $rc = $self->_Select(%{$argv});
816  
817 191 ▶ $self->setMessgeLog($saved_message_log) if (defined($argv->{message_log}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"message_log"} 0 191 191
818 191 ▶ $self->_setQuote($saved_quote) if (defined($argv->{quote}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"quote"} 0 191 191
819 191 ▶ $self->_setSqlSave($saved_sql_save) if (defined($argv->{sql_save}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"sql_save"} 1 190 191
820  
821 191 ▶ return "\\(". ( ($self->getRC()==0) ? $self->getLastSQL() : "**".$self->getMessage()."**" ) .")" if ($argv->{subquery});
Branch: 2 branches
BranchTrueFalseTotal
if $argv->{"subquery"} 6 185 191
$self->getRC == 0 ? : 6 0 6
822 185 return $rc;
823 }
824  
825 sub _Select()
826 {
827 208 ▶ my $self = shift;
Subroutine _Select: called CC=90 SCAR=52.9
828 208 my $argv = {@_};
829  
830 208 ▶ 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 208 208
831  
832 ## testing buffer options
833 208 ▶ if (!defined($argv->{buffer})){}
Branch: 7 branches
BranchTrueFalseTotal
if (not defined $argv->{'buffer'}) { } 208 0 208
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 208 my @fields_work;
854 my %fields_distinct;
855 208 my %fields_aliases;
856  
857 208 ▶ if (defined($argv->{fields}))
Branch: 2 branches
BranchTrueFalseTotal
if (defined $argv->{'fields'}) { } 195 13 208
elsif (defined $self->{'argv'}{'tables'}) { } 6 7 13
858 {
859 195 my $fields_argv;
860 195 ▶ if (ref($argv->{fields}) eq "ARRAY") { $fields_argv = $argv->{fields}; }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'fields'} eq 'ARRAY') { } 184 11 195
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 195 ▶ if (@{$fields_argv} != 1 || $fields_argv->[0] ne "*")
Branch: 1 branch
BranchTrueFalseTotal
if (@{$fields_argv;} != 1 or $fields_argv->[0] ne "*") 192 3 195
Condition100%3/3
@{$fields_argv;} != 1 or $fields_argv->[0] ne "*"
l!l&&r!l&&!r
571353
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 192 ▶ for (my $ix=0; $ix < @{$fields_argv}; $ix++)
Branch: 1 branch
BranchTrueFalseTotal
if ($ix < @{$fields_argv;}) 275 175 450
870 {
871 275 my $field = $fields_argv->[$ix];
872 275 my $distinct;
873 my $alias;
874 275 ▶ if (ref($field) eq "HASH")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $field eq "HASH") 80 195 275
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 275 ▶ if ($field =~ /^distinct$/i)
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ /^distinct$/i) { } 3 272 275
elsif ($field =~ /^distinct\s+(.*)/i) { } 0 272 272
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 275 ▶ if (!($field =~ /^\\/))
Branch: 1 branch
BranchTrueFalseTotal
unless ($field =~ /^\\/) 272 3 275
894 {
895 272 ▶ my $value = ($field =~ /^(.*?)\((.*?)\,(.*)\)/) ? $2 : ($field =~ /^(.*?)\((.*)\)/) ? $2 : $field;
Branch: 2 branches
BranchTrueFalseTotal
$field =~ /^(.*?)\((.*?)\,(.*)\)/ ? : 1 271 272
$field =~ /^(.*?)\((.*)\)/ ? : 18 253 271
896 272 ▶ if ($value =~ /^(.*)\.(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(.*)\.(.*)$/) 129 143 272
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 258 ▶ push(@fields_work,$alias || $field);
Condition66%2/3
$alias || $field
l!l&&r!l&&!r
721860
MC/DC0%0/2
$alias || $field
$alias $field
Truth table66%2/3
A || B
A= $aliasB= $field
ABresult
1X1
011
000
906 258 ▶ $fields_distinct{$field} = 1 if ($distinct);
Branch: 1 branch
BranchTrueFalseTotal
if $distinct 3 255 258
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 191 my @group_work;
953 191 ▶ if (defined($argv->{group_by}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"group_by"}) 15 176 191
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 191 my @order_work;
966 191 ▶ if (defined($argv->{order_by}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"order_by"}) 42 149 191
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 191 ▶ my $middle = ($self->{init}{alias_with_as}) ? " AS " : " ";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'init'}{'alias_with_as'} ? : 0 191 191
983 191 my @fields;
984 191 my $table = $self->{work}{tables_inuse}[0];
985 191 ▶ if (@fields_work)
Branch: 1 branch
BranchTrueFalseTotal
if (@fields_work) { } 177 14 191
986 {
987 177 foreach my $field(@fields_work)
988 {
989 264 my $alias;
990 264 ▶ my $distinct = ($fields_distinct{$field}) ? "DISTINCT " : "";
Branch: 1 branch
BranchTrueFalseTotal
$fields_distinct{$field} ? : 3 261 264
991 ## field is hash?
992 264 ▶ if (defined($fields_aliases{$field}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields_aliases{$field}) 72 192 264
993 {
994 72 $alias = $fields_aliases{$field}{a};
995 72 $field = $fields_aliases{$field}{f};
996 }
997 ## is escape?
998 264 ▶ if ($field =~ /^\\(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^\\(.*)/) 3 261 264
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 261 my $field_a;
1007 my $field_b;
1008 261 ▶ if ($field =~ /^(.*?)\((.*?)\,(.*)\)/)
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ /^(.*?)\((.*?)\,(.*)\)/) { } 1 260 261
elsif ($field =~ /^(.*?)\((.*)\)/) { } 18 242 260
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 242 $field_a = "";
1023 242 $field_b = "";
1024 }
1025 ## translate field
1026 261 ▶ if ($field =~ /^(.*)\.(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^(.*)\.(.*)$/) { } 112 149 261
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 149 ▶ if (@{$self->{work}{tables_inuse}} == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'work'}{'tables_inuse'};} == 1) { } 123 26 149
1051 {
1052 123 my $realn = $self->_getAliasCols(2,$field,SQL_SIMPLE_ALIAS_SELECT);
1053 123 ▶ ($alias) ?
Branch: 2 branches
BranchTrueFalseTotal
$alias ? : 18 105 123
$field ne $realn ? : 54 51 105
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 191 my $where;
1092 191 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhere("select",$argv->{where},\$where));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhere("select", $argv->{"where"}, \$where) 0 191 191
1093  
1094 ## make group_by
1095 191 ▶ for (my $i=0; $i < @group_work; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @group_work) 22 191 213
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 191 my $having;
1104 191 ▶ return SQL_SIMPLE_RC_SYNTAX if ($self->_getWhere("select",$argv->{having},\$having));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_getWhere("select", $argv->{"having"}, \$having) 0 191 191
1105  
1106 ## make order
1107 191 my @order;
1108 191 ▶ while (@order_work)
Branch: 1 branch
BranchTrueFalseTotal
if (@order_work) 56 191 247
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 191 my @tables;
1123 191 foreach my $table(@{$self->{work}{tables_inuse}})
1124 {
1125 257 push(@tables,$self->_getAliasTable($table,$argv));
1126 }
1127  
1128 ## build sql command
1129 191 my $sql = "SELECT ".join(", ",@fields)." FROM ".join(", ",@tables);
1130 191 ▶ $sql .= " WHERE ".$where if ($where);
Branch: 1 branch
BranchTrueFalseTotal
if $where 66 125 191
1131 191 ▶ $sql .= " GROUP BY ".join(", ",@group_work) if (@group_work);
Branch: 1 branch
BranchTrueFalseTotal
if @group_work 15 176 191
1132 191 ▶ $sql .= " HAVING ".$having if ($having);
Branch: 1 branch
BranchTrueFalseTotal
if $having 4 187 191
1133 191 ▶ $sql .= " ORDER BY ".join(", ",@order) if (@order);
Branch: 1 branch
BranchTrueFalseTotal
if @order 42 149 191
1134 191 ▶ $sql .= " LIMIT ".$argv->{limit} if (defined($argv->{limit}) && $argv->{limit} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if defined $argv->{"limit"} and $argv->{"limit"} > 0 16 175 191
Condition100%3/3
defined $argv->{"limit"} and $argv->{"limit"} > 0
!ll&&!rl&&r
174116
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 191 $self->{work}{cursor_key_vs_hashkey} = 0;
1138 191 ▶ if (defined($argv->{buffer_hashkey}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $argv->{"buffer_hashkey"}) 0 191 191
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 191 ▶ ));
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"}) 191 0 191
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 268 ▶ my $self = shift;
Subroutine _Call: called CC=74 SCAR=84.4
1656 268 my $argv = {@_};
1657  
1658 268 $self->_setLastSQL($argv->{command});
1659  
1660 ## save command (call-sql_save is prior that new-sql_save
1661 268 ▶ 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 267 268
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
10267
defined $argv->{"sql_save"} and $argv->{"sql_save"}
!ll&&!rl&&r
26701
defined $self->{"argv"}{"sql_save"} and $self->{"argv"}{"sql_save"} and $argv->{"command_type"}
!ll&&!rl&&r
26700
defined $self->{"argv"}{"sql_save"} and $self->{"argv"}{"sql_save"}
!ll&&!rl&&r
244230
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 268 ▶ return SQL_SIMPLE_RC_ERROR if ($argv->{make_only});
Branch: 1 branch
BranchTrueFalseTotal
if $argv->{"make_only"} 268 0 268
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 40 ▶ my $self = shift;
Subroutine getWhere: called CC=3 SCAR=11.2
Pod documented
1996 40 my $argv = {@_};
1997  
1998 40 $self->{work}{tables_inuse} = [];
1999 40 ▶ if (ref($argv->{table}) eq "ARRAY"){ push(@{$self->{work}{tables_inuse}},@{$argv->{table}}); }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'table'} eq 'ARRAY') { } 9 31 40
elsif (ref $argv->{'table'} eq '') { } 31 0 31
2000 31 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 40 return $self->_getWhere("where",$argv->{where},$argv->{buffer});
2007 }
2008  
2009 sub _getWhere()
2010 {
2011 477 ▶ my $self = shift;
Subroutine _getWhere: called CC=3 SCAR=11.0
2012 477 my $command = shift;
2013 477 my $where = shift;
2014 477 my $buffer = shift;
2015  
2016 ## return dummy where
2017 477 ▶ return SQL_SIMPLE_RC_OK if (!$where);
Branch: 1 branch
BranchTrueFalseTotal
unless $where 342 135 477
2018  
2019 ## format where
2020 135 my @where_local;
2021 135 ▶ 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 135 135
2022  
2023 ## return the where clause
2024 135 ${$buffer} = join(" ",@where_local);
2025 135 return SQL_SIMPLE_RC_OK;
2026 }
2027  
2028 sub _getWhereRecursive()
2029 {
2030 159 ▶ my $self = shift;
Subroutine _getWhereRecursive: called CC=82 SCAR=48.6
2031 159 my $command = shift;
2032 159 my $level = shift;
2033 159 my $where = shift;
2034 159 my $buffer = shift;
2035  
2036 ## return error if argvs is empty, format error
2037 159 ▶ if ($where eq "")
Branch: 1 branch
BranchTrueFalseTotal
if ($where eq "") 0 159 159
2038 {
2039 0 $self->_setMessage($command,SQL_SIMPLE_RC_SYNTAX,"020");
2040 0 return SQL_SIMPLE_RC_SYNTAX;
2041 }
2042 159 ▶ if (ref($where) eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where eq "") 0 159 159
2043 {
2044 0 push(@{$buffer},$where);
2045 0 return 0;
2046 }
2047 ## return error if value1 is not array or value type
2048 159 ▶ if (ref($where) ne "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where ne "ARRAY") 0 159 159
2049 {
2050 0 $self->_setMessage($command,SQL_SIMPLE_RC_SYNTAX,"021");
2051 0 return SQL_SIMPLE_RC_SYNTAX;
2052 }
2053 ## format where
2054 159 my @where_tmp;
2055 159 my $oper_pend = 0;
2056 159 ▶ for (my $ix=0; $ix < @{$where};)
Branch: 1 branch
BranchTrueFalseTotal
if ($ix < @{$where;}) 225 158 383
2057 {
2058 225 ▶ undef(@where_tmp) if (@where_tmp && join('',@where_tmp) eq '');
Branch: 1 branch
BranchTrueFalseTotal
if @where_tmp and join("", @where_tmp) eq "" 1 224 225
Condition100%3/3
@where_tmp and join("", @where_tmp) eq ""
!ll&&!rl&&r
162621
MC/DC100%2/2
@where_tmp and join("", @where_tmp) eq ""
@where_tmp join("", @where_tmp) eq ""
Truth table100%3/3
A and B
A= @where_tmpB= join("", @where_tmp) eq ""
ABresult
0X0
100
111
2059  
2060 ###############################################################
2061 ## value1
2062  
2063 225 my $value1 = $where->[$ix++];
2064  
2065 225 ▶ if (ref($value1) ne "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value1 ne "") 24 201 225
2066 {
2067 24 my @where_aux;
2068 24 ▶ 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 24 24
2069  
2070 ## valida se requer AND/OR
2071 24 ▶ push(@where_tmp,"AND") if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 5 19 24
Condition66%2/3
$oper_pend and @where_tmp
!ll&&!rl&&r
1905
MC/DC50%1/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
Truth table66%2/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
2072 ## salva o where recursivo
2073 24 push(@where_tmp,join(" ",@where_aux));
2074 24 $oper_pend = 1;
2075 24 next;
2076 }
2077  
2078 ## check and/or logical connector
2079 201 ▶ if ($value1 =~ /^(and|\&\&|or|\|\|)$/i)
Branch: 1 branch
BranchTrueFalseTotal
if ($value1 =~ /^(and|\&\&|or|\|\|)$/i) 12 189 201
2080 {
2081 12 ▶ push(@where_tmp,uc($value1)) if ($oper_pend && @where_tmp);
Branch: 1 branch
BranchTrueFalseTotal
if $oper_pend and @where_tmp 10 2 12
Condition66%2/3
$oper_pend and @where_tmp
!ll&&!rl&&r
0210
MC/DC50%1/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
Truth table66%2/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
2082 12 $oper_pend = 0;
2083 12 next;
2084 }
2085  
2086 ## valida se requer AND/OR
2087 189 ▶ if ($oper_pend && @where_tmp)
Branch: 1 branch
BranchTrueFalseTotal
if ($oper_pend and @where_tmp) 37 152 189
Condition66%2/3
$oper_pend and @where_tmp
!ll&&!rl&&r
152037
MC/DC50%1/2
$oper_pend and @where_tmp
$oper_pend @where_tmp
Truth table66%2/3
A and B
A= $oper_pendB= @where_tmp
ABresult
0X0
100
111
2088 {
2089 37 push(@where_tmp,"AND");
2090 37 $oper_pend = 0;
2091 }
2092  
2093 ## process value if not escape
2094 189 ▶ if (!($value1 =~ /^\\(.*)/))
Branch: 1 branch
BranchTrueFalseTotal
if (not $value1 =~ /^\\(.*)/) { } 189 0 189
2095 {
2096 ## validate functions as arguments
2097 189 ▶ if ($self->_checkFunctions(\$value1,SQL_SIMPLE_ALIAS_WHERE))
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_checkFunctions(\$value1, 16)) { } 13 176 189
elsif (@{$self->{'work'}{'tables_inuse'};} == 1) { } 115 61 176
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 176 elsif (@{$self->{work}{tables_inuse}} == 1)
2101 {
2102 115 $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 189 ▶ if ($ix >= @{$where})
Branch: 1 branch
BranchTrueFalseTotal
if ($ix >= @{$where;}) 1 188 189
2126 {
2127 1 push(@where_tmp,$value1);
2128 1 last;
2129 }
2130  
2131 ###############################################################
2132 ## value2
2133  
2134 ## test value2, if required
2135 188 my $value2 = $where->[$ix++];
2136 188 my $quote = $self->{argv}{quote};
2137  
2138 188 $oper_pend = 1;
2139  
2140 ## value2 is array, multiple values
2141 188 ▶ if (ref($value2) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value2 eq "ARRAY") 53 135 188
2142 {
2143 53 my @_value2 = @{$value2};
2144 53 my $value2_b = "";
2145 53 my $value2_a = "";
2146 53 my $operator = $value2->[0];
2147 53 my $where_opr = "AND";
2148  
2149 ## value0 is escaped (not operator)
2150 53 ▶ if (!defined($operator)) { $operator = "="; }
Branch: 18 branches
BranchTrueFalseTotal
if (not defined $operator) { } 2 51 53
elsif ($operator =~ /^\\/) { } 1 50 51
elsif ($operator eq '=') { } 4 46 50
elsif ($operator eq '!') { } 16 30 46
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
2151 1 elsif ($operator =~ /^\\/) { $operator = "="; }
2152 4 elsif ($operator eq "=") { shift(@_value2); }
2153 16 elsif ($operator eq "!") { shift(@_value2); $operator = "!="; }
2154 0 elsif ($operator eq "!=") { shift(@_value2); $operator = "!="; }
2155 0 elsif ($operator eq "<>") { shift(@_value2); $operator = "!="; }
2156 0 elsif ($operator eq "<=") { shift(@_value2); }
2157 5 elsif ($operator eq "<") { shift(@_value2); }
2158 5 elsif ($operator eq ">=") { shift(@_value2); }
2159 5 elsif ($operator eq ">") { shift(@_value2); }
2160 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
2161 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
2162 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
2163 1 ▶ elsif ($operator eq "^^") { shift(@_value2); $operator = "LIKE"; $where_opr = "OR" if (@_value2 > 1); }
Branch: 1 branch
BranchTrueFalseTotal
if @_value2 > 1 0 1 1
2164 0 elsif ($operator eq "!%%") { shift(@_value2); $operator = "NOT LIKE"; $value2_b = "%"; $value2_a = "%"; }
2165 2 elsif ($operator eq "!^%") { shift(@_value2); $operator = "NOT LIKE"; $value2_b = "%"; }
2166 2 elsif ($operator eq "!%^") { shift(@_value2); $operator = "NOT LIKE"; $value2_a = "%"; }
2167 0 elsif ($operator eq "!^^") { shift(@_value2); $operator = "NOT LIKE"; }
2168 5 else { $operator = "="; }
2169  
2170 ## construct condition
2171 53 ▶ if ($operator eq "=" || $operator eq "!=")
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "=" or $operator eq "!=") 28 25 53
Condition100%3/3
$operator eq "=" or $operator eq "!="
l!l&&r!l&&!r
121625
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
2172 {
2173 28 ▶ if (@_value2 > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@_value2 > 1) 8 20 28
2174 {
2175 8 ▶ for (my $i=0; $i < @_value2; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_value2) 21 8 29
2176 {
2177 21 ▶ if (!defined($_value2[$i]))
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $_value2[$i]) { } 0 21 21
elsif ($_value2[$i] =~ /^\\(.*)/) { } 2 19 21
2178 {
2179 0 $_value2[$i] = 'NULL';
2180 }
2181 elsif ($_value2[$i] =~ /^\\(.*)/)
2182 {
2183 2 my $v = $1;
2184 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
2185 {
2186 2 $_value2[$i] = $v;
2187 }
2188 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
2189 {
2190 0 $_value2[$i] = $self->_getAliasCols(22,$v,SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN);
2191 }
2192 elsif (defined($self->{work}{field_alias}{$v}))
2193 {
2194 0 $_value2[$i] = $self->_getAliasCols(27,$self->{work}{field_alias}{$v},SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN);
2195 }
2196 else
2197 {
2198 0 $_value2[$i] = $v;
2199 }
2200 }
2201 else
2202 {
2203 19 $_value2[$i] = $quote.$self->_escapeQuote($_value2[$i]).$quote;
2204 }
2205 }
2206 8 $quote = "";
2207 8 ▶ my $not = ($operator eq "!=") ? " NOT" : "";
Branch: 1 branch
BranchTrueFalseTotal
$operator eq '!=' ? : 2 6 8
2208
2209 ## no _escapeQuote required, already done in value2 build
2210 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
2211 push(@where_tmp,$value1.$not." BETWEEN (".$quote.$_value2[0].$quote.",".$quote.$_value2[2].$quote.")"):
2212 push(@where_tmp,$value1.$not." IN (".$quote.join("$quote,$quote",@_value2).$quote.")");
2213 8 next;
2214 }
2215 }
2216  
2217 ## multiple conditions
2218 45 my @where_aux;
2219 45 foreach my $value(@_value2)
2220 {
2221 49 ▶ if (defined($value))
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value) { } 46 3 49
elsif ($operator eq '=') { } 0 3 3
2222 {
2223 46 ▶ if ($value =~ /^\\(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^\\(.*)/) { } 9 37 46
2224 {
2225 9 my $v = $1;
2226 9 ▶ if ($v =~ /^(\(SELECT\s+.*\))$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($v =~ /^(\(SELECT\s+.*\))$/) { } 2 7 9
elsif ($v =~ /^(.*?)\..*?$/ and grep /^$1$/, @{$$self{'work'}{'tables_valids'};}) { } 0 7 7
elsif (defined $self->{'work'}{'field_alias'}{$v}) { } 0 7 7
2227 {
2228 2 ▶ if ($operator eq "=") { push(@where_tmp,$value1." IN ".$1); }
Branch: 2 branches
BranchTrueFalseTotal
if ($operator eq '=') { } 0 2 2
elsif ($operator eq '!=') { } 2 0 2
2229 2 elsif ($operator eq "!=") { push(@where_tmp,$value1." NOT IN ".$1); }
2230 0 else { push(@where_tmp,$value1." ".$operator." ".$1); }
2231 }
2232 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
2233 {
2234 0 push(@where_aux,$value1." ".$operator." ".$self->_getAliasCols(23,$v,SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2235 }
2236 elsif (defined($self->{work}{field_alias}{$v}))
2237 {
2238 0 push(@where_aux,$value1." = ".$self->_getAliasCols(26,$self->{work}{field_alias}{$v},SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2239 }
2240 else
2241 {
2242 7 push(@where_aux,$value1." ".$operator." ".$v);
2243 }
2244 }
2245 else
2246 {
2247 37 push(@where_aux,$value1." ".$operator." ".$quote.$self->_escapeQuote($value2_a.$value.$value2_b).$quote);
2248 }
2249 }
2250 elsif ($operator eq "=")
2251 {
2252 0 push(@where_aux,$value1." IS NULL");
2253 }
2254 else
2255 {
2256 3 push(@where_aux,$value1." IS NOT NULL");
2257 }
2258 }
2259 45 ▶ if (@where_aux > 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@where_aux > 1) 6 39 45
2260 {
2261 6 $where_aux[0] = "(".$where_aux[0];
2262 6 $where_aux[@where_aux-1] .= ")";
2263 }
2264 45 ▶ push(@where_tmp,join(" ".$where_opr." ",@where_aux)) if (@where_aux);
Branch: 1 branch
BranchTrueFalseTotal
if @where_aux 41 4 45
2265 45 next;
2266 }
2267  
2268 ## value2 is single value
2269 135 ▶ if (!defined($value2))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value2) 3 132 135
2270 {
2271 3 push(@where_tmp,$value1." IS NULL");
2272 3 next;
2273 }
2274 132 ▶ if (ref($value2) eq "")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value2 eq "") 132 0 132
2275 {
2276 132 ▶ if ($value2 =~ /^\\(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($value2 =~ /^\\(.*)/) { } 29 103 132
2277 {
2278 29 my $v = $1;
2279 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
2280 {
2281 2 push(@where_tmp,$value1." IN ".$1);
2282 }
2283 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
2284 {
2285 15 push(@where_tmp,$value1." = ".$self->_getAliasCols(24,$v,SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2286 }
2287 elsif (defined($self->{work}{field_alias}{$v}))
2288 {
2289 1 push(@where_tmp,$value1." = ".$self->_getAliasCols(25,$self->{work}{field_alias}{$v},SQL_SIMPLE_ALIAS_WHERE+SQL_SIMPLE_ALIAS_FQDN));
2290 }
2291 else
2292 {
2293 11 push(@where_tmp,$value1." = ".$v);
2294 }
2295 }
2296 else
2297 {
2298 103 push(@where_tmp,$value1." = ".$quote.$self->_escapeQuote($value2).$quote);
2299 }
2300 132 next;
2301 }
2302  
2303 ## return error if value2 is not array or value type
2304 0 $self->_setMessage($command,SQL_SIMPLE_RC_SYNTAX,"028");
2305 0 return SQL_SIMPLE_RC_SYNTAX;
2306 }
2307 159 ▶ if (@where_tmp)
Branch: 1 branch
BranchTrueFalseTotal
if (@where_tmp) 158 1 159
2308 {
2309 158 push(@{$buffer},join(" ",@where_tmp));
2310 158 ▶ if ($level && @where_tmp > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($level and @where_tmp > 1) 14 144 158
Condition100%3/3
$level and @where_tmp > 1
!ll&&!rl&&r
135914
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
2311 {
2312 14 $buffer->[0] = "(".$buffer->[0];
2313 14 $buffer->[@{$buffer}-1] .= ")";
2314 }
2315 }
2316 159 return 0;
2317 }
2318  
2319 ##############################################################################
2320 ## action: get dbh entry point module
2321 ## return: current dbi drive pointer module
2322  
2323 sub getDBH()
2324 {
2325 0 ▶ return $_[0]->{init}{dbh};
Subroutine getDBH: not called CC=1 SCAR=6.9
Pod documented
2326 }
2327  
2328 ##############################################################################
2329 ## action: get last condition state
2330 ## return: last return code state
2331  
2332 sub getRC()
2333 {
2334 570 ▶ return $err;
Subroutine getRC: called CC=1 SCAR=0.0
Pod documented
2335 }
2336  
2337 ##############################################################################
2338 ## action: get last message state
2339 ## return: last system message
2340  
2341 sub getMessage()
2342 {
2343 17 ▶ return $errstr;
Subroutine getMessage: called CC=1 SCAR=0.0
Pod documented
2344 }
2345  
2346 ##############################################################################
2347 ## action: get number of extracted lines
2348 ## return: number of extracted lines
2349  
2350 sub getRows()
2351 {
2352 0 ▶ return $_[0]->{init}{rows};
Subroutine getRows: not called CC=1 SCAR=6.9
Pod documented
2353 }
2354  
2355 ##############################################################################
2356 ## action: get the last sql command
2357 ## return: last sql command
2358  
2359 sub getLastSQL()
2360 {
2361 285 ▶ return $_[0]->{init}{sql_command};
Subroutine getLastSQL: called CC=1 SCAR=0.0
Pod documented
2362 }
2363  
2364 ##############################################################################
2365 ## action: get the last cursor pointer
2366 ## return: cursor pointer
2367  
2368 sub getLastCursor()
2369 {
2370 0 ▶ my $self = shift;
Subroutine getLastCursor: not called CC=1 SCAR=6.9
Pod documented
2371 0 return %{$self->{init}{cursor}};
2372 }
2373  
2374 ##############################################################################
2375 ## action: get the last saved fileset
2376 ## return: last sql logfile
2377  
2378 sub getLastSave()
2379 {
2380 1 ▶ return $_[0]->{init}{sql_save_logfile};
Subroutine getLastSave: called CC=1 SCAR=0.0
Pod documented
2381 }
2382  
2383 ##############################################################################
2384 ## action: get the table's realname
2385 ## return: name of the table
2386  
2387 sub getAliasTable()
2388 {
2389 0 ▶ my $self = shift;
Subroutine getAliasTable: not called CC=1 SCAR=6.9
Pod documented
2390 0 return $self->_getAliasTable(@_,{schema=>defined($self->{init}{schema})});
2391 }
2392  
2393 sub _getAliasTable()
2394 {
2395 308 ▶ my $self = shift;
Subroutine _getAliasTable: called CC=2 SCAR=6.9
2396 308 my $table = shift;
2397 308 my $argv = shift;
2398  
2399 308 ▶ 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} 201 107 308
2400 107 return $self->_getSchemaName($argv).$table;
2401 }
2402  
2403 ##############################################################################
2404 ## action: get the schema name if required
2405 ## return: name of the schema
2406  
2407 sub _getSchemaName()
2408 {
2409 308 ▶ my $self = shift;
Subroutine _getSchemaName: called CC=3 SCAR=15.1
2410 308 my $argv = shift;
2411  
2412 308 ▶ return "" if (!$argv->{schema});
Branch: 1 branch
BranchTrueFalseTotal
unless $argv->{"schema"} 308 0 308
2413 0 ▶ return "" if (!defined($self->{argv}{schema}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"argv"}{"schema"} 0 0 0
2414 0 return $self->{argv}{schema}.".";
2415 }
2416  
2417 ##############################################################################
2418 ## action: get the table's realname
2419 ## return: name of the table
2420  
2421 sub getAliasCols()
2422 {
2423 0 ▶ my $self = shift;
Subroutine getAliasCols: not called CC=1 SCAR=6.9
Pod documented
2424 0 return $self->_getAliasCols(0,@_);
2425 }
2426  
2427 ##############################################################################
2428 # 0x01 - return col_real wo/table
2429  
2430 sub _getAliasCols()
2431 {
2432 636 ▶ my $self = shift;
Subroutine _getAliasCols: called CC=26 SCAR=32.6
2433 636 my $mycall = shift;
2434 636 my $field = shift;
2435 636 my $result = shift;
2436  
2437 636 my $_table;
2438 my $_field;
2439  
2440 ## enforce prefered aliases if defined
2441 636 ▶ $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 630 636
2442  
2443 ## field have ident?
2444 636 ▶ if ($field =~ /^(.*?)\.(.*?)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^(.*?)\.(.*?)$/) { } 306 330 636
2445 {
2446 306 $_table = $1;
2447 306 $_field = $2;
2448 306 ▶ if (defined($self->{work}{field_cols}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}) 78 228 306
2449 {
2450 78 ▶ if (defined($self->{work}{field_cols}{$_table}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'work'}{'field_cols'}{$_table}) { } 66 12 78
2451 {
2452 66 ▶ if (defined($self->{work}{field_cols}{$_table}{$_field}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}{$_table}{$_field}) 4 62 66
2453 {
2454 4 $_field = $self->{work}{field_cols}{$_table}{$_field};
2455 }
2456 }
2457 else
2458 {
2459 12 ▶ if (defined($self->{work}{tables_alias}{$_table}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"tables_alias"}{$_table}) 6 6 12
2460 {
2461 6 my $a = $self->{work}{tables_alias}{$_table};
2462 6 ▶ if (defined($self->{work}{field_cols}{$a}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}{$a}) 6 0 6
2463 {
2464 6 ▶ if (defined($self->{work}{field_cols}{$a}{$_field}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"field_cols"}{$a}{$_field}) 2 4 6
2465 {
2466 2 $_field = $self->{work}{field_cols}{$a}{$_field};
2467 }
2468 }
2469 }
2470 }
2471  
2472 }
2473 306 ▶ if (!grep(/^$_table$/,@{$self->{work}{tables_inuse}}))
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$_table$/, @{$$self{"work"}{"tables_inuse"};}) 104 202 306
2474 {
2475 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
2476 94 $_table = $self->{argv}{tables}{$_table}{name};
2477 }
2478 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
2479 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
2480 }
2481 else
2482 {
2483 330 $_field = $field;
2484  
2485 ## single table in use?
2486 330 ▶ if (@{$self->{work}{tables_inuse}} == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'work'}{'tables_inuse'};} == 1) { } 294 36 330
2487 {
2488 294 $_table = $self->{work}{tables_inuse}[0];
2489 294 ▶ $_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} 107 187 294
Condition100%3/3
defined $self->{"work"}{"tables_alias"}{$_table} and defined $self->{"argv"}{"tables"}{$self->{"work"}{"tables_alias"}{$_table}}{"cols"}{$_field}
!ll&&!rl&&r
16126107
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
2490 }
2491
2492 ## scan contents
2493 else
2494 {
2495 36 foreach my $t(@{$self->{work}{tables_inuse}})
2496 {
2497 ## ignore table if field not found
2498 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
2499  
2500 ## returns field as is if duplicated
2501 56 ▶ return $field if ($_table);
Branch: 1 branch
BranchTrueFalseTotal
if $_table 28 28 56
2502  
2503 ## define the table by alias
2504 28 $_table = $t;
2505 }
2506 }
2507 }
2508 598 ▶ if ($_table && $result & SQL_SIMPLE_ALIAS_FQDN)
Branch: 1 branch
BranchTrueFalseTotal
if ($_table and $result & 32768) 232 366 598
Condition100%3/3
$_table and $result & 32768
!ll&&!rl&&r
8358232
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
2509 {
2510 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
2511 232 return $_table.".".$_field;
2512 }
2513 366 return $_field;
2514 }
2515  
2516 ################################################################################
2517 ## action: validate functions and convert the fields named
2518  
2519 sub _checkFunctions()
2520 {
2521 240 ▶ my $self = shift;
Subroutine _checkFunctions: called CC=9 SCAR=22.0
2522 240 my $value1 = shift;
2523 240 my $result = shift;
2524  
2525 ## test if value is function
2526 240 my $fnc;
2527 240 my $op1 = ${$value1};
2528 240 my $op2 = '';
2529 240 my $lvl;
2530 240 ▶ while (($op1 =~ /^(.*?)\((.*)\)(.*)\)$/) || ($op1 =~ /^(.*?)\((.*)\)$/))
Branch: 1 branch
BranchTrueFalseTotal
if ($op1 =~ /^(.*?)\((.*)\)(.*)\)$/ or $op1 =~ /^(.*?)\((.*)\)$/) 15 240 255
Condition100%3/3
$op1 =~ /^(.*?)\((.*)\)(.*)\)$/ or $op1 =~ /^(.*?)\((.*)\)$/
l!l&&r!l&&!r
213240
MC/DC100%2/2
$op1 =~ /^(.*?)\((.*)\)(.*)\)$/ or $op1 =~ /^(.*?)\((.*)\)$/
$op1 =~ /^(.*?)\((.*)\)(.*)\)$/ $op1 =~ /^(.*?)\((.*)\)$/
Truth table100%3/3
A or B
A= $op1 =~ /^(.*?)\((.*)\)(.*)\)$/B= $op1 =~ /^(.*?)\((.*)\)$/
ABresult
1X1
011
000
2531 {
2532 15 $lvl++;
2533 15 $fnc .= $1."(";
2534 15 ▶ $op1 = $2.((defined($3)) ? ")" : "");
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 2 13 15
2535 15 ▶ $op2 .= (defined($3)) ? ")".$3 : ")";
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 2 13 15
2536 }
2537  
2538 ## process functions if mapped
2539 240 ▶ if ($lvl)
Branch: 1 branch
BranchTrueFalseTotal
if ($lvl) 13 227 240
2540 {
2541 13 ▶ if ($op1 =~ /^(.*?)\,(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($op1 =~ /^(.*?)\,(.*)$/) { } 2 11 13
2542 {
2543 2 my $o1 = $1;
2544 2 my $o2 = $2;
2545 2 ▶ if ($o1 =~ /^.*?\..*?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($o1 =~ /^.*?\..*?$/) { } 0 2 2
2546 {
2547 0 $op1 = $self->_getAliasCols(15,$o1,$result+SQL_SIMPLE_ALIAS_FQDN);
2548 }
2549 else
2550 {
2551 2 $op1 = $self->_getAliasCols(16,$o1,$result);
2552 }
2553 2 $op1 .= ",".$o2;
2554 }
2555 else
2556 {
2557 11 ▶ if ($op1 =~ /^.*?\..*?$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($op1 =~ /^.*?\..*?$/) { } 2 9 11
2558 {
2559 2 $op1 = $self->_getAliasCols(17,$op1,$result+SQL_SIMPLE_ALIAS_FQDN);
2560 }
2561 else
2562 {
2563 9 $op1 = $self->_getAliasCols(18,$op1,$result);
2564 }
2565 }
2566 13 ${$value1} = $fnc.$op1.$op2;
2567 }
2568 240 return $lvl;
2569 }
2570  
2571 ################################################################################
2572 ## action: test the argv->{table} and create the tables_inuse list
2573  
2574 sub _checkTablesEntries()
2575 {
2576 285 ▶ my $self = shift;
Subroutine _checkTablesEntries: called CC=13 SCAR=27.4
2577 285 my $cmnd = shift;
2578 285 my $argv = shift;
2579  
2580 ## tables is missing?
2581 285 ▶ if (!defined($argv->{table}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argv->{"table"}) 0 285 285
2582 {
2583 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"005");
2584 0 return SQL_SIMPLE_RC_SYNTAX;
2585 }
2586  
2587 ## validate tables
2588 285 my $tables_work;
2589 285 ▶ if (ref($argv->{table}) eq "")
Branch: 2 branches
BranchTrueFalseTotal
if (ref $argv->{'table'} eq '') { } 199 86 285
elsif (ref $argv->{'table'} eq 'ARRAY' and $self->{'work'}{'command'} == 8 || $self->{'work'}{'command'} == 2) { } 86 0 86
2590 {
2591 199 $tables_work = [$argv->{table}];
2592 }
2593 ▶ 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
2594 {
2595 86 $tables_work = $argv->{table};
2596 }
2597 else
2598 {
2599 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"006");
2600 0 return SQL_SIMPLE_RC_SYNTAX;
2601 }
2602  
2603 ## assign table as in use
2604 285 $self->{work}{tables_valids} = [];
2605 285 foreach my $table(@{$tables_work})
2606 {
2607 371 ▶ if (grep(/^$table$/,@{$self->{work}{tables_inuse}}))
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$table$/, @{$$self{"work"}{"tables_inuse"};}) 0 371 371
2608 {
2609 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"033",$table);
2610 0 return SQL_SIMPLE_RC_SYNTAX;
2611 }
2612 371 ▶ if (defined($self->{argv}{tables}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"argv"}{"tables"}) 309 62 371
2613 {
2614 ## defined as alias in content tables?
2615 309 ▶ 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'}) { } 159 150 309
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
1500159
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
2616 {
2617 159 my $realname = $self->{argv}{tables}{$table}{name};
2618 159 ▶ if (defined($self->{work}{tables_alias}{$realname}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"work"}{"tables_alias"}{$realname}) 0 159 159
2619 {
2620 0 $self->_setMessage($cmnd,SQL_SIMPLE_RC_SYNTAX,"033",$table);
2621 0 return SQL_SIMPLE_RC_SYNTAX;
2622 }
2623 159 push(@{$self->{work}{tables_inuse}},$realname);
2624 159 $self->{work}{tables_alias}{$realname} = $table;
2625 159 push(@{$self->{work}{tables_valids}},$table);
2626 159 next;
2627 }
2628 elsif (defined($self->{init}{table_realname}{$table}))
2629 {
2630 70 $self->{work}{tables_alias}{$table} = $self->{init}{table_realname}{$table};
2631 70 push(@{$self->{work}{tables_valids}},$self->{init}{table_realname}{$table});
2632 }
2633 }
2634 212 push(@{$self->{work}{tables_inuse}},$table);
2635 }
2636 285 push(@{$self->{work}{tables_valids}},@{$self->{work}{tables_inuse}});
2637 285 return SQL_SIMPLE_RC_OK;
2638 }
2639  
2640 ################################################################################
2641 ## action: set last command sql
2642 ## return: none
2643  
2644 sub _setLastSQL()
2645 {
2646 555 ▶ $_[0]->{init}{sql_command} = $_[1];
Subroutine _setLastSQL: called CC=1 SCAR=0.0
2647 }
2648  
2649 ################################################################################
2650 ## action: set commit
2651 ## return: old commit
2652  
2653 sub _setCommit()
2654 {
2655 0 ▶ my $self = shift;
Subroutine _setCommit: not called CC=2 SCAR=17.9
2656 0 my $save = $self->{argv}{commit};
2657 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
2658 0 return $save;
2659 }
2660  
2661 ################################################################################
2662 ## action: set message_log
2663 ## return: old message_log
2664  
2665 sub _setLogMessage()
2666 {
2667 0 ▶ my $self = shift;
Subroutine _setLogMessage: not called CC=2 SCAR=17.9
2668 0 my $save = $self->{argv}{message_log};
2669 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
2670 0 return $save;
2671 }
2672  
2673 ################################################################################
2674 ## action: set sql_save
2675 ## return: old sql_save
2676  
2677 sub _setSqlSave()
2678 {
2679 2 ▶ my $self = shift;
Subroutine _setSqlSave: called CC=2 SCAR=6.9
2680 2 my $save = $self->{argv}{sql_save};
2681 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
2682 2 return $save;
2683 }
2684  
2685 ################################################################################
2686 ## action: set quote character
2687 ## return: old quote chacracter
2688  
2689 sub _setQuote()
2690 {
2691 0 ▶ my $self = shift;
Subroutine _setQuote: not called CC=5 SCAR=34.0
2692 0 my $quote = shift;
2693 0 my $save = $self->{argv}{quote};
2694 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
2695 0 return $save;
2696 }
2697  
2698 ################################################################################
2699 ## action: escape quote in string
2700 ## return: string with escape (if exists)
2701  
2702 sub _escapeQuote()
2703 {
2704 239 ▶ my $self = shift;
Subroutine _escapeQuote: called CC=2 SCAR=7.0
2705 239 my $value = shift;
2706
2707 ## return if not quote
2708 239 ▶ return $value if ($self->{argv}{quote} eq "");
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"argv"}{"quote"} eq "" 0 239 239
2709
2710 ## escape and return
2711 239 $value =~ s/$self->{argv}{quote}/\\$self->{argv}{quote}/g;
2712 239 return $value;
2713 }
2714  
2715 ################################################################################
2716 ## action: cleanup the last session call
2717 ## return: return code
2718  
2719 sub _resetSession()
2720 {
2721 287 ▶ my $self = shift;
Subroutine _resetSession: called CC=1 SCAR=0.0
2722 287 $err = 0;
2723 287 $errstr = "";
2724 287 $self->_setLastSQL("");
2725 287 delete ($self->{work});
2726 287 $self->{work} = {};
2727 }
2728  
2729 ################################################################################
2730 ## action: set message state
2731 ## return: return code
2732  
2733 sub _setMessage()
2734 {
2735 21 ▶ my $self = shift;
Subroutine _setMessage: called CC=14 SCAR=38.1
2736 21 my $command = shift;
2737 21 my $rc = shift;
2738 21 my $code = shift;
2739 21 my @argv = @_;
2740  
2741 21 ▶ if (!defined($rc))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rc) 4 17 21
2742 {
2743 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
2744 4 ▶ return $self->_setMessage($command,$DBI::err+0,"099",$DBI::errstr) if ($DBI::err);
Branch: 1 branch
BranchTrueFalseTotal
if $DBI::err 0 4 4
2745  
2746 4 $err = 0;
2747 4 $errstr = "";
2748 4 return $err;
2749 }
2750  
2751 17 $err = $rc;
2752 $errstr = (defined($SQL_SIMPLE_TABLE_OF_MSGS{$code})) ?
2753 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
2754 "999S [message] invalid message code '$code'";
2755  
2756 17 ▶ if ($self->{argv}{message_log})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"message_log"}) 0 17 17
2757 {
2758 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
2759  
2760 0 ▶ if ($self->{argv}{message_log} & SQL_SIMPLE_LOG_SYS)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"argv"}{"message_log"} & 1) 0 0 0
2761 {
2762 0 require Sys::Syslog;
2763 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
2764 syslog(
2765 ($SQL_SIMPLE_TABLE_OF_MSGS{$code}{T} eq "E") ? "error" :
2766 ($SQL_SIMPLE_TABLE_OF_MSGS{$code}{T} eq "S") ? "error" :
2767 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
2768 "info",
2769 $errstr
2770 );
2771 0 closelog();
2772 }
2773 }
2774 17 return $err;
2775 }
2776  
2777 ################################################################################
2778 ## action: enable/disable show dumper data at each call
2779 ## note: used for debug mode only.
2780  
2781 sub setDumper()
2782 {
2783 279 ▶ my $self = shift;
Subroutine setDumper: called CC=1 SCAR=0.0
Pod documented
2784 279 return $self->{init}{dumper} = shift;
2785 }
2786  
2787 sub _Dumper()
2788 {
2789 286 ▶ my $self = shift;
Subroutine _Dumper: called CC=2 SCAR=10.8
2790 286 my $call = shift;
2791 286 my $argv = shift;
2792  
2793 286 ▶ return if (!$self->{init}{dumper});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"init"}{"dumper"} 286 0 286
2794  
2795 0 require Data::Dumper;
2796 0 ▶ $Data::Dumper::Sortkeys = \sub { my ($hash) = @_; return [ (sort keys %$hash) ]; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
2797  
2798 0 my $dumper = new Data::Dumper([$argv]);
2799  
2800 0 $dumper->Terse(1);
2801  
2802 0 print STDERR $call." = ".$dumper->Dump;
2803 }
2804  
2805 __END__
↑ Summary SimpleOps/DBI/MySQL.pm »