lib/DB/Object/Statement.pm

filter: Statementstmt 17.6% 136 / 770 Branchbran 8.1% 41 / 502 Conditioncond 4.6% 19 / 413 MC/DCmcdc 0.0% 0 / 215 Subroutinesub 32.3% 23 / 71 Podpod 89.8% 44 / 49 totaltotal 13.0% 263 / 2020 CC 413 SCAR 80.4
CC
413
Cov
12%
execute
8747.3
join
4970.0
__ANON__
506.0
CRAP 3107.6
↑ Summary lib/DB/Object/Query.pm »
1 # -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## SQL API Abstraction - ~/lib/DB/Object/Statement.pm
4 ## Version v0.10.1
5 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2017/07/19
8 ## Modified 2026/10/01
9 ## All rights reserved
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 ## This package's purpose is to automatically terminate the statement object and
15 ## separate them from the connection object (DB::Object).
16 ## Connection object last longer than statement objects
17 ##----------------------------------------------------------------------------
18 package DB::Object::Statement;
19 BEGIN
20 3 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 warnings::register_categories( 'DB::Object' );
24 3 ▶ use parent qw( DB::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶ use vars qw( $VERSION $DEBUG $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶ use Class::Struct qw( struct );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 our $DEBUG = 0;
30 3 our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
31 3 our $VERSION = 'v0.10.1';
32 };
33  
34 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 sub init
38 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
39 0 my $self = shift( @_ );
40 0 $self->{_exception_class} = $EXCEPTION_CLASS;
41 0 ▶ $self->Module::Generic::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->Module::Generic::init(@_) or return $self->pass_error 0 0 0
42 0 return( $self );
43 }
44  
45 sub as_string
46 0 ▶{
Subroutine as_string: not called CC=2 SCAR=17.9
Pod documented
47 0 my $self = shift( @_ );
48 # my $q = $self->_query_object_current;
49 # used by select, insert, update, delete to flag that we need to reformat the query
50 0 $self->{as_string}++;
51 0 ▶ if( my $qo = $self->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $qo = $self->query_object) 0 0 0
52 {
53 0 $qo->final(1);
54 }
55 # return( $self->{sth}->{Statement} );
56 # Same:
57 # return( $q->as_string );
58 0 return( $self->{query} );
59 }
60  
61 sub attach
62 0 ▶{
Subroutine attach: not called CC=11 SCAR=48.8
Pod documented
63 0 my $self = shift( @_ );
64 0 ▶ my $dbo = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No DB::Object object was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No DB::Object object was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
65 return( $self->error( "No DB::Object object was provided." ) );
66 0 my $base_class = $self->base_class;
67 0 ▶ unless( $self->_is_a( $dbo => $base_class ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($dbo, $base_class)) 0 0 0
68 {
69 0 return( $self->error( "Value provided is not a ${base_class} object." ) );
70 }
71 0 $self->debug( $dbo->debug );
72 0 ▶ $self->database_object( $dbo ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->database_object($dbo) or return $self->pass_error 0 0 0
73 0 ▶ if( my $tbl = $self->table_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $tbl = $self->table_object) 0 0 0
74 {
75 0 ▶ if( $self->_is_a( $tbl => "${base_class}::Tables" ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($tbl, "${base_class}::Tables")) { } 0 0 0
76 {
77 0 ▶ $self->_load_class( "${base_class}::Tables" ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("${base_class}::Tables") or return $self->pass_error 0 0 0
78 0 $tbl->attach( $dbo );
79 }
80 else
81 {
82 0 ▶ warn( "Table object found (", $self->_str_val( $tbl ), ") in this statement object is actually not a table object (${base_class}::Tables) !" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
83 0 $self->table_object( undef );
84 }
85 }
86 0 ▶ if( my $qo = $self->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if (my $qo = $self->query_object) 0 0 0
87 {
88 0 ▶ unless( $self->_is_a( $qo => "${base_class}::Query" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($qo, "${base_class}::Query")) 0 0 0
89 {
90 0 die( "Query object found (", $self->_str_val( $qo ), ") in this statement object is actually not a query object (${base_class}::Query) !" );
91 }
92 0 ▶ $self->_load_class( "${base_class}::Query" ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("${base_class}::Query") or return $self->pass_error 0 0 0
93 0 $qo->attach( $dbo );
94 }
95 0 return( $self );
96 }
97  
98 sub bind_param
99 0 ▶{
Subroutine bind_param: not called CC=4 SCAR=30.0
Pod documented
100 0 my $self = shift( @_ );
101 0 my( $pack, $file, $line ) = caller();
102 0 my $sub = ( caller(1) )[3];
103 0 $self->{pack} = $pack;
104 0 $self->{file} = $file;
105 0 $self->{line} = $line;
106 0 $self->{sub} = $sub;
107 my $rc = eval
108 0 {
109 0 $self->{sth}->bind_param( @_ );
110 };
111 0 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif ($rc) { } 0 0 0
112 {
113 0 my $err = $self->errstr();
114 0 $err =~ s/ at line \d+.*$//;
115 # printf( STDERR "%s in %s at line %d within sub '%s'.\n", $err, $self->{file}, $self->{line}, $self->{sub} );
116 # exit(1);
117 0 return( $self->error( $err ) );
118 }
119 elsif( $rc )
120 {
121 0 return( $rc );
122 }
123 else
124 {
125 0 ▶ my $err = $@ = $self->{sth}->errstr() || "Unknown error while binding parameters to query.";
Condition0%0/2
$self->{'sth'}->errstr || 'Unknown error while binding parameters to query.'
l!l
00
MC/DC0%0/1
$self->{'sth'}->errstr || 'Unknown error while binding parameters to query.'
$self->{'sth'}->errstr
Truth table0%0/2
A
A= $self->{'sth'}->errstr
Aresult
11
00
126 0 return( $self->error( $err ) );
127 }
128 }
129  
130 sub clone
131 0 ▶{
Subroutine clone: not called CC=11 SCAR=48.8
Pod documented
132 0 my $self = shift( @_ );
133 # We make sure to not clone the DBI database handle object
134 0 my $dbo = CORE::delete( $self->{dbo} );
135 0 my( $tbl, $tbl_dbo, $qo, $query_dbo );
136 0 ▶ if( $tbl = $self->table_object )
Branch: 1 branch
BranchTrueFalseTotal
if ($tbl = $self->table_object) 0 0 0
137 {
138 0 $tbl_dbo = CORE::delete( $tbl->{dbo} );
139 }
140 0 ▶ if( $qo = $self->query_object )
Branch: 1 branch
BranchTrueFalseTotal
if ($qo = $self->query_object) 0 0 0
141 {
142 0 $query_dbo = CORE::delete( $qo->{database_object} );
143 }
144 0 ▶ my $new = $self->Module::Generic::clone ||
Condition0%0/2
$self->Module::Generic::clone || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->Module::Generic::clone || (return $self->pass_error)
$self->Module::Generic::clone
Truth table0%0/2
A
A= $self->Module::Generic::clone
Aresult
11
00
145 return( $self->pass_error );
146 0 ▶ $new->attach( $dbo ) if( defined( $dbo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbo 0 0 0
147 0 ▶ $tbl->attach( $tbl_dbo ) if( defined( $tbl_dbo ) && ( !$dbo || $tbl_dbo ne $dbo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $tbl_dbo and !$dbo || $tbl_dbo ne $dbo 0 0 0
Condition0%0/6
defined $tbl_dbo and !$dbo || $tbl_dbo ne $dbo
!ll&&!rl&&r
000
not $dbo or $tbl_dbo ne $dbo
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $tbl_dbo and !$dbo || $tbl_dbo ne $dbo
defined $tbl_dbo not $dbo $tbl_dbo ne $dbo
Truth table0%0/4
A and not(B) or C
A= defined $tbl_dboB= not $dboC= $tbl_dbo ne $dbo
ABCresult
0XX0
1000
11X1
1011
148 0 ▶ $qo->attach( $query_dbo ) if( defined( $query_dbo ) && ( !$dbo || $query_dbo ne $dbo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $query_dbo and !$dbo || $query_dbo ne $dbo 0 0 0
Condition0%0/6
defined $query_dbo and !$dbo || $query_dbo ne $dbo
!ll&&!rl&&r
000
not $dbo or $query_dbo ne $dbo
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $query_dbo and !$dbo || $query_dbo ne $dbo
defined $query_dbo not $dbo $query_dbo ne $dbo
Truth table0%0/4
A and not(B) or C
A= defined $query_dboB= not $dboC= $query_dbo ne $dbo
ABCresult
0XX0
1000
11X1
1011
149 0 return( $new );
150 }
151  
152 sub commit
153 0 ▶{
Subroutine commit: not called CC=6 SCAR=37.4
Pod documented
154 0 my $self = shift( @_ );
155 0 ▶ if( $self->{sth} && $self->param( 'autocommit' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sth"} and $self->param("autocommit")) 0 0 0
Condition0%0/3
$self->{"sth"} and $self->param("autocommit")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"sth"} and $self->param("autocommit")
$self->{"sth"} $self->param("autocommit")
Truth table0%0/3
A and B
A= $self->{"sth"}B= $self->param("autocommit")
ABresult
0X0
100
111
156 {
157 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
158 return( $self->error( "No database handle could be found." ) );
159 0 ▶ my $sth = $dbo->prepare( 'COMMIT' ) || return( $self->pass_error( $dbo->error ) );
Condition0%0/2
$dbo->prepare('COMMIT') || (return $self->pass_error($dbo->error))
l!l
00
MC/DC0%0/1
$dbo->prepare('COMMIT') || (return $self->pass_error($dbo->error))
$dbo->prepare('COMMIT')
Truth table0%0/2
A
A= $dbo->prepare('COMMIT')
Aresult
11
00
160 0 ▶ $sth->execute() || return( $self->error( "An error occurred while executing query: ", $sth->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("An error occurred while executing query: ", $sth->error) 0 0 0
161 0 $sth->finish();
162 }
163 0 return( $self );
164 }
165  
166 2 ▶sub database_object { return( shift->_set_get_object_without_init( 'dbo', 'DB::Object', @_ ) ); }
Subroutine database_object: called CC=1 SCAR=0.0
Pod documented
167  
168 sub distinct
169 0 ▶{
Subroutine distinct: not called CC=7 SCAR=40.3
Pod documented
170 0 my $self = shift( @_ );
171 my $query = $self->{query} ||
172 0 ▶ return( $self->error( "No query to set as to be ignored." ) );
Condition0%0/2
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
l!l
00
MC/DC0%0/1
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
$self->{'query'}
Truth table0%0/2
A
A= $self->{'query'}
Aresult
11
00
173  
174 0 my $type = uc( ( $query =~ /^\s*(\S+)\s+/ )[0] );
175 # ALTER for table alteration statements (DB::Object::Tables
176 0 my @allowed = qw( SELECT );
177 0 my $allowed = CORE::join( '|', @allowed );
178 0 ▶ if( !scalar( grep{ /^$type$/i } @allowed ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep({/^$type$/i;} @allowed)) 0 0 0
179 {
180 0 return( $self->error( "You may not flag statement of type \U$type\E to be distinct:\n$query" ) );
181 }
182 # Incompatible. Do not bother going further
183 0 ▶ return( $self ) if( $query =~ /^\s*(?:$allowed)\s+(?:DISTINCT|DISTINCTROW|ALL)\s+/i );
Branch: 1 branch
BranchTrueFalseTotal
if $query =~ /^\s*(?:$allowed)\s+(?:DISTINCT|DISTINCTROW|ALL)\s+/i 0 0 0
184  
185 0 $query =~ s/^(\s*)($allowed)(\s+)/$1$2 DISTINCT /;
186 # my $sth = $self->prepare( $query ) ||
187 # $self->{ 'query' } = $query;
188 # saving parameters to bind later on must have been done previously
189 0 ▶ my $sth = $self->_cache_this( $query ) ||
Condition0%0/2
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
l!l
00
MC/DC0%0/1
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
$self->_cache_this($query)
Truth table0%0/2
A
A= $self->_cache_this($query)
Aresult
11
00
190 return( $self->error( "Error while preparing new ignored query:\n$query" ) );
191 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
192 {
193 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing new ignored query:\n$query") 0 0 0
194 return( $self->error( "Error while executing new ignored query:\n$query" ) );
195 }
196 0 return( $sth );
197 }
198  
199 sub dump
200 0 ▶{
Subroutine dump: not called CC=11 SCAR=48.8
Pod documented
201 0 my $self = shift( @_ );
202 0 my $file = shift( @_ );
203 0 ▶ if( $file )
Branch: 2 branches
BranchTrueFalseTotal
if ($file) { } 0 0 0
elsif (exists $self->{'sth'}) { } 0 0 0
204 {
205 # Used to be handled by SQL server
206 # my $query = $self->as_string();
207 # $query =~ s/(\s+FROM\s+)/ INTO OUTFILE '$file'$1/;
208 # my $sth = $self->prepare( $query ) ||
209 # return( $self->error( "Error while preparing query to dump result on select:\n$query" ) );
210 # $sth->execute() ||
211 # return( $self->error( "Error while executing query to dump result on select:\n$query" ) );
212 0 ▶ $self->_load_class( 'DateTime::Lite' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime::Lite") or return $self->pass_error 0 0 0
213 0 my $fields = $self->{_fields};
214 0 my @header = sort{ $fields->{ $a } <=> $fields->{ $b } } keys( %$fields );
215 # new_file is inherited from Module::Generic
216 0 $file = $self->new_file( $file );
217 0 ▶ my $io = $file->open( '>', { binmode => 'utf8' }) ||
Condition0%0/2
$file->open('>', {'binmode', 'utf8'}) || (return $self->error("Unable to open file '${file}' in write mode: ", $file->error))
l!l
00
MC/DC0%0/1
$file->open('>', {'binmode', 'utf8'}) || (return $self->error("Unable to open file '${file}' in write mode: ", $file->error))
$file->open('>', {'binmode', 'utf8'})
Truth table0%0/2
A
A= $file->open('>', {'binmode', 'utf8'})
Aresult
11
00
218 return( $self->error( "Unable to open file '$file' in write mode: ", $file->error ) );
219 0 ▶ $self->_load_class( 'DateTime::Lite' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime::Lite") or return $self->pass_error 0 0 0
220 return( $self->pass_error );
221 0 my $date = DateTime::Lite->now;
222 0 my $table = $self->{table};
223 0 $io->printf( "## Generated on %s for table $table\n", $date->strftime( '%c' ) );
224 0 $io->print( "## ", CORE::join( "\t", @header ), "\n" );
225 0 my @data = ();
226 0 ▶ while( @data = $self->fetchrow() )
Branch: 1 branch
BranchTrueFalseTotal
if (@data = $self->fetchrow) 0 0 0
227 {
228 0 print( $io CORE::join( "\t", @data ), "\n" );
229 }
230 0 $io->close;
231 0 $self->finish;
232 0 return( $self );
233 }
234 elsif( exists( $self->{sth} ) )
235 {
236 # my $fields = $self->{ '_fields' };
237 0 my @fields = @{ $self->{sth}->FETCH( 'NAME' ) };
238 0 my $max = 0;
239 # foreach my $field ( keys( %$fields ) )
240 0 foreach my $field ( @fields )
241 {
242 0 ▶ $max = length( $field ) if( length( $field ) > $max );
Branch: 1 branch
BranchTrueFalseTotal
if length $field > $max 0 0 0
243 }
244 0 my $template = '';
245 ## foreach my $field ( sort{ $fields->{ $a } <=> $fields->{ $b } } keys( %$fields ) )
246 0 foreach my $field ( @fields )
247 {
248 0 $template .= "$field" . ( '.' x ( $max - length( $field ) ) ) . ": %s\n";
249 }
250 0 $template .= "\n";
251 0 my @data = ();
252 0 ▶ while( @data = $self->fetchrow() )
Branch: 1 branch
BranchTrueFalseTotal
if (@data = $self->fetchrow) 0 0 0
253 {
254 0 printf( STDERR $template, @data );
255 }
256 0 $self->finish;
257 0 return( $self );
258 }
259 else
260 {
261 0 return( $self->error( "No query to dump." ) );
262 }
263 }
264  
265 0 ▶sub exec { return( shift->execute( @_ ) ); }
Subroutine exec: not called CC=1 SCAR=6.9
Pod documented
266  
267 sub execute
268 1 ▶{
Subroutine execute: called CC=127 SCAR=90.8
Pod documented
269 1 my $self = shift( @_ );
270 1 my @args = @_;
271 # Resolve caller context only when needed for error reporting or debug.
272 # Calling caller() unconditionally on every execute() is expensive.
273 1 ▶ if( $self->debug || !$self->{pack} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug or not $self->{"pack"}) 1 0 1
Condition33%1/3
$self->debug or not $self->{"pack"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->debug or not $self->{"pack"}
$self->debug not $self->{"pack"}
Truth table33%1/3
A or not(B)
A= $self->debugB= not $self->{"pack"}
ABresult
1X1
011
000
274 {
275 1 my( $pack, $file, $line ) = caller();
276 1 my $sub = ( caller(1) )[3];
277 # What we want is to get the point from where we were originatly called
278 1 my $class = 'DB::Object';
279 1 ▶ if( substr( $pack, 0, length( $class ) ) eq $class )
Branch: 1 branch
BranchTrueFalseTotal
if (substr($pack, 0, length $class) eq $class) 1 0 1
280 {
281 1 ▶ for( my $i = 1; $i < 5; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 5) 2 0 2
282 {
283 2 ( $pack, $file, $line ) = caller( $i );
284 2 $sub = ( caller( $i + 1 ) )[3];
285 2 ▶ last if( substr( $pack, 0, length( $class ) ) ne $class );
Branch: 1 branch
BranchTrueFalseTotal
if substr($pack, 0, length $class) ne $class 1 1 2
286 }
287 }
288 1 $self->{pack} = $pack;
289 1 $self->{file} = $file;
290 1 $self->{line} = $line;
291 1 $self->{sub} = $sub;
292 }
293 1 ▶ my $dbo = $self->database_object ||
Condition50%1/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
10
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table50%1/2
A
A= $self->database_object
Aresult
11
00
294 return( $self->error( "No database handle could be found." ) );
295 1 $self->{executed}++;
296 1 my $q = $self->query_object;
297 1 ▶ $q->final(1) if( $q );
Branch: 1 branch
BranchTrueFalseTotal
if $q 0 1 1
298 1 my @binded = ();
299 1 my @binded_types = ();
300 # Boolean used so we do not automatically change a string litteral into an array if
301 # the number of types and values are not the same, as it would lead to undesirable results.
302 1 my $bind_mismatch = 0;
303 1 my $el;
304 # As a rule, if the first placeholder is a numbered one, then all are, because we cannot mix numbered placeholder and non-numbered ones.
305 1 ▶ my $use_numbered_placeholders = ( ( $q && $q->elements->first->is_numbered ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$q && $q->elements->first->is_numbered ? : 0 1 1
Condition33%1/3
$q and $q->elements->first->is_numbered
!ll&&!rl&&r
100
MC/DC0%0/2
$q and $q->elements->first->is_numbered
$q $q->elements->first->is_numbered
Truth table33%1/3
A and B
A= $qB= $q->elements->first->is_numbered
ABresult
0X0
100
111
306 1 ▶ if( $q &&
Branch: 1 branch
BranchTrueFalseTotal
if ($q and $el = $q->elements and $el->types->length) 0 1 1
Condition33%2/6
$q and $el = $q->elements and $el->types->length
!ll&&!rl&&r
100
$q and $el = $q->elements
!ll&&!rl&&r
100
MC/DC0%0/3
$q and $el = $q->elements and $el->types->length
$q $el = $q->elements $el->types->length
Truth table25%1/4
A and B and C
A= $qB= $el = $q->elementsC= $el->types->length
ABCresult
0XX0
10X0
1100
1111
307 ( $el = $q->elements ) &&
308 $el->types->length )
309 {
310 0 my $types = $q->binded_types_as_param;
311 0 @binded_types = @$types;
312 }
313  
314 1 ▶ if( defined( $el ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $el) 0 1 1
315 {
316 }
317  
318 # Get the values to bind
319 1 ▶ if( $q && $self->{bind} )
Branch: 1 branch
BranchTrueFalseTotal
if ($q and $self->{"bind"}) 0 1 1
Condition33%1/3
$q and $self->{"bind"}
!ll&&!rl&&r
100
MC/DC0%0/2
$q and $self->{"bind"}
$q $self->{"bind"}
Truth table33%1/3
A and B
A= $qB= $self->{"bind"}
ABresult
0X0
100
111
320 {
321 0 ▶ if( @_ &&
Branch: 2 branches
BranchTrueFalseTotal
if (@_ and @_ == 1 && $self->_is_hash($_[0], 'strict') || !(@_ % 2) && ref $_[0] ne 'HASH') { } 0 0 0
elsif (@_) { } 0 0 0
Condition0%0/12
@_ and @_ == 1 && $self->_is_hash($_[0], "strict") || !(@_ % 2) && ref $_[0] ne "HASH"
!ll&&!rl&&r
000
@_ == 1 and $self->_is_hash($_[0], "strict") or not @_ % 2 and ref $_[0] ne "HASH"
l!l&&r!l&&!r
000
@_ == 1 and $self->_is_hash($_[0], "strict")
!ll&&!rl&&r
000
not @_ % 2 and ref $_[0] ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/5
@_ and @_ == 1 && $self->_is_hash($_[0], "strict") || !(@_ % 2) && ref $_[0] ne "HASH"
@_ @_ == 1 $self->_is_hash($_[0], "strict") not @_ % 2 ref $_[0] ne "HASH"
Truth table0%0/8
A and B and C or not(D) and E
A= @_B= @_ == 1C= $self->_is_hash($_[0], "strict")D= not @_ % 2E= ref $_[0] ne "HASH"
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
322 (
323 # hash reference
324 ( @_ == 1 && $self->_is_hash( $_[0] => 'strict' ) ) ||
325 # key => value pairs
326 ( !( @_ % 2 ) && ref( $_[0] ) ne 'HASH' )
327 )
328 )
329 {
330 0 my $vals = {};
331 0 ▶ if( $self->_is_hash( $_[0] => 'strict' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_hash($_[0], 'strict')) { } 0 0 0
332 {
333 0 $vals = shift( @_ );
334 }
335 else
336 {
337 0 $vals = { @_ };
338 }
339 # This is the list of fields as they appear in the order in insert or update query
340 # Knowing their order of appearance is key so we can bind follow-on values to them
341 0 my $sorted = $q->sorted;
342 0 foreach my $f ( @$sorted )
343 {
344 0 ▶ if( !CORE::exists( $vals->{ $f } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $vals->{$f}) { } 0 0 0
345 {
346 0 push( @binded, undef() );
347 }
348 # The value may be defined or not, or may be zero length long
349 else
350 {
351 0 push( @binded, $vals->{ $f } );
352 }
353 }
354 }
355 elsif( @_ )
356 {
357 0 push( @binded, @_ );
358 }
359 else
360 {
361 # my $binded_values = $q->binded;
362 0 my $binded_values = $q->elements->values;
363 0 ▶ push( @binded, @$binded_values ) if( scalar( @$binded_values ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$binded_values 0 0 0
364 }
365 }
366  
367 1 ▶ @binded = @_ if( !@binded && @_ );
Branch: 1 branch
BranchTrueFalseTotal
if not @binded and @_ 0 1 1
Condition33%1/3
not @binded and @_
!ll&&!rl&&r
010
MC/DC0%0/2
not @binded and @_
not @binded @_
Truth table33%1/3
not(A) and B
A= not @bindedB= @_
ABresult
0X0
100
111
368 1 ▶ @binded = () if( !@binded );
Branch: 1 branch
BranchTrueFalseTotal
unless @binded 1 0 1
369 1 ▶ if( $q && $q->is_upsert )
Branch: 1 branch
BranchTrueFalseTotal
if ($q and $q->is_upsert) 0 1 1
Condition33%1/3
$q and $q->is_upsert
!ll&&!rl&&r
100
MC/DC0%0/2
$q and $q->is_upsert
$q $q->is_upsert
Truth table33%1/3
A and B
A= $qB= $q->is_upsert
ABresult
0X0
100
111
370 {
371 0 ▶ if( !$use_numbered_placeholders &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $use_numbered_placeholders and scalar @binded_types > scalar @binded) 0 0 0
Condition0%0/3
not $use_numbered_placeholders and scalar @binded_types > scalar @binded
!ll&&!rl&&r
000
MC/DC0%0/2
not $use_numbered_placeholders and scalar @binded_types > scalar @binded
not $use_numbered_placeholders scalar @binded_types > scalar @binded
Truth table0%0/3
not(A) and B
A= not $use_numbered_placeholdersB= scalar @binded_types > scalar @binded
ABresult
0X0
100
111
372 scalar( @binded_types ) > scalar( @binded ) )
373 {
374 0 CORE::push( @binded, @binded );
375 }
376 }
377  
378 1 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 0 1 1
379 {
380 0 my $temp = {};
381 0 my $el;
382 0 ▶ $el = $q->elements->elements if( $q && $q->elements );
Branch: 1 branch
BranchTrueFalseTotal
if $q and $q->elements 0 0 0
Condition0%0/3
$q and $q->elements
!ll&&!rl&&r
000
MC/DC0%0/2
$q and $q->elements
$q $q->elements
Truth table0%0/3
A and B
A= $qB= $q->elements
ABresult
0X0
100
111
383 0 local $" = ', ';
384 0 ▶ for( my $i = 0; $i < scalar( @args ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @args) 0 0 0
385 {
386 # { $some_value => 'varchar' }
387 0 ▶ if( ref( $_[$i] ) eq 'HASH' &&
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[$i] eq 'HASH' and scalar keys %{$_[$i];} == 1 and $dbo->datatype_to_constant([values %{$_[$i];}]->[0])) { } 0 0 0
elsif (ref $_[$i] eq 'HASH' and scalar keys %{$_[$i];} == 1 and 'DBI'->can('SQL_' . uc([values %{$_[$i];}]->[0]))) { } 0 0 0
Condition0%0/6
ref $_[$i] eq "HASH" and scalar keys %{$_[$i];} == 1 and $dbo->datatype_to_constant([values %{$_[$i];}]->[0])
!ll&&!rl&&r
000
ref $_[$i] eq "HASH" and scalar keys %{$_[$i];} == 1
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_[$i] eq "HASH" and scalar keys %{$_[$i];} == 1 and $dbo->datatype_to_constant([values %{$_[$i];}]->[0])
ref $_[$i] eq "HASH" scalar keys %{$_[$i];} == 1 $dbo->datatype_to_constant([values %{$_[$i];}]->[0])
Truth table0%0/4
A and B and C
A= ref $_[$i] eq "HASH"B= scalar keys %{$_[$i];} == 1C= $dbo->datatype_to_constant([values %{$_[$i];}]->[0])
ABCresult
0XX0
10X0
1100
1111
388 0 scalar( keys( %{$_[$i]} ) ) == 1 &&
389 0 $dbo->datatype_to_constant( [values( %{$_[$i]} )]->[0] ) )
390 {
391 0 my $constant = $dbo->datatype_to_constant( [values( %{$_[$i]} )]->[0] );
392 0 $temp->{$i} = { type => $constant, value => [keys( %{$_[$i]} )]->[0] };
393 }
394 ▶ elsif( ref( $_[$i] ) eq 'HASH' &&
Condition0%0/6
ref $_[$i] eq "HASH" and scalar keys %{$_[$i];} == 1 and "DBI"->can('SQL_' . uc([values %{$_[$i];}]->[0]))
!ll&&!rl&&r
000
ref $_[$i] eq "HASH" and scalar keys %{$_[$i];} == 1
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_[$i] eq "HASH" and scalar keys %{$_[$i];} == 1 and "DBI"->can('SQL_' . uc([values %{$_[$i];}]->[0]))
ref $_[$i] eq "HASH" scalar keys %{$_[$i];} == 1 "DBI"->can('SQL_' . uc([values %{$_[$i];}]->[0]))
Truth table0%0/4
A and B and C
A= ref $_[$i] eq "HASH"B= scalar keys %{$_[$i];} == 1C= "DBI"->can('SQL_' . uc([values %{$_[$i];}]->[0]))
ABCresult
0XX0
10X0
1100
1111
395 0 scalar( keys( %{$_[$i]} ) ) == 1 &&
396 # e.g. DBI::SQL_VARCHAR or DBI::SQL_INTEGER
397 0 DBI->can( "SQL_" . uc( [values( %{$_[$i]} )]->[0] ) ) )
398 {
399 0 my $constant = DBI->can( "SQL_" . uc( [values( %{$_[$i]} )]->[0] ) );
400 0 $temp->{$i} = { type => $constant->(), value => [keys( %{$_[$i]} )]->[0] };
401 }
402 }
403  
404 # The user has chosen to override any datatype computed and be explicit.
405 0 ▶ if( scalar( keys( %$temp ) ) == scalar( @_ ) )
Branch: 2 branches
BranchTrueFalseTotal
if (scalar keys %$temp == scalar @_) { } 0 0 0
elsif (scalar keys %$temp) { } 0 0 0
406 {
407 # @binded = @_;
408 0 @binded_types = ();
409 0 @binded = ();
410 0 foreach my $i ( sort( keys( %$temp ) ) )
411 {
412 0 push( @binded_types, $temp->{ $i }->{type} );
413 0 push( @binded, $temp->{ $i }->{value} );
414 }
415 }
416 elsif( scalar( keys( %$temp ) ) )
417 {
418 0 foreach my $i ( sort( keys( %$temp ) ) )
419 {
420 0 CORE::splice( @binded_types, $i, 1, $temp->{ $i }->{type} );
421 0 $binded[$i] = $temp->{ $i }->{value};
422 }
423 }
424 }
425  
426 1 ▶ if( $q && scalar( @binded ) != scalar( @binded_types ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($q and scalar @binded != scalar @binded_types) 0 1 1
Condition33%1/3
$q and scalar @binded != scalar @binded_types
!ll&&!rl&&r
100
MC/DC0%0/2
$q and scalar @binded != scalar @binded_types
$q scalar @binded != scalar @binded_types
Truth table33%1/3
A and B
A= $qB= scalar @binded != scalar @binded_types
ABresult
0X0
100
111
427 {
428 # Flag we use a bit below
429 0 $bind_mismatch++;
430 0 ▶ warn( sprintf( "Warning: total %d bound values does not match the total %d bound types ('%s')! Check the code for query $self->{sth}->{Statement}", scalar( @binded ), scalar( @binded_types ), CORE::join( "','", map{ ref( $_ ) eq 'HASH' ? $self->Module::Generic::dump( $_ ) : $_ } @binded_types ) ) ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 2 branches
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
ref $_ eq 'HASH' ? : 0 0 0
431 # Cancel it, because it will create problems
432 0 @binded_types = ();
433 }
434  
435 # If there are any array object of some sort provided, make sure they are transformed into a regular array so DBD::Ph can then transform it into a Postgres array.
436 1 ▶ for( my $i = 0; $i < scalar( @binded ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @binded) 0 1 1
437 {
438 0 ▶ next if( !defined( $binded[$i] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $binded[$i] 0 0 0
439 0 my $elem;
440 0 ▶ if( defined( $el ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field")) 0 0 0
Condition0%0/12
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field")
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i]
!ll&&!rl&&r
000
defined $el and not $bind_mismatch
!ll&&!rl&&r
000
MC/DC0%0/5
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field")
defined $el not $bind_mismatch $elem = $el->elements->[$i] defined $elem $self->_is_a($elem->fo, "DB::Object::Fields::Field")
Truth table0%0/6
A and not(B) and C and D and E
A= defined $elB= not $bind_mismatchC= $elem = $el->elements->[$i]D= defined $elemE= $self->_is_a($elem->fo, "DB::Object::Fields::Field")
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
441 !$bind_mismatch &&
442 ( $elem = $el->elements->[$i] ) &&
443 defined( $elem ) &&
444 $self->_is_a( $elem->fo => 'DB::Object::Fields::Field' ) )
445 {
446 }
447  
448 0 ▶ if( defined( $el ) &&
Branch: 3 branches
BranchTrueFalseTotal
if (defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, 'DB::Object::Fields::Field') and $elem->fo->is_array and not $self->_is_array($binded[$i]) and defined $binded[$i]) { } 0 0 0
elsif (defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, 'DB::Object::Fields::Field') and ($elem->fo->type // '') eq 'jsonb' || ($elem->fo->type // '') eq 'json' and $self->_is_hash($binded[$i], 'strict')) { } 0 0 0
elsif (defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, 'DB::Object::Fields::Field') and ($elem->fo->type // '') =~ /^(date|timestamp)/i || $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length and defined $binded[$i] and $self->_is_a($binded[$i], ['DateTime', 'DateTime::Lite']) and !$binded[$i]->formatter || ($binded[$i]->stringify // '') =~ /^\d+$/) { } 0 0 0
Condition0%0/21
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and $elem->fo->is_array and not $self->_is_array($binded[$i]) and defined $binded[$i]
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and $elem->fo->is_array and not $self->_is_array($binded[$i])
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and $elem->fo->is_array
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field")
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i]
!ll&&!rl&&r
000
defined $el and not $bind_mismatch
!ll&&!rl&&r
000
MC/DC0%0/8
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and $elem->fo->is_array and not $self->_is_array($binded[$i]) and defined $binded[$i]
defined $el not $bind_mismatch $elem = $el->elements->[$i] defined $elem $self->_is_a($elem->fo, "DB::Object::Fields::Field") $elem->fo->is_array not $self->_is_array($binded[$i]) defined $binded[$i]
Truth table0%0/9
A and not(B) and C and D and E and F and not(G) and H
A= defined $elB= not $bind_mismatchC= $elem = $el->elements->[$i]D= defined $elemE= $self->_is_a($elem->fo, "DB::Object::Fields::Field")F= $elem->fo->is_arrayG= not $self->_is_array($binded[$i])H= defined $binded[$i]
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
449 !$bind_mismatch &&
450 ( $elem = $el->elements->[$i] ) &&
451 defined( $elem ) &&
452 $self->_is_a( $elem->fo => 'DB::Object::Fields::Field' ) &&
453 $elem->fo->is_array &&
454 !$self->_is_array( $binded[$i] ) &&
455 defined( $binded[$i] ) )
456 {
457 0 ▶ $binded[$i] = $self->_is_number( $binded[$i] ) ? [$binded[$i]] : [$dbo->quote( $binded[$i] )];
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_number($binded[$i]) ? : 0 0 0
458 }
459 ▶ elsif( defined( $el ) &&
Condition0%0/25
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") eq "jsonb" || ($elem->fo->type // "") eq "json" and $self->_is_hash($binded[$i], "strict")
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") eq "jsonb" || ($elem->fo->type // "") eq "json"
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field")
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i]
!ll&&!rl&&r
000
defined $el and not $bind_mismatch
!ll&&!rl&&r
000
($elem->fo->type // "") eq "jsonb" or ($elem->fo->type // "") eq "json"
l!l&&r!l&&!r
000
$elem->fo->type // ""
l!l
00
$elem->fo->type // ""
l!l
00
MC/DC0%0/8
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") eq "jsonb" || ($elem->fo->type // "") eq "json" and $self->_is_hash($binded[$i], "strict")
defined $el not $bind_mismatch $elem = $el->elements->[$i] defined $elem $self->_is_a($elem->fo, "DB::Object::Fields::Field") $elem->fo->type $elem->fo->type $self->_is_hash($binded[$i], "strict")
Truth table0%0/10
A and not(B) and C and D and E and F or G and H
A= defined $elB= not $bind_mismatchC= $elem = $el->elements->[$i]D= defined $elemE= $self->_is_a($elem->fo, "DB::Object::Fields::Field")F= $elem->fo->typeG= $elem->fo->typeH= $self->_is_hash($binded[$i], "strict")
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
1111100X0
111111X00
111110100
111111X11
111110111
460 !$bind_mismatch &&
461 ( $elem = $el->elements->[$i] ) &&
462 defined( $elem ) &&
463 $self->_is_a( $elem->fo => 'DB::Object::Fields::Field' ) &&
464 ( ( $elem->fo->type // '' ) eq 'jsonb' || ( $elem->fo->type // '' ) eq 'json' ) &&
465 $self->_is_hash( $binded[$i] => 'strict' ) )
466 {
467 # try-catch
468 0 local $@;
469 my $json = eval
470 0 {
471 0 $self->new_json->encode( $binded[$i] );
472 };
473 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
474 {
475 0 ▶ warn( "Error trying to encode hash value ", $binded[$i], ": $@" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
476 }
477 else
478 {
479 0 $binded[$i] = $json;
480 }
481 }
482 # If the value provided is a DateTime::Lite object without a formatter, we transform the given value into a ISO8601 datetime string
483 ▶ elsif( defined( $el ) &&
Condition0%0/34
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") =~ /^(date|timestamp)/i || $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length and defined $binded[$i] and $self->_is_a($binded[$i], ["DateTime", "DateTime::Lite"]) and !$binded[$i]->formatter || ($binded[$i]->stringify // "") =~ /^\d+$/
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") =~ /^(date|timestamp)/i || $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length and defined $binded[$i] and $self->_is_a($binded[$i], ["DateTime", "DateTime::Lite"])
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") =~ /^(date|timestamp)/i || $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length and defined $binded[$i]
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") =~ /^(date|timestamp)/i || $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field")
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem
!ll&&!rl&&r
000
defined $el and not $bind_mismatch and $elem = $el->elements->[$i]
!ll&&!rl&&r
000
defined $el and not $bind_mismatch
!ll&&!rl&&r
000
($elem->fo->type // "") =~ /^(date|timestamp)/i or $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length
l!l&&r!l&&!r
000
$elem->fo->type // ""
l!l
00
not $binded[$i]->formatter or ($binded[$i]->stringify // "") =~ /^\d+$/
l!l&&r!l&&!r
000
$binded[$i]->stringify // ""
l!l
00
MC/DC0%0/11
defined $el and not $bind_mismatch and $elem = $el->elements->[$i] and defined $elem and $self->_is_a($elem->fo, "DB::Object::Fields::Field") and ($elem->fo->type // "") =~ /^(date|timestamp)/i || $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length and defined $binded[$i] and $self->_is_a($binded[$i], ["DateTime", "DateTime::Lite"]) and !$binded[$i]->formatter || ($binded[$i]->stringify // "") =~ /^\d+$/
defined $el not $bind_mismatch $elem = $el->elements->[$i] defined $elem $self->_is_a($elem->fo, "DB::Object::Fields::Field") $elem->fo->type $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->length defined $binded[$i] $self->_is_a($binded[$i], ["DateTime", "DateTime::Lite"]) not $binded[$i]->formatter $binded[$i]->stringify
Truth table0%0/16
A and not(B) and C and D and E and F or G and H and I and not(J) or K
A= defined $elB= not $bind_mismatchC= $elem = $el->elements->[$i]D= defined $elemE= $self->_is_a($elem->fo, "DB::Object::Fields::Field")F= $elem->fo->typeG= $elem->fo->datatype->alias->grep(qr/^(date|timestamp)/i)->lengthH= defined $binded[$i]I= $self->_is_a($binded[$i], ["DateTime", "DateTime::Lite"])J= not $binded[$i]->formatterK= $binded[$i]->stringify
ABCDEFGHIJKresult
0XXXXXXXXXX0
10XXXXXXXXX0
110XXXXXXXX0
1110XXXXXXX0
11110XXXXXX0
1111100XXXX0
111111X0XXX0
11111010XXX0
111111X10XX0
111110110XX0
111111X11000
111110111000
111111X111X1
111111X11011
1111101111X1
111110111011
484 !$bind_mismatch &&
485 ( $elem = $el->elements->[$i] ) &&
486 defined( $elem ) &&
487 $self->_is_a( $elem->fo => 'DB::Object::Fields::Field' ) &&
488 ( ( $elem->fo->type // '' ) =~ /^(date|timestamp)/i || $elem->fo->datatype->alias->grep( qr/^(date|timestamp)/i )->length ) &&
489 defined( $binded[$i] ) &&
490 $self->_is_a( $binded[$i] => [qw( DateTime DateTime::Lite )] ) &&
491 # There is no formatter, or it is set to a Unix timestamp
492 ( !$binded[$i]->formatter || ( $binded[$i]->stringify // '' ) =~ /^\d+$/ ) )
493 {
494 0 $binded[$i] = $binded[$i]->iso8601;
495 }
496  
497 # The value is an array object, but not a simple array, so we need to convert it
498 # or else the driver will not understand nor accept it.
499 0 ▶ if( $self->_is_array( $binded[$i] ) &&
Branch: 5 branches
BranchTrueFalseTotal
if ($self->_is_array($binded[$i]) and ref $binded[$i] ne 'ARRAY') { } 0 0 0
elsif ($self->_is_a($binded[$i], ['DateTime::Lite', 'DateTime'])) { } 0 0 0
elsif ($self->_is_object($binded[$i]) and overload::Overloaded($binded[$i]) and overload::Method($binded[$i], '""')) { } 0 0 0
elsif ($self->_is_hash($binded[$i]) and $self->_can($binded[$i], 'as_json')) { } 0 0 0
elsif ($self->_is_hash($binded[$i], 'strict')) { } 0 0 0
Condition0%0/3
$self->_is_array($binded[$i]) and ref $binded[$i] ne "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_array($binded[$i]) and ref $binded[$i] ne "ARRAY"
$self->_is_array($binded[$i]) ref $binded[$i] ne "ARRAY"
Truth table0%0/3
A and B
A= $self->_is_array($binded[$i])B= ref $binded[$i] ne "ARRAY"
ABresult
0X0
100
111
500 ref( $binded[$i] ) ne 'ARRAY' )
501 {
502 0 $binded[$i] = [@{$binded[$i]}];
503 }
504 elsif( $self->_is_a( $binded[$i] => [qw( DateTime::Lite DateTime )] ) )
505 {
506 0 $binded[$i] = $binded[$i]->iso8601;
507 }
508 ▶ elsif( $self->_is_object( $binded[$i] ) &&
Condition0%0/6
$self->_is_object($binded[$i]) and overload::Overloaded($binded[$i]) and overload::Method($binded[$i], "\"\"")
!ll&&!rl&&r
000
$self->_is_object($binded[$i]) and overload::Overloaded($binded[$i])
!ll&&!rl&&r
000
MC/DC0%0/3
$self->_is_object($binded[$i]) and overload::Overloaded($binded[$i]) and overload::Method($binded[$i], "\"\"")
$self->_is_object($binded[$i]) overload::Overloaded($binded[$i]) overload::Method($binded[$i], "\"\"")
Truth table0%0/4
A and B and C
A= $self->_is_object($binded[$i])B= overload::Overloaded($binded[$i])C= overload::Method($binded[$i], "\"\"")
ABCresult
0XX0
10X0
1100
1111
509 overload::Overloaded( $binded[$i] ) &&
510 overload::Method( $binded[$i], '""' ) )
511 {
512 3 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
513 0 my $v = "$binded[$i]";
514 0 ▶ $binded[$i] = defined( $v ) ? $v : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 0 0 0
515 }
516 # Will work well with Module::Generic::Hash
517 ▶ elsif( $self->_is_hash( $binded[$i] ) &&
Condition0%0/3
$self->_is_hash($binded[$i]) and $self->_can($binded[$i], "as_json")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_hash($binded[$i]) and $self->_can($binded[$i], "as_json")
$self->_is_hash($binded[$i]) $self->_can($binded[$i], "as_json")
Truth table0%0/3
A and B
A= $self->_is_hash($binded[$i])B= $self->_can($binded[$i], "as_json")
ABresult
0X0
100
111
518 $self->_can( $binded[$i], 'as_json' ) )
519 {
520 0 $binded[$i] = $binded[$i]->as_json;
521 }
522 elsif( $self->_is_hash( $binded[$i] => 'strict' ) )
523 {
524 # try-catch
525 0 local $@;
526 my $json = eval
527 0 {
528 0 $self->new_json->encode( $binded[$i] );
529 };
530 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
531 {
532 0 ▶ warn( "Error trying to encode hash value ", $binded[$i], ": $@" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
533 }
534 else
535 {
536 0 $binded[$i] = $json;
537 }
538 }
539 }
540  
541 1 local $_;
542 my $rv = eval
543 1 {
544 0 ▶ local( $SIG{ALRM} ) = sub{ die( "Timeout while processing query $self->{sth}->{Statement}\n" ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
545 1 ▶ for( my $i = 0; $i < scalar( @binded ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @binded) 0 1 1
546 {
547 # Stringify the binded value if it is a stringifyable object.
548 0 ▶ if( ref( $binded[$i] ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $binded[$i] and $self->_is_object($binded[$i]) and overload::Overloaded($binded[$i]) and overload::Method($binded[$i], "\"\"")) 0 0 0
Condition0%0/9
ref $binded[$i] and $self->_is_object($binded[$i]) and overload::Overloaded($binded[$i]) and overload::Method($binded[$i], "\"\"")
!ll&&!rl&&r
000
ref $binded[$i] and $self->_is_object($binded[$i]) and overload::Overloaded($binded[$i])
!ll&&!rl&&r
000
ref $binded[$i] and $self->_is_object($binded[$i])
!ll&&!rl&&r
000
MC/DC0%0/4
ref $binded[$i] and $self->_is_object($binded[$i]) and overload::Overloaded($binded[$i]) and overload::Method($binded[$i], "\"\"")
ref $binded[$i] $self->_is_object($binded[$i]) overload::Overloaded($binded[$i]) overload::Method($binded[$i], "\"\"")
Truth table0%0/5
A and B and C and D
A= ref $binded[$i]B= $self->_is_object($binded[$i])C= overload::Overloaded($binded[$i])D= overload::Method($binded[$i], "\"\"")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
549 $self->_is_object( $binded[$i] ) &&
550 overload::Overloaded( $binded[$i] ) &&
551 overload::Method( $binded[$i], '""' ) )
552 {
553 0 $binded[$i] .= '';
554 }
555  
556 0 my $data_type = $binded_types[ $i ];
557 0 ▶ if( CORE::length( $data_type ) && $self->_is_hash( $data_type ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $data_type and $self->_is_hash($data_type)) { } 0 0 0
Condition0%0/3
length $data_type and $self->_is_hash($data_type)
!ll&&!rl&&r
000
MC/DC0%0/2
length $data_type and $self->_is_hash($data_type)
length $data_type $self->_is_hash($data_type)
Truth table0%0/3
A and B
A= length $data_typeB= $self->_is_hash($data_type)
ABresult
0X0
100
111
558 {
559 0 $self->{sth}->bind_param( $i + 1, $binded[ $i ], $data_type );
560 }
561 else
562 {
563 0 $self->{sth}->bind_param( $i + 1, $binded[ $i ] );
564 }
565 }
566 1 $self->{sth}->execute();
567 };
568 1 my $error = $@;
569 1 ▶ $error ||= $self->{sth}->errstr if( !$rv );
Branch: 1 branch
BranchTrueFalseTotal
unless $rv 0 1 1
Condition0%0/3
$error ||= $self->{"sth"}->errstr
l!l&&r!l&&!r
000
MC/DC0%0/2
$error ||= $self->{"sth"}->errstr
$error $self->{"sth"}->errstr
Truth table0%0/3
A ||= B
A= $errorB= $self->{"sth"}->errstr
ABresult
1X1
011
000
570 1 ▶ if( $q )
Branch: 1 branch
BranchTrueFalseTotal
if ($q) 0 1 1
571 {
572 # Only reset the table's query object if this is NOT a cached/reused joined statement.
573 # For joined statements, the query object ($q_source) is permanently attached to the
574 # statement handle and resetting the table creates a new ~500KB query object on every
575 # execute() that is never freed (the old one is orphaned). The reset serves to prepare
576 # the table for a fresh query after a one-shot select(), which is not the case here.
577 # A joined statement is identified by having join_tables populated.
578 # For a joined statement that is reused in a loop (exec() called multiple times),
579 # calling reset() on any of the tables is wasteful: it creates a new ~500KB query
580 # object for every single exec() call, and those objects are never freed because the
581 # allocator retains the arena pages. The reset was designed for one-shot select()
582 # usage, not for reused prepared statements. Skip it entirely for joined statements.
583 0 ▶ if( $q->join_tables->length == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($q->join_tables->length == 0) 0 0 0
584 {
585 0 $q->table_object->reset;
586 }
587 }
588 1 ▶ my $tie = $self->{tie} || {};
Condition50%1/2
$self->{'tie'} || {}
l!l
01
MC/DC0%0/1
$self->{'tie'} || {}
$self->{'tie'}
Truth table50%1/2
A
A= $self->{'tie'}
Aresult
11
00
589 # Maybe it is time to bind SQL result to possible provided perl variables?
590 1 ▶ if( !$error && %$tie )
Branch: 1 branch
BranchTrueFalseTotal
if (not $error and %$tie) 0 1 1
Condition33%1/3
not $error and %$tie
!ll&&!rl&&r
010
MC/DC0%0/2
not $error and %$tie
not $error %$tie
Truth table33%1/3
not(A) and B
A= not $errorB= %$tie
ABresult
0X0
100
111
591 {
592 0 my $order = $self->{tie_order};
593 0 my $sth = $self->{sth};
594 0 ▶ for( my $i = 0; $i < @$order; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$order) 0 0 0
595 {
596 0 my $pos = $i + 1;
597 0 my $val = $order->[ $i ];
598 0 ▶ if( exists( $tie->{ $val } ) && ref( $tie->{ $val } ) eq 'SCALAR' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tie->{$val} and ref $tie->{$val} eq "SCALAR") 0 0 0
Condition0%0/3
exists $tie->{$val} and ref $tie->{$val} eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $tie->{$val} and ref $tie->{$val} eq "SCALAR"
exists $tie->{$val} ref $tie->{$val} eq "SCALAR"
Truth table0%0/3
A and B
A= exists $tie->{$val}B= ref $tie->{$val} eq "SCALAR"
ABresult
0X0
100
111
599 {
600 0 $sth->bind_col( $pos, $tie->{ $val } );
601 }
602 }
603 }
604 1 ▶ if( $error )
Branch: 2 branches
BranchTrueFalseTotal
if ($error) { } 0 1 1
elsif ($self->{'sth'}->errstr) { } 0 1 1
605 {
606 0 ▶ if( $error =~ / at (\S+\s)?line \d+.*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ / at (\S+\s)?line \d+.*$/) 0 0 0
607 {
608 0 $error =~ s/ at (\S+\s)?line \d+.*$//s;
609 }
610 # $err .= ":\n\"$self->{ 'query' }\"";
611 # $error .= ":\n\"$self->{sth}->{Statement}\"";
612 0 $error = "Error while trying to execute query $self->{sth}->{Statement}: $error";
613 0 ▶ if( $self->fatal() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fatal) { } 0 0 0
614 {
615 0 die( "$error in $self->{file} at line $self->{line} within sub $self->{sub}\n" );
616 }
617 else
618 {
619 # return( $self->error( "$err in $self->{ 'file' } at line $self->{ 'line' } within sub $self->{ 'sub' }" ) );
620 0 return( $self->error( $error ) );
621 }
622 }
623 elsif( $self->{sth}->errstr() )
624 {
625 0 return( $self->error( "Error while trying to execute query $self->{sth}->{Statement}: ", $self->{sth}->errstr ) );
626 }
627 # Clear any error, since this query statement may be re-used
628 1 $self->clear_error;
629  
630 # User wants an object for chaining like:
631 # $sth->exec( 'some value' )->fetchrow;
632 1 ▶ if( want( 'OBJECT' ) )
Branch: 2 branches
BranchTrueFalseTotal
if (want('OBJECT')) { } 0 1 1
elsif ($rv) { } 1 0 1
633 {
634 0 return( $self );
635 }
636 elsif( $rv )
637 {
638 1 return( $rv );
639 }
640 # For void context too
641 else
642 {
643 0 return(1);
644 }
645 }
646  
647 sub executed
648 1 ▶{
Subroutine executed: called CC=3 SCAR=12.5
Pod documented
649 1 my $self = shift( @_ );
650 # For hand made query to avoid clash when executing generic routine such as fetchall_arrayref...
651 1 ▶ return(1) if( !exists( $self->{query} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"query"} 0 1 1
652 1 ▶ return( exists( $self->{executed} ) && $self->{executed} );
Condition33%1/3
exists $self->{'executed'} && $self->{'executed'}
!ll&&!rl&&r
001
MC/DC0%0/2
exists $self->{'executed'} && $self->{'executed'}
exists $self->{'executed'} $self->{'executed'}
Truth table33%1/3
A && B
A= exists $self->{'executed'}B= $self->{'executed'}
ABresult
0X0
100
111
653 }
654  
655 sub fetchall_arrayref($@)
656 1 ▶{
Subroutine fetchall_arrayref: called CC=23 SCAR=46.0
Pod documented
657 1 my $self = shift( @_ );
658 1 ▶ my $slice = shift( @_ ) || [];
Condition50%1/2
shift @_ || []
l!l
10
MC/DC0%0/1
shift @_ || []
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
659 1 ▶ my $dbo = $self->database_object ||
Condition50%1/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
10
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table50%1/2
A
A= $self->database_object
Aresult
11
00
660 return( $self->error( "No database handle could be found." ) );
661 1 ▶ my $sth = $self->{sth} || die( "Unable to get the underlying statement handler!" );
Condition50%1/2
$self->{'sth'} || die('Unable to get the underlying statement handler!')
l!l
10
MC/DC0%0/1
$self->{'sth'} || die('Unable to get the underlying statement handler!')
$self->{'sth'}
Truth table50%1/2
A
A= $self->{'sth'}
Aresult
11
00
662 1 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 1 1
663 {
664 0 ▶ $self->execute() || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return 0 0 0
665 }
666 # Ensure we set the cache of field names and types. We will need them to post process the query results with _convert_datetime2object()
667 # This is necessary for MySQL whose object lose that information, while the PostgreSQL or SQLite driver keep the information.
668 1 ▶ my $need_post_processing = ( ( $dbo->auto_decode_json || $dbo->auto_convert_datetime_to_object ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$dbo->auto_decode_json || $dbo->auto_convert_datetime_to_object ? : 1 0 1
Condition33%1/3
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
l!l&&r!l&&!r
100
MC/DC0%0/2
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
$dbo->auto_decode_json $dbo->auto_convert_datetime_to_object
Truth table33%1/3
A or B
A= $dbo->auto_decode_jsonB= $dbo->auto_convert_datetime_to_object
ABresult
1X1
011
000
669 1 ▶ if( $need_post_processing )
Branch: 1 branch
BranchTrueFalseTotal
if ($need_post_processing) 1 0 1
670 {
671 1 $self->_cache_field_names;
672 1 $self->_cache_field_types;
673 }
674 # $self->_cleanup();
675 1 my $mode = ref( $slice );
676 1 my @rows;
677 my $row;
678 1 ▶ if( $mode eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'ARRAY') { } 0 1 1
elsif ($mode eq 'HASH') { } 1 0 1
679 {
680 0 ▶ if( @$slice )
Branch: 1 branch
BranchTrueFalseTotal
if (@$slice) { } 0 0 0
681 {
682 0 ▶ push( @rows, [ @{$row}[ @$slice ] ] ) while( $row = $sth->fetch() );
Branch: 1 branch
BranchTrueFalseTotal
$row = $sth->fetch and do { push @rows, [@{$row;}[@$slice]] } 0 0 0
683 }
684 else
685 {
686 0 ▶ push( @rows, [ @$row ] ) while( $row = $sth->fetch );
Branch: 1 branch
BranchTrueFalseTotal
$row = $sth->fetch and do { push @rows, [@$row] } 0 0 0
687 }
688 }
689 elsif( $mode eq 'HASH' )
690 {
691 1 my @o_keys = keys( %$slice );
692 1 ▶ if( @o_keys )
Branch: 1 branch
BranchTrueFalseTotal
if (@o_keys) { } 0 1 1
693 {
694 # my %i_names = map{ ( lc( $_ ) => $_ ) } @{ $sth->FETCH( 'NAME' ) };
695 # my @i_keys = map{ $i_names{ lc( $_ ) } } @o_keys;
696 0 my $i_keys = $self->field_names_lc;
697 0 ▶ while( $row = $sth->fetchrow_hashref() )
Branch: 1 branch
BranchTrueFalseTotal
if ($row = $sth->fetchrow_hashref) 0 0 0
698 {
699 0 my %hash;
700 0 @hash{ @o_keys } = @{$row}{ @$i_keys };
701 0 push( @rows, \%hash );
702 }
703 }
704 else
705 {
706 1 ▶ push( @rows, $row ) while( $row = $sth->fetchrow_hashref() );
Branch: 1 branch
BranchTrueFalseTotal
$row = $sth->fetchrow_hashref and do { push @rows, $row } 2 1 3
707 }
708 }
709 else
710 {
711 0 ▶ warn( "fetchall_arrayref($mode) invalid" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
712 }
713  
714 1 ▶ if( !scalar( @rows ) && $sth->err )
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar @rows and $sth->err) 0 1 1
Condition33%1/3
not scalar @rows and $sth->err
!ll&&!rl&&r
100
MC/DC0%0/2
not scalar @rows and $sth->err
not scalar @rows $sth->err
Truth table33%1/3
not(A) and B
A= not scalar @rowsB= $sth->err
ABresult
0X0
100
111
715 {
716 0 $self->error({ code => $sth->err, message => $sth->errstr });
717 }
718 # return( \@rows );
719 1 ▶ return( \@rows ) if( !$need_post_processing );
Branch: 1 branch
BranchTrueFalseTotal
unless $need_post_processing 0 1 1
720 1 my $data = \@rows;
721 1 ▶ $data = $self->_convert_json2hash({ statement => $sth, data => $data }) if( $dbo->auto_decode_json );
Branch: 1 branch
BranchTrueFalseTotal
if $dbo->auto_decode_json 1 0 1
722 1 ▶ $data = $self->_convert_datetime2object({ statement => $sth, data => $data }) if( $dbo->auto_convert_datetime_to_object );
Branch: 1 branch
BranchTrueFalseTotal
if $dbo->auto_convert_datetime_to_object 0 1 1
723 1 return( $data );
724 }
725  
726 sub fetchcol($;$)
727 0 ▶{
Subroutine fetchcol: not called CC=7 SCAR=40.3
Pod documented
728 0 my $self = shift( @_ );
729 # @arr = $sth->fetchcol( $col_number );
730 0 my $col_num = shift( @_ );
731 0 ▶ my $sth = $self->{sth} || die( "Unable to get the underlying statement handler!" );
Condition0%0/2
$self->{'sth'} || die('Unable to get the underlying statement handler!')
l!l
00
MC/DC0%0/1
$self->{'sth'} || die('Unable to get the underlying statement handler!')
$self->{'sth'}
Truth table0%0/2
A
A= $self->{'sth'}
Aresult
11
00
732 0 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 0 0
733 {
734 0 ▶ $self->execute() || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return $self->pass_error 0 0 0
735 }
736 # $self->_cleanup();
737 # return( $h->fetchcol( $COL_NUM ) );
738 0 my @col;
739 # $self->dataseek( 0 );
740 my $ref;
741 0 ▶ while( $ref = $self->{sth}->fetchrow_arrayref() )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref = $self->{"sth"}->fetchrow_arrayref) 0 0 0
742 {
743 0 push( @col, $ref->[ $col_num ] );
744 }
745 0 ▶ if( !defined( $ref ) && $sth->err )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref and $sth->err) 0 0 0
Condition0%0/3
not defined $ref and $sth->err
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $sth->err
not defined $ref $sth->err
Truth table0%0/3
not(A) and B
A= not defined $refB= $sth->err
ABresult
0X0
100
111
746 {
747 0 $self->error({ code => $sth->err, message => $sth->errstr });
748 }
749 0 return( @col );
750 }
751  
752 sub fetchhash(@)
753 0 ▶{
Subroutine fetchhash: not called CC=14 SCAR=53.5
Pod documented
754 0 my $self = shift( @_ );
755 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
756 return( $self->error( "No database handle could be found." ) );
757 0 ▶ my $sth = $self->{sth} || die( "Unable to get the underlying statement handler!" );
Condition0%0/2
$self->{'sth'} || die('Unable to get the underlying statement handler!')
l!l
00
MC/DC0%0/1
$self->{'sth'} || die('Unable to get the underlying statement handler!')
$self->{'sth'}
Truth table0%0/2
A
A= $self->{'sth'}
Aresult
11
00
758 0 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 0 0
759 {
760 0 ▶ $self->execute() || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return $self->pass_error 0 0 0
761 }
762 # Ensure we set the cache of field names and types. We will need them to post process the query results with _convert_datetime2object()
763 # This is necessary for MySQL whose object lose that information, while the PostgreSQL or SQLite driver keep the information.
764 0 ▶ if( $dbo->auto_decode_json || $dbo->auto_convert_datetime_to_object )
Branch: 1 branch
BranchTrueFalseTotal
if ($dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object) 0 0 0
Condition0%0/3
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
$dbo->auto_decode_json $dbo->auto_convert_datetime_to_object
Truth table0%0/3
A or B
A= $dbo->auto_decode_jsonB= $dbo->auto_convert_datetime_to_object
ABresult
1X1
011
000
765 {
766 0 $self->_cache_field_names;
767 0 $self->_cache_field_types;
768 }
769 # $self->_cleanup();
770 # %hash = $sth->fetchhash;
771 # return( $h->fetchhash );
772 0 my $ref = $sth->fetchrow_hashref();
773 0 ▶ if( !defined( $ref ) && $sth->err )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref and $sth->err) 0 0 0
Condition0%0/3
not defined $ref and $sth->err
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $sth->err
not defined $ref $sth->err
Truth table0%0/3
not(A) and B
A= not defined $refB= $sth->err
ABresult
0X0
100
111
774 {
775 0 $self->error({ code => $sth->err, message => $sth->errstr });
776 }
777 0 ▶ if( $ref )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
778 {
779 0 ▶ if( $dbo->auto_decode_json || $dbo->auto_convert_datetime_to_object )
Branch: 1 branch
BranchTrueFalseTotal
if ($dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object) 0 0 0
Condition0%0/3
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
$dbo->auto_decode_json $dbo->auto_convert_datetime_to_object
Truth table0%0/3
A or B
A= $dbo->auto_decode_jsonB= $dbo->auto_convert_datetime_to_object
ABresult
1X1
011
000
780 {
781 0 ▶ $ref = $self->_convert_json2hash({ statement => $sth, data => $ref }) if( $dbo->auto_decode_json );
Branch: 1 branch
BranchTrueFalseTotal
if $dbo->auto_decode_json 0 0 0
782 0 ▶ $ref = $self->_convert_datetime2object({ statement => $sth, data => $ref }) if( $dbo->auto_convert_datetime_to_object );
Branch: 1 branch
BranchTrueFalseTotal
if $dbo->auto_convert_datetime_to_object 0 0 0
783 }
784 0 return( %$ref );
785 }
786 else
787 {
788 0 return( () );
789 }
790 }
791  
792 sub fetchrow(@)
793 0 ▶{
Subroutine fetchrow: not called CC=8 SCAR=42.8
Pod documented
794 0 my $self = shift( @_ );
795 0 ▶ my $sth = $self->{sth} || die( "Unable to get the underlying statement handler!" );
Condition0%0/2
$self->{'sth'} || die('Unable to get the underlying statement handler!')
l!l
00
MC/DC0%0/1
$self->{'sth'} || die('Unable to get the underlying statement handler!')
$self->{'sth'}
Truth table0%0/2
A
A= $self->{'sth'}
Aresult
11
00
796 0 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 0 0
797 {
798 0 ▶ $self->execute() || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return $self->pass_error 0 0 0
799 }
800 # $self->_cleanup();
801 # @arr = $sth->fetchrow; # Array context
802 # $firstcol = $sth->fetchrow; # Scalar context
803 # return( $h->fetchrow );
804 # my $ref = $self->fetchrow_arrayref();
805 0 my $ref = $sth->fetchrow_arrayref();
806 0 ▶ if( !defined( $ref ) && $sth->err )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref and $sth->err) 0 0 0
Condition0%0/3
not defined $ref and $sth->err
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $sth->err
not defined $ref $sth->err
Truth table0%0/3
not(A) and B
A= not defined $refB= $sth->err
ABresult
0X0
100
111
807 {
808 0 $self->error({ code => $sth->err, message => $sth->errstr });
809 }
810 # my $ref = $self->{sth}->fetch();
811 0 ▶ if( $ref )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
812 {
813 0 ▶ return( wantarray ? @$ref : $ref->[0] );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
814 }
815 else
816 {
817 0 return( () );
818 }
819 }
820  
821 # sub fetchrow_hashref(@) is inherited from DBI
822 sub fetchrow_hashref
823 0 ▶{
Subroutine fetchrow_hashref: not called CC=11 SCAR=48.8
Pod documented
824 0 my $self = shift( @_ );
825 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
826 return( $self->error( "No database handle could be found." ) );
827 0 my $deb = {};
828 0 %$deb = %$self;
829 0 ▶ my $sth = $self->{sth} || die( "Unable to get the underlying statement handler!" );
Condition0%0/2
$self->{'sth'} || die('Unable to get the underlying statement handler!')
l!l
00
MC/DC0%0/1
$self->{'sth'} || die('Unable to get the underlying statement handler!')
$self->{'sth'}
Truth table0%0/2
A
A= $self->{'sth'}
Aresult
11
00
830 0 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 0 0
831 {
832 0 ▶ $self->execute() || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return $self->pass_error 0 0 0
833 }
834 # Ensure we set the cache of field names and types. We will need them to post process the query results with _convert_datetime2object()
835 # This is necessary for MySQL whose object lose that information, while the PostgreSQL or SQLite driver keep the information.
836 0 ▶ if( $dbo->auto_decode_json || $dbo->auto_convert_datetime_to_object )
Branch: 1 branch
BranchTrueFalseTotal
if ($dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object) 0 0 0
Condition0%0/3
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbo->auto_decode_json or $dbo->auto_convert_datetime_to_object
$dbo->auto_decode_json $dbo->auto_convert_datetime_to_object
Truth table0%0/3
A or B
A= $dbo->auto_decode_jsonB= $dbo->auto_convert_datetime_to_object
ABresult
1X1
011
000
837 {
838 0 $self->_cache_field_names;
839 0 $self->_cache_field_types;
840 }
841 0 my $ref = $sth->fetchrow_hashref;
842 # DBI documentation says:
843 # "If there are no more rows or if an error occurs, then fetchrow_hashref returns an undef. You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the undef returned was due to an error."
844 # Also: <https://metacpan.org/pod/DBI#errstr>
845 0 ▶ if( !defined( $ref ) && $sth->err )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref and $sth->err) 0 0 0
Condition0%0/3
not defined $ref and $sth->err
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $sth->err
not defined $ref $sth->err
Truth table0%0/3
not(A) and B
A= not defined $refB= $sth->err
ABresult
0X0
100
111
846 {
847 0 $self->error({ code => $sth->err, message => $sth->errstr });
848 }
849 0 ▶ $ref = $self->_convert_json2hash({ statement => $sth, data => $ref }) if( $dbo->auto_decode_json );
Branch: 1 branch
BranchTrueFalseTotal
if $dbo->auto_decode_json 0 0 0
850 0 ▶ $ref = $self->_convert_datetime2object({ statement => $sth, data => $ref }) if( $dbo->auto_convert_datetime_to_object );
Branch: 1 branch
BranchTrueFalseTotal
if $dbo->auto_convert_datetime_to_object 0 0 0
851 0 return( $ref );
852 }
853  
854 sub fetchrow_object
855 0 ▶{
Subroutine fetchrow_object: not called CC=9 SCAR=45.0
Pod documented
856 0 my $self = shift( @_ );
857 # This should give us something like Postgres or Mysql or SQLite
858 0 my $basePack = ( ref( $self ) =~ /^DB::Object::([^\:]+)/ )[0];
859 0 ▶ my $sth = $self->{sth} || die( "Unable to get the underlying statement handler!" );
Condition0%0/2
$self->{'sth'} || die('Unable to get the underlying statement handler!')
l!l
00
MC/DC0%0/1
$self->{'sth'} || die('Unable to get the underlying statement handler!')
$self->{'sth'}
Truth table0%0/2
A
A= $self->{'sth'}
Aresult
11
00
860 0 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 0 0
861 {
862 0 ▶ $self->execute() || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return $self->pass_error 0 0 0
863 }
864 # $self->_cleanup();
865 0 my $rows = $self->{sth}->rows;
866 0 my $ref = $self->{sth}->fetchrow_hashref();
867 # DBI documentation says:
868 # "If there are no more rows or if an error occurs, then fetchrow_hashref returns an undef. You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the undef returned was due to an error."
869 0 ▶ if( !defined( $ref ) && $sth->err )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ref and $sth->err) 0 0 0
Condition0%0/3
not defined $ref and $sth->err
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $ref and $sth->err
not defined $ref $sth->err
Truth table0%0/3
not(A) and B
A= not defined $refB= $sth->err
ABresult
0X0
100
111
870 {
871 0 $self->error({ code => $sth->err, message => $sth->errstr });
872 }
873 0 ▶ if( $ref && scalar( keys( %$ref ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and scalar keys %$ref) { } 0 0 0
Condition0%0/2
$ref and scalar keys %$ref
!ll
00
MC/DC0%0/1
$ref and scalar keys %$ref
$ref
Truth table0%0/2
A
A= $ref
Aresult
00
11
874 {
875 0 my $struct = { map{ $_ => '$' } keys( %$ref ) };
876 0 my $table = $self->table;
877 0 my $class = "DB::Object::${basePack}::Result::${table}";
878 0 ▶ if( !defined( &{ $class . '::new' } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{$class . '::new';}) 0 0 0
879 {
880 0 struct $class => $struct;
881 }
882 0 my $obj = $class->new( %$ref );
883 0 return( $obj );
884 }
885 else
886 {
887 0 return( () );
888 }
889 }
890  
891 # NOTE: field_names -> NAME
892 # <https://metacpan.org/pod/DBI#NAME>
893 1 ▶sub field_names { return( shift->_get_statement_attribute( 'NAME' ) ); }
Subroutine field_names: called CC=1 SCAR=0.0
Pod documented
894  
895 # NOTE: field_names_lc -> NAME_lc
896 # <https://metacpan.org/pod/DBI#NAME_lc>
897 0 ▶sub field_names_lc { return( shift->_get_statement_attribute( 'NAME_lc' ) ); }
Subroutine field_names_lc: not called CC=1 SCAR=6.9
Pod documented
898  
899 # NOTE: field_names_uc -> NAME_uc
900 # <https://metacpan.org/pod/DBI#NAME_uc>
901 0 ▶sub field_names_uc { return( shift->_get_statement_attribute( 'NAME_uc' ) ); }
Subroutine field_names_uc: not called CC=1 SCAR=6.9
Pod documented
902  
903 # NOTE: field_nullables -> NULLABLE
904 # <https://metacpan.org/pod/DBI#NULLABLE>
905 0 ▶sub field_nullables { return( shift->_get_statement_attribute( 'NULLABLE' ) ); }
Subroutine field_nullables: not called CC=1 SCAR=6.9
Pod documented
906  
907 # NOTE: field_precisions -> PRECISION
908 # <https://metacpan.org/pod/DBI#PRECISION>
909 0 ▶sub field_precisions { return( shift->_get_statement_attribute( 'PRECISION' ) ); }
Subroutine field_precisions: not called CC=1 SCAR=6.9
Pod documented
910  
911 # NOTE: field_scales -> SCALE
912 # <https://metacpan.org/pod/DBI#SCALE>
913 0 ▶sub field_scales { return( shift->_get_statement_attribute( 'SCALE' ) ); }
Subroutine field_scales: not called CC=1 SCAR=6.9
Pod documented
914  
915 # NOTE: field_types -> TYPE
916 # <https://metacpan.org/pod/DBI#TYPE>
917 1 ▶sub field_types { return( shift->_get_statement_attribute( 'TYPE' ) ); }
Subroutine field_types: called CC=1 SCAR=0.0
Pod documented
918  
919 sub finish
920 0 ▶{
Subroutine finish: not called CC=2 SCAR=17.9
Pod documented
921 0 my $self = shift( @_ );
922 0 my $rc = $self->{sth}->finish();
923 0 ▶ if( !$rc )
Branch: 1 branch
BranchTrueFalseTotal
if (not $rc) { } 0 0 0
924 {
925 0 return( $self->error( $self->{sth}->errstr() ) );
926 }
927 else
928 {
929 0 return( $rc );
930 }
931 }
932  
933 sub ignore
934 0 ▶{
Subroutine ignore: not called CC=9 SCAR=45.0
Pod documented
935 0 my $self = shift( @_ );
936 my $query = $self->{query} ||
937 0 ▶ return( $self->error( "No query to set as to be ignored." ) );
Condition0%0/2
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
l!l
00
MC/DC0%0/1
$self->{'query'} || (return $self->error('No query to set as to be ignored.'))
$self->{'query'}
Truth table0%0/2
A
A= $self->{'query'}
Aresult
11
00
938  
939 0 my $type = uc( ( $query =~ /^\s*(\S+)\s+/ )[0] );
940 # ALTER for table alteration statements (DB::Object::Tables
941 0 my @allowed = qw( INSERT UPDATE ALTER );
942 0 my $allowed = CORE::join( '|', @allowed );
943 0 ▶ if( !scalar( grep{ /^$type$/i } @allowed ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep({/^$type$/i;} @allowed)) 0 0 0
944 {
945 0 return( $self->error( "You may not flag statement of type \U$type\E to be ignored:\n$query" ) );
946 }
947 # Incompatible. Do not bother going further
948 0 ▶ return( $self ) if( $query =~ /^\s*(?:$allowed)\s+(?:DELAYED|LOW_PRIORITY|HIGH_PRIORITY)\s+/i );
Branch: 1 branch
BranchTrueFalseTotal
if $query =~ /^\s*(?:$allowed)\s+(?:DELAYED|LOW_PRIORITY|HIGH_PRIORITY)\s+/i 0 0 0
949 0 ▶ return( $self ) if( $type eq 'ALTER' && $query !~ /^\s*$type\s+TABLE\s+/i );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "ALTER" and not $query =~ /^\s*$type\s+TABLE\s+/i 0 0 0
Condition0%0/3
$type eq "ALTER" and not $query =~ /^\s*$type\s+TABLE\s+/i
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "ALTER" and not $query =~ /^\s*$type\s+TABLE\s+/i
$type eq "ALTER" not $query =~ /^\s*$type\s+TABLE\s+/i
Truth table0%0/3
A and not(B)
A= $type eq "ALTER"B= not $query =~ /^\s*$type\s+TABLE\s+/i
ABresult
0X0
100
111
950  
951 0 $query =~ s/^(\s*)($allowed)(\s+)/$1$2 IGNORE /;
952 # my $sth = $self->prepare( $query ) ||
953 # $self->{ 'query' } = $query;
954 # saving parameters to bind later on must have been done previously
955 0 ▶ my $sth = $self->_cache_this( $query ) ||
Condition0%0/2
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
l!l
00
MC/DC0%0/1
$self->_cache_this($query) || (return $self->error("Error while preparing new ignored query:\n$query"))
$self->_cache_this($query)
Truth table0%0/2
A
A= $self->_cache_this($query)
Aresult
11
00
956 return( $self->error( "Error while preparing new ignored query:\n$query" ) );
957 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
958 {
959 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing new ignored query:\n$query") 0 0 0
960 return( $self->error( "Error while executing new ignored query:\n$query" ) );
961 }
962 0 return( $sth );
963 }
964  
965 sub join
966 0 ▶{
Subroutine join: not called CC=70 SCAR=85.1
Pod documented
967 0 my $self = shift( @_ );
968 0 my $data = shift( @_ );
969 0 my $on;
970 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
971 {
972 0 ▶ $on = ( scalar( @_ ) == 1 && ref( $_[0] ) ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 1 && ref $_[0] ? : 0 0 0
Condition0%0/3
scalar @_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and ref $_[0]
scalar @_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0]
ABresult
0X0
100
111
973 }
974 0 ▶ my $q = $self->query_object || return( $self->error( "No query formatter object was set" ) );
Condition0%0/2
$self->query_object || (return $self->error('No query formatter object was set'))
l!l
00
MC/DC0%0/1
$self->query_object || (return $self->error('No query formatter object was set'))
$self->query_object
Truth table0%0/2
A
A= $self->query_object
Aresult
11
00
975 0 ▶ my $tbl_o = $q->table_object || return( $self->error( "No table object is set in query object." ) );
Condition0%0/2
$q->table_object || (return $self->error('No table object is set in query object.'))
l!l
00
MC/DC0%0/1
$q->table_object || (return $self->error('No table object is set in query object.'))
$q->table_object
Truth table0%0/2
A
A= $q->table_object
Aresult
11
00
976 0 ▶ my $query = $q->query ||
Condition0%0/2
$q->query || (return $self->error('No query prepared for join with another table.'))
l!l
00
MC/DC0%0/1
$q->query || (return $self->error('No query prepared for join with another table.'))
$q->query
Truth table0%0/2
A
A= $q->query
Aresult
11
00
977 return( $self->error( "No query prepared for join with another table." ) );
978 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
979 return( $self->error( "No database handle could be found." ) );
980 0 ▶ if( $query !~ /^[[:blank:]]*SELECT[[:blank:]]+/i )
Branch: 1 branch
BranchTrueFalseTotal
unless ($query =~ /^[[:blank:]]*SELECT[[:blank:]]+/i) 0 0 0
981 {
982 0 return( $self->error( "You may not perform a join on a query other than select." ) );
983 }
984 0 my $constant = $q->constant;
985 # Constant is set and query object marked as final, which means this statement has already been processed as a join and so we skip all further processing.
986 0 ▶ if( scalar( keys( %$constant ) ) && $q->final )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$constant and $q->final) 0 0 0
Condition0%0/3
scalar keys %$constant and $q->final
!ll&&!rl&&r
000
MC/DC0%0/2
scalar keys %$constant and $q->final
scalar keys %$constant $q->final
Truth table0%0/3
A and B
A= scalar keys %$constantB= $q->final
ABresult
0X0
100
111
987 {
988 0 return( $self );
989 }
990 0 my $table = $tbl_o->table;
991 0 my $db = $tbl_o->database;
992 0 my $multi_db = $tbl_o->prefix_database;
993 0 my $alias = $tbl_o->as;
994 0 my $new_fields = '';
995 0 my $new_table = '';
996 0 my $new_db = '';
997 0 my $class = ref( $self );
998 0 my $q_source = $q->clone;
999 # clone() does a shallow copy - $q_source->{elements} would share the same object
1000 # as $q->{elements}. Any subsequent _save_bind() on $q would then corrupt the
1001 # element list of the cached statement. We reset elements here so $q_source gets
1002 # its own fresh object, populated by _query_components below.
1003 0 $q_source->{elements} = $q_source->new_elements;
1004 # clone() copies the hash shallowly, which means {table_object} is a strong reference
1005 # in the clone even though _query_object_create() weakens it for freshly created query
1006 # objects. If left strong, $q_source permanently retains the table object, which in turn
1007 # retains every new query object created by _reset_query() on each execute() cycle,
1008 # causing an ~8 MB per-iteration memory leak. Weaken it here to restore correct ownership.
1009 0 ▶ Scalar::Util::weaken( $q_source->{table_object} ) if( $q_source->{table_object} && !Scalar::Util::isweak( $q_source->{table_object} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $q_source->{"table_object"} and not builtin::is_weak($q_source->{"table_object"}) 0 0 0
Condition0%0/3
$q_source->{"table_object"} and not builtin::is_weak($q_source->{"table_object"})
!ll&&!rl&&r
000
MC/DC0%0/2
$q_source->{"table_object"} and not builtin::is_weak($q_source->{"table_object"})
$q_source->{"table_object"} not builtin::is_weak($q_source->{"table_object"})
Truth table0%0/3
A and not(B)
A= $q_source->{"table_object"}B= not builtin::is_weak($q_source->{"table_object"})
ABresult
0X0
100
111
1010 0 ▶ Scalar::Util::weaken( $q_source->{database_object} ) if( $q_source->{database_object} && !Scalar::Util::isweak( $q_source->{database_object} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $q_source->{"database_object"} and not builtin::is_weak($q_source->{"database_object"}) 0 0 0
Condition0%0/3
$q_source->{"database_object"} and not builtin::is_weak($q_source->{"database_object"})
!ll&&!rl&&r
000
MC/DC0%0/2
$q_source->{"database_object"} and not builtin::is_weak($q_source->{"database_object"})
$q_source->{"database_object"} not builtin::is_weak($q_source->{"database_object"})
Truth table0%0/3
A and not(B)
A= $q_source->{"database_object"}B= not builtin::is_weak($q_source->{"database_object"})
ABresult
0X0
100
111
1011  
1012 0 my $q_target;
1013 # On the duplicated table object, add the current table in the join
1014 0 ▶ $q_source->join_tables( $tbl_o ) if( !$q_source->join_tables->length );
Branch: 1 branch
BranchTrueFalseTotal
unless $q_source->join_tables->length 0 0 0
1015 # $data is a DB::Object::Postgres::Statement object - we get all its parameter and merge them with ours
1016 # if( ref( $data ) && ref( $data ) eq $class )
1017 0 ▶ if( ref( $data ) && $self->_is_a( $data, $class ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data and $self->_is_a($data, $class)) { } 0 0 0
Condition0%0/3
ref $data and $self->_is_a($data, $class)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $data and $self->_is_a($data, $class)
ref $data $self->_is_a($data, $class)
Truth table0%0/3
A and B
A= ref $dataB= $self->_is_a($data, $class)
ABresult
0X0
100
111
1018 {
1019 0 $q_target = $data->query_object;
1020 }
1021 # $data is the table name
1022 else
1023 {
1024 0 my $join_tbl;
1025 0 ▶ if( $self->_is_object( $data ) && $data->isa( 'DB::Object::Tables' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_object($data) and $data->isa('DB::Object::Tables')) { } 0 0 0
elsif ($self->_is_object($data)) { } 0 0 0
Condition0%0/3
$self->_is_object($data) and $data->isa("DB::Object::Tables")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($data) and $data->isa("DB::Object::Tables")
$self->_is_object($data) $data->isa("DB::Object::Tables")
Truth table0%0/3
A and B
A= $self->_is_object($data)B= $data->isa("DB::Object::Tables")
ABresult
0X0
100
111
1026 {
1027 0 $join_tbl = $data;
1028 }
1029 elsif( $self->_is_object( $data ) )
1030 {
1031 0 return( $self->error( "I was expecting either a table name as a scalar or a table object, but instead got \"$data\" (", ref( $data ), ")." ) );
1032 }
1033 else
1034 {
1035 0 ▶ return( $self->error( "No such table \"$data\" exists in database \"$db\"." ) ) if( !$dbo->table_exists( $data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $dbo->table_exists($data) 0 0 0
1036 0 $join_tbl = $dbo->table( $data );
1037 0 ▶ return( $self->error( "Could not get a table object from \"$data\"." ) ) if( !$join_tbl );
Branch: 1 branch
BranchTrueFalseTotal
unless $join_tbl 0 0 0
1038 }
1039 0 ▶ $join_tbl->prefixed( $db ne $join_tbl->database_object->database ? 3 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$db ne $join_tbl->database_object->database ? : 0 0 0
1040 0 ▶ my $sth_tmp = $join_tbl->select || return( $self->pass_error( $join_tbl->error ) );
Condition0%0/2
$join_tbl->select || (return $self->pass_error($join_tbl->error))
l!l
00
MC/DC0%0/1
$join_tbl->select || (return $self->pass_error($join_tbl->error))
$join_tbl->select
Truth table0%0/2
A
A= $join_tbl->select
Aresult
11
00
1041 0 ▶ $q_target = $sth_tmp->query_object ||
Condition0%0/2
$sth_tmp->query_object || (return $self->error(qq[Could not get a query object out of the dummy select query I made from table "$data".]))
l!l
00
MC/DC0%0/1
$sth_tmp->query_object || (return $self->error(qq[Could not get a query object out of the dummy select query I made from table "$data".]))
$sth_tmp->query_object
Truth table0%0/2
A
A= $sth_tmp->query_object
Aresult
11
00
1042 return( $self->error( "Could not get a query object out of the dummy select query I made from table \"$data\"." ) );
1043 0 $new_fields = $q_target->selected_fields;
1044 # NOTE: 2021-08-22: If we reset it here, we lose the table aliasing
1045 # $join_tbl->reset;
1046  
1047 # $join_tbl->prefixed( $db ne $join_tbl->database_object->database ? 3 : 1 ) unless( $join_tbl->prefixed );
1048 0 $new_table = $join_tbl->prefix;
1049 0 $join_tbl->reset;
1050 # We assume this table is part of our same database
1051 0 $new_db = $db;
1052 # my $db_data = $self->getdefault( $new_table );
1053 # $new_fields = $db_data->format_statement();
1054 0 $new_fields = '';
1055 }
1056 # TODO: check this or remove it
1057 # $q_target->table_object->prefixed( $db ne $q_target->database_object->database ? 3 : 1 );
1058 0 $new_fields = $q_target->selected_fields;
1059 0 $new_table = $q_target->table_object->name;
1060 # $new_table = $q_target->table_object->prefix;
1061 0 $new_db = $q_target->database_object->database;
1062 0 $q_source->join_tables->push( $q_target->table_object );
1063 0 ▶ if( $q->where && $q_target->where )
Branch: 2 branches
BranchTrueFalseTotal
if ($q->where and $q_target->where) { } 0 0 0
elsif ($q_target->where) { } 0 0 0
Condition0%0/3
$q->where and $q_target->where
!ll&&!rl&&r
000
MC/DC0%0/2
$q->where and $q_target->where
$q->where $q_target->where
Truth table0%0/3
A and B
A= $q->whereB= $q_target->where
ABresult
0X0
100
111
1064 {
1065 # We must NOT call $q_source->where( AND(...) ) here because _where_having would
1066 # reconstruct the WHERE via process_where_condition, losing the bind elements that
1067 # were built up in $q->where. Instead we build a merged Clause directly, copying
1068 # the existing elements from $q->where so they are available to _save_bind below.
1069 0 my $merged = $q_source->new_clause;
1070 0 $merged->merge( $self->AND( $q->where, $q_target->new_clause({ value => '( ' . ( $q_target->where ) . ' )' }) ) );
1071 0 $q_source->{where} = $merged;
1072 }
1073 elsif( $q_target->where )
1074 {
1075 0 $q_source->where( $q_target->where );
1076 }
1077 0 ▶ if( my $group_target = $q_target->group )
Branch: 1 branch
BranchTrueFalseTotal
if (my $group_target = $q_target->group) 0 0 0
1078 {
1079 0 ▶ $q_source->group( $group_target ) if( $group_target->value->length );
Branch: 1 branch
BranchTrueFalseTotal
if $group_target->value->length 0 0 0
1080 }
1081 0 ▶ if( my $order_target = $q_target->order )
Branch: 1 branch
BranchTrueFalseTotal
if (my $order_target = $q_target->order) 0 0 0
1082 {
1083 0 ▶ $q_source->order( $order_target ) if( $order_target->value->length );
Branch: 1 branch
BranchTrueFalseTotal
if $order_target->value->length 0 0 0
1084 }
1085  
1086 0 ▶ if( ( !$q_source->limit || ( $q_source->limit && !$q_source->limit->length ) ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (!$q_source->limit || $q_source->limit && !$q_source->limit->length and $q_source->limit and $q_source->limit->length) 0 0 0
Condition0%0/12
!$q_source->limit || $q_source->limit && !$q_source->limit->length and $q_source->limit and $q_source->limit->length
!ll&&!rl&&r
000
!$q_source->limit || $q_source->limit && !$q_source->limit->length and $q_source->limit
!ll&&!rl&&r
000
not $q_source->limit or $q_source->limit and not $q_source->limit->length
l!l&&r!l&&!r
000
$q_source->limit and not $q_source->limit->length
!ll&&!rl&&r
000
MC/DC0%0/5
!$q_source->limit || $q_source->limit && !$q_source->limit->length and $q_source->limit and $q_source->limit->length
not $q_source->limit $q_source->limit not $q_source->limit->length $q_source->limit $q_source->limit->length
Truth table0%0/8
not(A) or B and not(C) and D and E
A= not $q_source->limitB= $q_source->limitC= not $q_source->limit->lengthD= $q_source->limitE= $q_source->limit->length
ABCDEresult
00XXX0
010XX0
1XX0X0
0110X0
1XX100
011100
1XX111
011111
1087 $q_source->limit && $q_source->limit->length )
1088 {
1089 0 $q_source->limit( $q_target->limit );
1090 }
1091  
1092 0 ▶ my $prev_fields = length( $q->join_fields ) ? $q->join_fields : $q->selected_fields;
Branch: 1 branch
BranchTrueFalseTotal
length $q->join_fields ? : 0 0 0
1093 # Regular express to prepend previous fields by their table name if that's not the case already
1094 0 ▶ $tbl_o->prefixed( $db ne $new_db ? 3 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$db ne $new_db ? : 0 0 0
1095 # Prefix for previous fields list
1096 0 my $prev_prefix = $tbl_o->prefix;
1097 0 my $prev_fields_hash = $q->table_object->fields;
1098 0 my $prev_fields_list = CORE::join( '|', sort( keys( %$prev_fields_hash ) ) );
1099 0 my $re = qr/(?<![\.\"])\b($prev_fields_list)\b/;
1100 0 $prev_fields =~ s/(?<![\.\"])\b($prev_fields_list)\b/${prev_prefix}.$1/gs;
1101 0 ▶ my $fields = $new_fields ? CORE::join( ', ', $prev_fields, $new_fields ) : $prev_fields;
Branch: 1 branch
BranchTrueFalseTotal
$new_fields ? : 0 0 0
1102 0 $q_source->join_fields( $fields );
1103 0 ▶ $q_source->from_table->push(
Branch: 3 branches
BranchTrueFalseTotal
unless $q_source->from_table->length 0 0 0
$q_source->table_alias ? : 0 0 0
$q_source->table_object->prefixed ? : 0 0 0
1104 $q_source->table_alias
1105 ? sprintf( '%s AS %s', $q_source->table_object->name, $q_source->table_alias )
1106 : ( $q_source->table_object->prefixed ? $q_source->table_object->prefix : $q_source->table_object->name )
1107 ) if( !$q_source->from_table->length );
1108 0 my $left_join = '';
1109 0 my $condition = '';
1110 0 my $format_condition;
1111 $format_condition = sub
1112 0 ▶ {
Subroutine __ANON__: not called CC=22 SCAR=62.3
1113 0 my @vals = ();
1114 0 my $vals = shift( @_ );
1115 0 my $op = shift( @_ );
1116 0 my @res = ();
1117 0 my $fields_tables = {};
1118 0 ▶ while( scalar( @$vals ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$vals) 0 0 0
1119 {
1120 0 ▶ if( $self->_is_object( $vals->[0] ) && $vals->[0]->isa( 'DB::Object::Operator' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($vals->[0]) and $vals->[0]->isa('DB::Object::Operator')) { } 0 0 0
Condition0%0/3
$self->_is_object($vals->[0]) and $vals->[0]->isa("DB::Object::Operator")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($vals->[0]) and $vals->[0]->isa("DB::Object::Operator")
$self->_is_object($vals->[0]) $vals->[0]->isa("DB::Object::Operator")
Truth table0%0/3
A and B
A= $self->_is_object($vals->[0])B= $vals->[0]->isa("DB::Object::Operator")
ABresult
0X0
100
111
1121 {
1122 0 my $sub_obj = shift( @$vals );
1123 0 my $sub_op = $sub_obj->operator;
1124 0 my( @sub_vals ) = $sub_obj->value;
1125 0 my $this_ref = $format_condition->( \@sub_vals, $sub_op );
1126 0 ▶ CORE::push( @res, $this_ref->{clause} ) if( length( $this_ref->{clause} ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $this_ref->{"clause"} 0 0 0
1127 0 my $tmp = $this_ref->{fields_tables};
1128 0 my @those_table_names = keys( %$tmp );
1129 0 @$fields_tables{ @those_table_names } = @$tmp{ @those_table_names };
1130 }
1131 else
1132 {
1133 0 ▶ if( $self->_is_object( $vals->[0] ) && $vals->[0]->isa( 'DB::Object::Fields::Overloaded' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($vals->[0]) and $vals->[0]->isa("DB::Object::Fields::Overloaded")) 0 0 0
Condition0%0/3
$self->_is_object($vals->[0]) and $vals->[0]->isa("DB::Object::Fields::Overloaded")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($vals->[0]) and $vals->[0]->isa("DB::Object::Fields::Overloaded")
$self->_is_object($vals->[0]) $vals->[0]->isa("DB::Object::Fields::Overloaded")
Truth table0%0/3
A and B
A= $self->_is_object($vals->[0])B= $vals->[0]->isa("DB::Object::Fields::Overloaded")
ABresult
0X0
100
111
1134 {
1135 0 my $f1 = shift( @$vals );
1136 0 ▶ $f1->field->prefixed( $multi_db ? 3 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$multi_db ? : 0 0 0
1137 0 CORE::push( @res, "$f1" );
1138 0 ▶ $fields_tables->{ $f1->field->table }++ if( !$fields_tables->{ $f1->field->table } );
Branch: 1 branch
BranchTrueFalseTotal
unless $$fields_tables{$f1->field->table} 0 0 0
1139 0 next;
1140 }
1141  
1142 0 my( $f1, $f2 ) = ( shift( @$vals ), shift( @$vals ) );
1143 0 my $i_am_negative = 0;
1144 0 ▶ if( $self->_is_object( $f2 ) && $f2->isa( 'DB::Object::NOT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($f2) and $f2->isa("DB::Object::NOT")) 0 0 0
Condition0%0/3
$self->_is_object($f2) and $f2->isa("DB::Object::NOT")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($f2) and $f2->isa("DB::Object::NOT")
$self->_is_object($f2) $f2->isa("DB::Object::NOT")
Truth table0%0/3
A and B
A= $self->_is_object($f2)B= $f2->isa("DB::Object::NOT")
ABresult
0X0
100
111
1145 {
1146 0 ( $f2 ) = $f2->value;
1147 0 $i_am_negative++;
1148 }
1149  
1150 0 my( $field1, $field2 );
1151 0 ▶ if( $self->_is_object( $f1 ) && $f1->isa( 'DB::Object::Fields::Field' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($f1) and $f1->isa('DB::Object::Fields::Field')) { } 0 0 0
Condition0%0/3
$self->_is_object($f1) and $f1->isa("DB::Object::Fields::Field")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($f1) and $f1->isa("DB::Object::Fields::Field")
$self->_is_object($f1) $f1->isa("DB::Object::Fields::Field")
Truth table0%0/3
A and B
A= $self->_is_object($f1)B= $f1->isa("DB::Object::Fields::Field")
ABresult
0X0
100
111
1152 {
1153 0 ▶ $f1->prefixed( $multi_db ? 3 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$multi_db ? : 0 0 0
1154 0 $field1 = $f1->name;
1155 0 ▶ $fields_tables->{ $f1->table }++ if( !$fields_tables->{ $f1->table } );
Branch: 1 branch
BranchTrueFalseTotal
unless $$fields_tables{$f1->table} 0 0 0
1156 }
1157 else
1158 {
1159 0 ▶ $field1 = $multi_db ? "$new_db.$new_table.$f1" : "$new_table.$f1";
Branch: 1 branch
BranchTrueFalseTotal
$multi_db ? : 0 0 0
1160 }
1161 0 ▶ if( $self->_is_object( $f2 ) && $f2->isa( 'DB::Object::Fields::Field' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_object($f2) and $f2->isa('DB::Object::Fields::Field')) { } 0 0 0
Condition0%0/3
$self->_is_object($f2) and $f2->isa("DB::Object::Fields::Field")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($f2) and $f2->isa("DB::Object::Fields::Field")
$self->_is_object($f2) $f2->isa("DB::Object::Fields::Field")
Truth table0%0/3
A and B
A= $self->_is_object($f2)B= $f2->isa("DB::Object::Fields::Field")
ABresult
0X0
100
111
1162 {
1163 0 ▶ $f2->prefixed( $multi_db ? 3 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$multi_db ? : 0 0 0
1164 0 $field2 = $f2->name;
1165 0 ▶ $fields_tables->{ $f2->table }++ if( !$fields_tables->{ $f2->table } );
Branch: 1 branch
BranchTrueFalseTotal
unless $$fields_tables{$f2->table} 0 0 0
1166 }
1167 else
1168 {
1169 0 ▶ $field2 = $multi_db ? "$new_db.$new_table.$f2" : "$new_table.$f2";
Branch: 1 branch
BranchTrueFalseTotal
$multi_db ? : 0 0 0
1170 }
1171 0 ▶ CORE::push( @res, $i_am_negative ? "$field1 != $field2" : "$field1 = $field2" );
Branch: 1 branch
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
1172 }
1173 }
1174 return({
1175 0 clause => CORE::join( $op, @res ),
1176 fields_tables => $fields_tables,
1177 });
1178 0 };
1179  
1180 # $on is either a $dbh->AND, or $dbh->OR
1181 0 ▶ if( defined( $on ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $on) { } 0 0 0
1182 {
1183 0 ▶ if( $self->_is_object( $on ) && $on->isa( 'DB::Object::Operator' ) )
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_is_object($on) and $on->isa('DB::Object::Operator')) { } 0 0 0
elsif ($self->_is_object($on) and $on->isa('DB::Object::Fields::Overloaded')) { } 0 0 0
elsif ($self->_is_array($on)) { } 0 0 0
elsif ($self->_is_hash($on, 'strict')) { } 0 0 0
Condition0%0/3
$self->_is_object($on) and $on->isa("DB::Object::Operator")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($on) and $on->isa("DB::Object::Operator")
$self->_is_object($on) $on->isa("DB::Object::Operator")
Truth table0%0/3
A and B
A= $self->_is_object($on)B= $on->isa("DB::Object::Operator")
ABresult
0X0
100
111
1184 {
1185 0 my $op = $on->operator;
1186 0 my( @vals ) = $on->value;
1187 0 my $ret = $format_condition->( \@vals, $op );
1188 0 ▶ my $as = $q_target->table_alias ? sprintf( ' AS %s', $q_target->table_alias ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$q_target->table_alias ? : 0 0 0
1189 0 $left_join = "LEFT JOIN ${new_table}${as} ON $ret->{clause}";
1190 }
1191 ▶ elsif( $self->_is_object( $on ) && $on->isa( 'DB::Object::Fields::Overloaded' ) )
Condition0%0/3
$self->_is_object($on) and $on->isa("DB::Object::Fields::Overloaded")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($on) and $on->isa("DB::Object::Fields::Overloaded")
$self->_is_object($on) $on->isa("DB::Object::Fields::Overloaded")
Truth table0%0/3
A and B
A= $self->_is_object($on)B= $on->isa("DB::Object::Fields::Overloaded")
ABresult
0X0
100
111
1192 {
1193 0 ▶ my $as = $q_target->table_alias ? sprintf( ' AS %s', $q_target->table_alias ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$q_target->table_alias ? : 0 0 0
1194 0 $left_join = "LEFT JOIN ${new_table}${as} ON ${on}";
1195 }
1196 elsif( $self->_is_array( $on ) )
1197 {
1198 0 my $ret = $format_condition->( $on, 'AND' );
1199 0 ▶ my $as = $q_target->table_alias ? sprintf( ' AS %s', $q_target->table_alias ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$q_target->table_alias ? : 0 0 0
1200 0 $left_join = "LEFT JOIN ${new_table}${as} ON $ret->{clause}";
1201 }
1202 # There is a second parameter - if so this is the condition of the 'LEFT JOIN'
1203 elsif( $self->_is_hash( $on => 'strict' ) )
1204 {
1205 # Previous join
1206 0 my $join_ref = $q_source->left_join;
1207 0 my $def = { on => $on, table_object => $q_target->table_object, query_object => $q_target };
1208 ## Add the current one
1209 0 ▶ if( $multi_db )
Branch: 1 branch
BranchTrueFalseTotal
if ($multi_db) { } 0 0 0
1210 {
1211 0 $join_ref->{ "$new_db.$new_table" } = $def;
1212 }
1213 else
1214 {
1215 0 $join_ref->{ $new_table } = $def;
1216 }
1217 # (Re)build the LEFT JOIN ... ON ... definition
1218 0 my @join_data = ();
1219 0 foreach my $joined ( keys( %$join_ref ) )
1220 {
1221 0 my $condition = $join_ref->{ $joined }->{on};
1222 0 my $to = $join_ref->{ $joined }->{table_object};
1223 0 my $qo = $join_ref->{ $joined }->{query_object};
1224 0 my $join_table_name = $to->prefix;
1225 0 my $join_table_alias = '';
1226 0 ▶ if( length( $join_table_alias = $qo->table_alias ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length($join_table_alias = $qo->table_alias)) 0 0 0
1227 {
1228 0 $join_table_alias = " AS $join_table_alias";
1229 }
1230 0 push( @join_data, "LEFT JOIN ${join_table_name}${join_table_alias} ON " . CORE::join( ' AND ', map{ "$_=$condition->{ $_ }" } keys( %$condition ) ) );
1231 }
1232 0 $left_join = CORE::join( ' ', @join_data );
1233 }
1234 else
1235 {
1236 0 ▶ warn( "Warning: I have no clue what to do with '$on' (", overload::StrVal( $on ), ") in this join for table \"", $q->table_object->name, "\"" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
1237 }
1238 }
1239 # Otherwise, this is a straight JOIN
1240 else
1241 {
1242 # $q_source->from_table->push( $multi_db ? "$new_db.$new_table" : $new_table );
1243 0 ▶ $q_source->from_table->push(
Branch: 2 branches
BranchTrueFalseTotal
$q_target->table_alias ? : 0 0 0
$q_target->table_object->prefixed ? : 0 0 0
1244 $q_target->table_alias
1245 ? sprintf( '%s AS %s', $q_target->table_object->name, $q_target->table_alias )
1246 : ( $q_target->table_object->prefixed ? $q_target->table_object->prefix : $q_target->table_object->name )
1247 );
1248 }
1249 0 my $from = $q_source->from_table->join( ', ' );
1250 0 my $clause = $q_source->_query_components( 'select', { no_bind_copy => 1 } );
1251 # Copy WHERE (and other clause) elements directly into $q_source->elements so that
1252 # Statement::execute() can find the bind types regardless of the use_bind setting.
1253 # We do this explicitly rather than via _save_bind() because _save_bind() is gated
1254 # on use_bind, which may be 0 even when placeholders are present.
1255 # NOTE: $where->elements returns a Module::Generic::Array of Element objects directly
1256 # (NOT an Elements wrapper). Pass ->list to Elements::push(), not the array object itself.
1257 {
1258 0 my $elems = $q_source->new_elements;
1259 0 my $where = $q_source->where;
1260 0 my $limit = $q_source->limit;
1261 0 ▶ if( $where )
Branch: 1 branch
BranchTrueFalseTotal
if ($where) 0 0 0
1262 {
1263 0 my $where_arr = $where->elements;
1264 0 ▶ $elems->push( $where_arr->list ) if( $where_arr && $where_arr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $where_arr and $where_arr->length 0 0 0
Condition0%0/3
$where_arr and $where_arr->length
!ll&&!rl&&r
000
MC/DC0%0/2
$where_arr and $where_arr->length
$where_arr $where_arr->length
Truth table0%0/3
A and B
A= $where_arrB= $where_arr->length
ABresult
0X0
100
111
1265 }
1266 0 ▶ if( $limit )
Branch: 1 branch
BranchTrueFalseTotal
if ($limit) 0 0 0
1267 {
1268 0 my $limit_arr = $limit->elements;
1269 0 ▶ $elems->push( $limit_arr->list ) if( $limit_arr && $limit_arr->length );
Branch: 1 branch
BranchTrueFalseTotal
if $limit_arr and $limit_arr->length 0 0 0
Condition0%0/3
$limit_arr and $limit_arr->length
!ll&&!rl&&r
000
MC/DC0%0/2
$limit_arr and $limit_arr->length
$limit_arr $limit_arr->length
Truth table0%0/3
A and B
A= $limit_arrB= $limit_arr->length
ABresult
0X0
100
111
1270 }
1271 0 $q_source->elements( $elems );
1272  
1273 }
1274 0 my @query = ( "SELECT ${fields} FROM ${from} ${left_join}" );
1275 0 ▶ push( @query, @$clause ) if( @$clause );
Branch: 1 branch
BranchTrueFalseTotal
if @$clause 0 0 0
1276 0 my $statement = CORE::join( ' ', @query );
1277 0 $q_source->query( $statement );
1278 0 ▶ my $sth = $tbl_o->_cache_this( $q_source ) ||
Condition0%0/2
$tbl_o->_cache_this($q_source) || (return $self->error("Error while preparing query to select:\n", $q_source->as_string, $tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->_cache_this($q_source) || (return $self->error("Error while preparing query to select:\n", $q_source->as_string, $tbl_o->error))
$tbl_o->_cache_this($q_source)
Truth table0%0/2
A
A= $tbl_o->_cache_this($q_source)
Aresult
11
00
1279 return( $self->error( "Error while preparing query to select:\n", $q_source->as_string(), $tbl_o->error ) );
1280 # Routines such as as_string() expect an array on pupose so we do not have to commit the action
1281 # but rather get the statement string. At the end, we write:
1282 # $obj->select() to really select
1283 # $obj->select->as_string() to ONLY get the formatted statement
1284 # wantarray() returns the undefined value in void context, which is typical use of a real select command
1285 # i.e. $obj->select();
1286 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
1287 {
1288 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing query to select:\n", $q_source->as_string, "\nError: ", $sth->error) 0 0 0
1289 return( $self->error( "Error while executing query to select:\n", $q_source->as_string(), "\nError: ", $sth->error() ) );
1290 }
1291 0 return( $sth );
1292 }
1293  
1294 # NOTE: number_of_fields -> NUM_OF_FIELDS
1295 # <https://metacpan.org/pod/DBI#NUM_OF_FIELDS>
1296 0 ▶sub number_of_fields { return( shift->_get_statement_attribute( 'NUM_OF_FIELDS' ) ); }
Subroutine number_of_fields: not called CC=1 SCAR=6.9
Pod documented
1297  
1298 # NOTE: number_of_params -> NUM_OF_PARAMS
1299 # <https://metacpan.org/pod/DBI#NUM_OF_PARAMS>
1300 0 ▶sub number_of_params { return( shift->_get_statement_attribute( 'NUM_OF_PARAMS' ) ); }
Subroutine number_of_params: not called CC=1 SCAR=6.9
Pod documented
1301  
1302 sub object
1303 0 ▶{
Subroutine object: not called CC=3 SCAR=24.8
Pod documented
1304 0 my $self = shift( @_ );
1305 # This is intended for statement to fetched their object:
1306 # my $obj = $table->select( '*' )->object();
1307 # my $obj = $table->select( '*' )
1308 # would merly execute the statement before returning its object, but there are conditions
1309 # such like using a SELECT to create a table where we do not want the statement to be executed already
1310 0 ▶ return( $self->{sth} ) if( $self->{sth} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"sth"} 0 0 0
1311 # More sensible approach will return a special Module::Generic::Null object to avoid perl complaining of 'called on undef value' if this is used in chaining
1312 0 ▶ return( Module::Generic::Null->new ) if( want( 'OBJECT' ) );
Branch: 1 branch
BranchTrueFalseTotal
if want("OBJECT") 0 0 0
1313 0 return;
1314 }
1315  
1316 sub priority
1317 0 ▶{
Subroutine priority: not called CC=12 SCAR=50.5
Pod documented
1318 0 my $self = shift( @_ );
1319 0 my $prio = shift( @_ );
1320 0 my $map =
1321 {
1322 0 => 'LOW_PRIORITY',
1323 1 => 'HIGH_PRIORITY',
1324 };
1325 ## Bad argument. Do not bother
1326 0 ▶ return( $self ) if( !exists( $map->{ $prio } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $map->{$prio} 0 0 0
1327  
1328 my $query = $self->{query} ||
1329 0 ▶ return( $self->error( "No query to set priority for was provided." ) );
Condition0%0/2
$self->{'query'} || (return $self->error('No query to set priority for was provided.'))
l!l
00
MC/DC0%0/1
$self->{'query'} || (return $self->error('No query to set priority for was provided.'))
$self->{'query'}
Truth table0%0/2
A
A= $self->{'query'}
Aresult
11
00
1330 0 my $type = uc( ( $query =~ /^\s*(\S+)\s+/ )[ 0 ] );
1331 0 my @allowed = qw( DELETE INSERT REPLACE SELECT UPDATE );
1332 0 my $allowed = CORE::join( '|', @allowed );
1333 # Ignore if not allowed
1334 0 ▶ if( !scalar( grep{ /^$type$/i } @allowed ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar grep({/^$type$/i;} @allowed)) 0 0 0
1335 {
1336 0 $self->error( "You may not set priority on statement of type \U$type\E:\n$query" );
1337 0 return( $self );
1338 }
1339 # Incompatible. Do not bother going further
1340 0 ▶ return( $self ) if( $query =~ /^\s*(?:$allowed)\s+(?:DELAYED|LOW_PRIORITY|HIGH_PRIORITY)\s+/i );
Branch: 1 branch
BranchTrueFalseTotal
if $query =~ /^\s*(?:$allowed)\s+(?:DELAYED|LOW_PRIORITY|HIGH_PRIORITY)\s+/i 0 0 0
1341 # SELECT with something else than HIGH_PRIORITY is incompatible, so do not bother to go further
1342 0 ▶ return( $self ) if( $prio != 1 && $type =~ /^(?:SELECT)$/i );
Branch: 1 branch
BranchTrueFalseTotal
if $prio != 1 and $type =~ /^(?:SELECT)$/i 0 0 0
Condition0%0/3
$prio != 1 and $type =~ /^(?:SELECT)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$prio != 1 and $type =~ /^(?:SELECT)$/i
$prio != 1 $type =~ /^(?:SELECT)$/i
Truth table0%0/3
A and B
A= $prio != 1B= $type =~ /^(?:SELECT)$/i
ABresult
0X0
100
111
1343 0 ▶ return( $self ) if( $prio != 0 && $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i );
Branch: 1 branch
BranchTrueFalseTotal
if $prio != 0 and $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i 0 0 0
Condition0%0/3
$prio != 0 and $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$prio != 0 and $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
$prio != 0 $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
Truth table0%0/3
A and B
A= $prio != 0B= $type =~ /^(?:DELETE|INSERT|REPLACE|UPDATE)$/i
ABresult
0X0
100
111
1344  
1345 0 $query =~ s/^(\s*)($allowed)(\s+)/$1$2 $map->{ $prio } /i;
1346 # $self->{ 'query' } = $query;
1347 # my $sth = $self->prepare( $query ) ||
1348 0 ▶ my $sth = $self->_cache_this( $query ) ||
Condition0%0/2
$self->_cache_this($query) || (return $self->error("Error while preparing new low priority query:\n$query"))
l!l
00
MC/DC0%0/1
$self->_cache_this($query) || (return $self->error("Error while preparing new low priority query:\n$query"))
$self->_cache_this($query)
Truth table0%0/2
A
A= $self->_cache_this($query)
Aresult
11
00
1349 return( $self->error( "Error while preparing new low priority query:\n$query" ) );
1350 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
1351 {
1352 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing new low priority query:\n$query") 0 0 0
1353 return( $self->error( "Error while executing new low priority query:\n$query" ) );
1354 }
1355 0 return( $sth );
1356 }
1357  
1358 sub promise
1359 0 ▶{
Subroutine promise: not called CC=2 SCAR=17.9
Pod documented
1360 0 my $self = shift( @_ );
1361 0 ▶ $self->_load_class( 'Promise::Me' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Promise::Me") or return $self->pass_error 0 0 0
1362 return( Promise::Me->new(sub
1363 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1364 0 return( $self->execute( @_ ) );
1365 0 }) );
1366 }
1367  
1368 0 ▶sub query { return( shift->_set_get_scalar( 'query', @_ ) ); }
Subroutine query: not called CC=1 SCAR=6.9
Pod documented
1369  
1370 1 ▶sub query_object { return( shift->_set_get_object_without_init( 'query_object', 'DB::Object::Query', @_ ) ); }
Subroutine query_object: called CC=1 SCAR=0.0
Pod documented
1371  
1372 0 ▶sub query_time { return( shift->_set_get_datetime( 'query_time', @_ ) ); }
Subroutine query_time: not called CC=1 SCAR=6.9
Pod documented
1373  
1374 sub rollback
1375 0 ▶{
Subroutine rollback: not called CC=5 SCAR=34.0
Pod documented
1376 0 my $self = shift( @_ );
1377 0 ▶ if( $self->{sth} && $self->param( 'autocommit' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sth"} and $self->param("autocommit")) 0 0 0
Condition0%0/3
$self->{"sth"} and $self->param("autocommit")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"sth"} and $self->param("autocommit")
$self->{"sth"} $self->param("autocommit")
Truth table0%0/3
A and B
A= $self->{"sth"}B= $self->param("autocommit")
ABresult
0X0
100
111
1378 {
1379 0 ▶ my $sth = $self->prepare( "ROLLBACK" ) || return( $self->error( "An error occurred while preparing query to rollback: ", $self->error ) );
Condition0%0/2
$self->prepare('ROLLBACK') || (return $self->error('An error occurred while preparing query to rollback: ', $self->error))
l!l
00
MC/DC0%0/1
$self->prepare('ROLLBACK') || (return $self->error('An error occurred while preparing query to rollback: ', $self->error))
$self->prepare('ROLLBACK')
Truth table0%0/2
A
A= $self->prepare('ROLLBACK')
Aresult
11
00
1380 0 ▶ $sth->execute() || return( $self->error( "Error occurred while executing query to rollback: ", $sth->error ) );
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error occurred while executing query to rollback: ", $sth->error) 0 0 0
1381 0 $sth->finish();
1382 }
1383 0 return( $self );
1384 }
1385  
1386 sub rows(@)
1387 0 ▶{
Subroutine rows: not called CC=4 SCAR=30.0
Pod documented
1388 0 my $self = shift( @_ );
1389 0 ▶ if( !$self->executed() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->executed) 0 0 0
1390 {
1391 0 ▶ $self->execute() || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->execute or return $self->pass_error 0 0 0
1392 }
1393 # $self->_cleanup();
1394 # $rv = $sth->rows;
1395 0 ▶ if( !ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $self) { } 0 0 0
1396 {
1397 0 return( $DBI::rows );
1398 }
1399 else
1400 {
1401 0 return( $self->{sth}->rows() );
1402 }
1403 }
1404  
1405 # NOTE: statement -> Statement
1406 # <https://metacpan.org/pod/DBI#Statement>
1407 0 ▶sub statement { return( shift->_get_statement_attribute( 'Statement' ) ); }
Subroutine statement: not called CC=1 SCAR=6.9
Pod documented
1408  
1409 # A DBI::sth object. This should rather be a _set_get_object helper method, but I am not 100% sure if this is really a DBI::sth
1410 0 ▶sub sth { return( shift->_set_get_scalar( 'sth', @_ ) ); }
Subroutine sth: not called CC=1 SCAR=6.9
Pod documented
1411  
1412 0 ▶sub table { return( shift->{table} ); }
Subroutine table: not called CC=1 SCAR=6.9
Pod documented
1413  
1414 0 ▶sub table_object { return( shift->_set_get_object_without_init( 'table_object', 'DB::Object::Tables', @_ ) ); }
Subroutine table_object: not called CC=1 SCAR=6.9
Pod documented
1415  
1416 sub undo
1417 0 ▶{
Subroutine undo: not called CC=1 SCAR=6.9
Pod documented
1418 0 goto( &rollback );
1419 }
1420  
1421 0 ▶sub wait { return( shift->error( "Method wait() is not implemented by this driver." ) ); }
Subroutine wait: not called CC=1 SCAR=6.9
Pod documented
1422  
1423 # Used to get the cached field names by _convert_datetime2object
1424 sub _cache_field_names
1425 1 ▶{
Subroutine _cache_field_names: called CC=2 SCAR=7.0
1426 1 my $self = shift( @_ );
1427 1 my $names;
1428 1 ▶ if( !( $names = $self->{_cache_field_names} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($names = $self->{"_cache_field_names"}) 1 0 1
1429 {
1430 1 $names = $self->{_cache_field_names} = $self->field_names;
1431 }
1432 1 return( $names );
1433 }
1434  
1435 # Used to get the cached field names by _convert_datetime2object
1436 sub _cache_field_types
1437 1 ▶{
Subroutine _cache_field_types: called CC=2 SCAR=7.0
1438 1 my $self = shift( @_ );
1439 1 my $types;
1440 1 ▶ if( !( $types = $self->{_cache_field_types} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($types = $self->{"_cache_field_types"}) 1 0 1
1441 {
1442 1 $types = $self->{_cache_field_types} = $self->field_types;
1443 }
1444 1 return( $types );
1445 }
1446  
1447 # sub _convert_datetime2object { return( shift->database_object->_convert_datetime2object( @_ ) ); }
1448 # sub _convert_datetime2object
1449 # {
1450 # my $self = shift( @_ );
1451 # my $opts = $self->_get_args_as_hash( @_ );
1452 # return( $opts->{data} );
1453 # }
1454 sub _convert_datetime2object
1455 0 ▶{
Subroutine _convert_datetime2object: not called CC=18 SCAR=58.3
1456 0 my $self = shift( @_ );
1457 0 my $opts = $self->_get_args_as_hash( @_ );
1458 0 ▶ my $sth = $opts->{statement} || return( $self->error( "No statement handler was provided to convert data from json to perl." ) );
Condition0%0/2
$opts->{'statement'} || (return $self->error('No statement handler was provided to convert data from json to perl.'))
l!l
00
MC/DC0%0/1
$opts->{'statement'} || (return $self->error('No statement handler was provided to convert data from json to perl.'))
$opts->{'statement'}
Truth table0%0/2
A
A= $opts->{'statement'}
Aresult
11
00
1459 # my $data = $opts->{data} || return( $self->error( "No data was provided to convert from json to perl." ) );
1460 0 ▶ return( $opts->{data} ) if( !defined( $opts->{data} ) || !CORE::length( $opts->{data} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"data"} and length $opts->{"data"} 0 0 0
Condition0%0/3
defined $opts->{"data"} and length $opts->{"data"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"data"} and length $opts->{"data"}
defined $opts->{"data"} length $opts->{"data"}
Truth table0%0/3
A and B
A= defined $opts->{"data"}B= length $opts->{"data"}
ABresult
0X0
100
111
1461 0 my $data = $opts->{data};
1462 # my $names = $sth->FETCH('NAME');
1463 # my $types = $sth->FETCH('pg_type');
1464 # Get the cached field names and types that we stored after executing the query, but before we finished reading the statement
1465 0 my $names = $self->_cache_field_names;
1466 0 my $types = $self->_cache_field_types;
1467 0 my $mode = ref( $data );
1468  
1469 0 ▶ for( my $i = 0; $i < scalar( @$names ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$names) 0 0 0
1470 {
1471 0 ▶ if( $types->[$i] eq DBI::SQL_DATE ||
Branch: 1 branch
BranchTrueFalseTotal
if ($types->[$i] eq &DBI::SQL_DATE() or $types->[$i] eq &DBI::SQL_TIMESTAMP() or $types->[$i] eq "date" or $types->[$i] eq "timestamp") 0 0 0
Condition0%0/9
$types->[$i] eq &DBI::SQL_DATE() or $types->[$i] eq &DBI::SQL_TIMESTAMP() or $types->[$i] eq "date" or $types->[$i] eq "timestamp"
l!l&&r!l&&!r
000
$types->[$i] eq &DBI::SQL_DATE() or $types->[$i] eq &DBI::SQL_TIMESTAMP() or $types->[$i] eq "date"
l!l&&r!l&&!r
000
$types->[$i] eq &DBI::SQL_DATE() or $types->[$i] eq &DBI::SQL_TIMESTAMP()
l!l&&r!l&&!r
000
MC/DC0%0/4
$types->[$i] eq &DBI::SQL_DATE() or $types->[$i] eq &DBI::SQL_TIMESTAMP() or $types->[$i] eq "date" or $types->[$i] eq "timestamp"
$types->[$i] eq &DBI::SQL_DATE() $types->[$i] eq &DBI::SQL_TIMESTAMP() $types->[$i] eq "date" $types->[$i] eq "timestamp"
Truth table0%0/5
A or B or C or D
A= $types->[$i] eq &DBI::SQL_DATE()B= $types->[$i] eq &DBI::SQL_TIMESTAMP()C= $types->[$i] eq "date"D= $types->[$i] eq "timestamp"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1472 $types->[$i] eq DBI::SQL_TIMESTAMP ||
1473 $types->[$i] eq 'date' ||
1474 $types->[$i] eq 'timestamp' )
1475 {
1476 0 ▶ if( $mode eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'ARRAY') { } 0 0 0
elsif ($mode eq 'HASH') { } 0 0 0
1477 {
1478 0 ▶ for( my $j = 0; $j < scalar( @$data ); $j++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($j < scalar @$data) 0 0 0
1479 {
1480 0 ▶ next if( !$data->[ $j ]->{ $names->[ $i ] } );
Branch: 1 branch
BranchTrueFalseTotal
unless $data->[$j]{$names->[$i]} 0 0 0
1481 0 my $dt = $self->_convert_string2datetime( $data->[ $j ]->{ $names->[ $i ] } );
1482 0 ▶ if( !defined( $dt ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dt) 0 0 0
1483 {
1484 0 ▶ warn( $self->error ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
1485 }
1486 0 $data->[ $j ]->{ $names->[ $i ] } = $dt;
1487 }
1488 }
1489 elsif( $mode eq 'HASH' )
1490 {
1491 0 ▶ next if( !$data->{ $names->[ $i ] } );
Branch: 1 branch
BranchTrueFalseTotal
unless $$data{$names->[$i]} 0 0 0
1492 0 my $dt = $self->_convert_string2datetime( $data->{ $names->[ $i ] } );
1493 0 ▶ if( !defined( $dt ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dt) 0 0 0
1494 {
1495 0 ▶ warn( $self->error ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
1496 }
1497 0 $data->{ $names->[ $i ] } = $dt;
1498 }
1499 }
1500 }
1501 0 return( $data );
1502 }
1503  
1504 # sub _convert_json2hash { return( shift->database_object->_convert_json2hash( @_ ) ); }
1505 # Does nothing by default
1506 # Must be superseded by the subclasses because we use the data types like PG_JSON, PG_JSONB
1507 # and we don't have them at this top level
1508 sub _convert_json2hash
1509 1 ▶{
Subroutine _convert_json2hash: called CC=1 SCAR=0.0
1510 1 my $self = shift( @_ );
1511 1 my $opts = $self->_get_args_as_hash( @_ );
1512 1 return( $opts->{data} );
1513 }
1514  
1515 sub _convert_string2datetime
1516 0 ▶{
Subroutine _convert_string2datetime: not called CC=4 SCAR=30.0
1517 0 my $self = shift( @_ );
1518 0 ▶ my $str = shift( @_ ) || return;
Condition0%0/2
shift @_ || (return)
l!l
00
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1519 0 my $dt = $self->_parse_timestamp( $str );
1520 0 ▶ if( !defined( $dt ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $dt) { } 0 0 0
elsif (not $dt) { } 0 0 0
1521 {
1522 0 return( $self->pass_error );
1523 }
1524 # An empty string means it did not fail, but probably did not recognise the format
1525 elsif( !$dt )
1526 {
1527 0 return( $str );
1528 }
1529 0 return( $dt );
1530 }
1531  
1532 sub _get_statement_attribute
1533 2 ▶{
Subroutine _get_statement_attribute: called CC=5 SCAR=17.4
1534 2 my $self = shift( @_ );
1535 2 my $attr = shift( @_ );
1536 2 ▶ if( !length( $attr // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (length($attr // "")) 0 2 2
Condition50%1/2
$attr // ""
l!l
20
MC/DC0%0/1
$attr // ""
$attr
Truth table50%1/2
A
A= $attr
Aresult
11
00
1537 {
1538 0 return( $self->error( "No statement attribute was provided to retrieve its value." ) );
1539 }
1540 2 ▶ my $sth = $self->{sth} || die( "Unable to get the underlying statement handler!" );
Condition50%1/2
$self->{'sth'} || die('Unable to get the underlying statement handler!')
l!l
20
MC/DC0%0/1
$self->{'sth'} || die('Unable to get the underlying statement handler!')
$self->{'sth'}
Truth table50%1/2
A
A= $self->{'sth'}
Aresult
11
00
1541 2 my $val;
1542 # try-catch
1543 2 local $@;
1544 eval
1545 2 {
1546 # Ensure we stringify
1547 2 $val = $sth->{ "$attr" };
1548 };
1549 2 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
1550 {
1551 0 return( $self->error( "Error retrieving value for '${attr}': $@" ) );
1552 }
1553 2 return( $val );
1554 }
1555  
1556 # NOTE: DESTROY
1557 DESTROY
1558 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
1559 # Do nothing but existing so it is handled by this package
1560 # print( STDERR "DESTROY'ing statement $self ($self->{ 'query' })\n" );
1561 };
1562  
1563 # NOTE: Storable hooks
1564 # We intentionally do NOT freeze DBI handles (dbh/sth) or back-references (dbo/table_object)
1565 # because they are process-local and cannot be safely restored.
1566 # NOTE: For CBOR and Sereal
1567 sub FREEZE
1568 0 ▶{
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
1569 0 my $self = CORE::shift( @_ );
1570 0 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1571 0 my $class = CORE::ref( $self );
1572  
1573 # We keep a strict allow-list to avoid accidentally freezing DBI handles or other
1574 # process-local state.
1575 # my @props = qw(
1576 # as_string bind cache params query query_object selected_fields
1577 # table tie tie_order _fields _cache_field_names _cache_field_types
1578 # );
1579 0 my @props = qw(
1580 as_string bind cache from_table left_join params query query_object selected_fields
1581 table table_object tie tie_order _fields _cache_field_names _cache_field_types
1582 );
1583  
1584 0 my $hash = {};
1585 0 foreach my $prop ( @props )
1586 {
1587 0 ▶ if( CORE::exists( $self->{ $prop } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE") 0 0 0
Condition0%0/6
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
!ll&&!rl&&r
000
exists $self->{$prop} and defined $self->{$prop}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
exists $self->{$prop} defined $self->{$prop} ref $self->{$prop} ne "CODE"
Truth table0%0/4
A and B and C
A= exists $self->{$prop}B= defined $self->{$prop}C= ref $self->{$prop} ne "CODE"
ABCresult
0XX0
10X0
1100
1111
1588 defined( $self->{ $prop } ) &&
1589 CORE::ref( $self->{ $prop } ) ne 'CODE' )
1590 {
1591 0 $hash->{ $prop } = $self->{ $prop };
1592 }
1593 }
1594 0 $hash->{_serial_version} = $DB::Object::SERIALISATION_VERSION;
1595  
1596 # Return an array reference rather than a list so this works with Sereal and CBOR.
1597 # Before Sereal version 4.023, Sereal did not support multiple values returned.
1598 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
1599 {
1600 0 require Sereal::Encoder;
1601 0 require version;
1602  
1603 0 ▶ if( version->parse( Sereal::Encoder->VERSION ) < version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) < "version"->parse("4.023")) 0 0 0
1604 {
1605 0 CORE::return( [$class, $hash] );
1606 }
1607 }
1608  
1609 # But Storable wants a list with the first element being the serialised element
1610 0 CORE::return( $class, $hash );
1611 }
1612  
1613 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
1614  
1615 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
1616  
1617 sub STORABLE_thaw_post_processing
1618 0 ▶{
Subroutine STORABLE_thaw_post_processing: not called CC=1 SCAR=6.9
Pod undocumented
1619 0 my $obj = shift( @_ );
1620 0 my @keys = %$obj;
1621 0 my $class = ref( $obj );
1622 0 my $hash = {};
1623 0 @$hash{ @keys } = @$obj{ @keys };
1624 0 my $self = bless( $hash => $class );
1625 0 return( $self );
1626 }
1627  
1628 sub THAW
1629 0 ▶{
Subroutine THAW: not called CC=20 SCAR=59.4
Pod undocumented
1630 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
1631 # 'CBOR' as the second value.
1632 0 my( $self, undef, @args ) = @_;
1633 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
1634 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
1635 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
1636  
1637 0 ▶ my $sv = CORE::delete( $hash->{_serial_version} ) // 0;
Condition0%0/2
delete $hash->{"_serial_version"} // 0
l!l
00
MC/DC0%0/1
delete $hash->{"_serial_version"} // 0
delete $hash->{"_serial_version"}
Truth table0%0/2
A
A= delete $hash->{"_serial_version"}
Aresult
11
00
1638 0 ▶ if( $sv != $DB::Object::SERIALISATION_VERSION )
Branch: 1 branch
BranchTrueFalseTotal
if ($sv != $DB::Object::SERIALISATION_VERSION) 0 0 0
1639 {
1640 0 require( $EXCEPTION_CLASS );
1641 0 die( $EXCEPTION_CLASS->new({
1642 code => 409, # Conflict
1643 message => sprintf(
1644 "Serialisation version mismatch in %s: expected %d, got %d. Please purge the cache.",
1645 $class,
1646 $DB::Object::SERIALISATION_VERSION,
1647 $sv,
1648 )
1649 }) );
1650 }
1651  
1652 # Since this class is inherited, we also need to load from which we depend, if necessary.
1653 0 ▶ if( $class ne 'DB::Object::Statement' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class ne "DB::Object::Statement") 0 0 0
1654 {
1655 0 require DB::Object;
1656 0 require DB::Object::Statement;
1657 0 my @supported_classes = CORE::values( %$DB::Object::DRIVER2PACK );
1658 0 push( @supported_classes, 'DB::Object' );
1659 0 my $ok_classes = CORE::join( '|', CORE::map{ CORE::quotemeta( $_ ) } @supported_classes );
1660 0 my $base_class = ( $class =~ /^($ok_classes)/ )[0];
1661 0 eval( "require $base_class;" );
1662 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1663 {
1664 0 require( $EXCEPTION_CLASS );
1665 0 die( $EXCEPTION_CLASS->new( "Failure to load $base_class: $@" ) );
1666 }
1667  
1668 # If inheritance is still missing (or incomplete) for any reason, repair it explicitly.
1669 3 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1670  
1671 0 my $stash = \%{"${class}\::"};
1672 0 my $isa_ref;
1673 # We check if the 'ISA' symbol exists in the stash and its ARRAY slot is defined
1674 0 ▶ if( exists( $stash->{ISA} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $stash->{'ISA'} and defined *{"${class}::ISA";}{'ARRAY'}) { } 0 0 0
Condition0%0/3
exists $stash->{"ISA"} and defined *{"${class}::ISA";}{"ARRAY"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $stash->{"ISA"} and defined *{"${class}::ISA";}{"ARRAY"}
exists $stash->{"ISA"} defined *{"${class}::ISA";}{"ARRAY"}
Truth table0%0/3
A and B
A= exists $stash->{"ISA"}B= defined *{"${class}::ISA";}{"ARRAY"}
ABresult
0X0
100
111
1675 0 defined( *{"${class}\::ISA"}{ARRAY} ) )
1676 {
1677 0 $isa_ref = *{"${class}\::ISA"}{ARRAY};
1678 }
1679 else
1680 {
1681 # # Force creation of @ISA array slot
1682 # @{"${class}::ISA"} = ();
1683 # $isa_ref = *{"${class}::ISA"}{ARRAY};
1684 # But I want it to die, so this can be dealt with, and not swept under the rug.
1685 0 die( "Unable to find the \@ISA value in $class. The package contains the following stashes:\n", $self->Module::Generic::dump( $stash ) );
1686 }
1687  
1688 0 my $has_stmt = 0;
1689 0 foreach my $p ( @$isa_ref )
1690 {
1691 # Same as what we can find in modules DB::Object::(Postgres|SQLite|Mysql)::Statement
1692 0 ▶ $has_stmt = 1 if( CORE::defined( $p ) && $p eq 'DB::Object::Statement' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $p and $p eq "DB::Object::Statement" 0 0 0
Condition0%0/3
defined $p and $p eq "DB::Object::Statement"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p and $p eq "DB::Object::Statement"
defined $p $p eq "DB::Object::Statement"
Truth table0%0/3
A and B
A= defined $pB= $p eq "DB::Object::Statement"
ABresult
0X0
100
111
1693 }
1694  
1695 0 ▶ if( !$has_stmt )
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_stmt) 0 0 0
1696 {
1697 0 @$isa_ref = ( 'DB::Object::Statement' );
1698 }
1699 }
1700 0 my $new;
1701 # Storable pattern requires to modify the object it created rather than returning a new one
1702 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
1703 {
1704 0 foreach( CORE::keys( %$hash ) )
1705 {
1706 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
1707 }
1708 0 $new = $self;
1709 }
1710 else
1711 {
1712 0 $new = CORE::bless( $hash => $class );
1713 }
1714 0 CORE::return( $new );
1715 }
1716  
1717 3 1;
1718 # NOTE: POD
1719 __END__
↑ Summary lib/DB/Object/Query.pm »