lib/DB/Object/Statement.pm

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