lib/DB/Object/Query.pm

filter: Statementstmt 7.7% 92 / 1188 Branchbran 3.7% 29 / 774 Conditioncond 0.1% 1 / 530 MC/DCmcdc 0.0% 0 / 295 Subroutinesub 19.7% 19 / 96 Podpod 92.9% 66 / 71 totaltotal 7.0% 207 / 2954 CC 607 SCAR 75.8
CC
607
Cov
5%
__ANON__
6642.0
getdefault
4830.0
select
2550.0
CRAP 1952.4
« lib/DB/Object/Statement.pm ↑ Summary lib/DB/Object.pm »
1 # -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## SQL API Abstraction - ~/lib//mnt/src/perl/DB-Object/lib/DB/Object/Query.pm
4 ## Version v0.11.0
5 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2017/07/19
8 ## Modified 2026/09/26
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 package DB::Object::Query;
15 BEGIN
16 4 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 warnings::register_categories( 'DB::Object' );
20 4 ▶ use parent qw( DB::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶ use vars qw( $VERSION $DEBUG $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶ use DB::Object::Query::Clause;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶ use DB::Object::Query::Elements;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶ use DB::Object::Query::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶ use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 our $DEBUG = 0;
28 4 our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
29 4 our $VERSION = 'v0.11.0';
30 };
31  
32 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 sub init
36 1 ▶{
Subroutine init: called CC=28 SCAR=38.4
Pod documented
37 1 my $self = shift( @_ );
38 1 ▶ $self->{alias} = {} unless( CORE::exists( $self->{alias} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"alias"} 1 0 1
39 1 ▶ $self->{avoid} = [] unless( CORE::exists( $self->{avoid} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"avoid"} 1 0 1
40 1 ▶ $self->{binded} = [] unless( CORE::exists( $self->{binded} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"binded"} 1 0 1
41 # $self->{binded_group} = [] unless( CORE::exists( $self->{binded_group} ) );
42 # $self->{binded_limit} = [] unless( CORE::exists( $self->{binded_limit} ) );
43 # $self->{binded_order} = [] unless( CORE::exists( $self->{binded_order} ) );
44 1 ▶ $self->{binded_types} = [] unless( CORE::exists( $self->{binded_types} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"binded_types"} 1 0 1
45 1 ▶ $self->{binded_values} = [] unless( CORE::exists( $self->{binded_values} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"binded_values"} 1 0 1
46 1 ▶ $self->{binded_where} = [] unless( CORE::exists( $self->{binded_where} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"binded_where"} 1 0 1
47 1 $self->{dirty} = 0;
48 1 ▶ $self->{elements} = undef unless( CORE::exists( $self->{elements} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"elements"} 1 0 1
49 1 ▶ $self->{enhance} = 0 unless( CORE::exists( $self->{enhance} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"enhance"} 1 0 1
50 1 ▶ $self->{from_table} = [] unless( CORE::exists( $self->{from_table} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"from_table"} 1 0 1
51 1 ▶ $self->{from_unixtime} = [] unless( CORE::exists( $self->{from_unixtime} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"from_unixtime"} 1 0 1
52 1 ▶ $self->{group_by} = '' unless( CORE::exists( $self->{group_by} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"group_by"} 1 0 1
53 1 ▶ $self->{having} = '' unless( CORE::exists( $self->{having} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"having"} 1 0 1
54 1 ▶ $self->{join_fields} = '' unless( CORE::exists( $self->{join_fields} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"join_fields"} 1 0 1
55 1 ▶ $self->{left_join} = {} unless( CORE::exists( $self->{left_join} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"left_join"} 1 0 1
56 1 ▶ $self->{limit} = '' unless( CORE::exists( $self->{limit} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"limit"} 1 0 1
57 1 ▶ $self->{local} = {} unless( CORE::exists( $self->{local} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"local"} 1 0 1
58 1 ▶ $self->{order_by} = '' unless( CORE::exists( $self->{order_by} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"order_by"} 1 0 1
59 1 ▶ $self->{prepare_options}= {} unless( CORE::exists( $self->{prepare_options} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"prepare_options"} 1 0 1
60 1 ▶ $self->{query_values} = undef unless( CORE::exists( $self->{query_values} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"query_values"} 1 0 1
61 1 ▶ $self->{reverse} = '' unless( CORE::exists( $self->{reverse} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"reverse"} 1 0 1
62 1 ▶ $self->{sorted} = [] unless( CORE::exists( $self->{sorted} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"sorted"} 1 0 1
63 1 ▶ $self->{table_alias} = '' unless( CORE::exists( $self->{table_alias} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"table_alias"} 1 0 1
64 1 ▶ $self->{table_object} = '' unless( CORE::exists( $self->{table_object} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"table_object"} 1 0 1
65 1 ▶ $self->{unix_timestamp} = [] unless( CORE::exists( $self->{unix_timestamp} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"unix_timestamp"} 1 0 1
66 1 ▶ $self->{where} = '' unless( CORE::exists( $self->{where} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"where"} 1 0 1
67 1 $self->{_init_strict_use_sub} = 1;
68 1 $self->{_exception_class} = $EXCEPTION_CLASS;
69 1 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 1 0 1
70 1 $self->{constant} = {};
71 1 $self->{query} = '';
72 1 $self->{query_reset} = 0;
73 1 $self->{query_reset_core_keys} = [qw(
74 alias binded binded_group binded_limit binded_order binded_types binded_values
75 binded_where dirty from_unixtime group_by having is_upsert limit local order_by reverse
76 sorted table_alias unix_timestamp where
77 from_table join_fields join_tables left_join prepare_options query_values constant
78 query selected_fields tie_order
79 )];
80 1 $self->{selected_fields} = '';
81 1 $self->{table_object} = '';
82 1 $self->{tie_order} = [];
83 1 ▶ unless( $self->{elements} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"elements"}) 1 0 1
84 {
85 1 $self->{elements} = $self->new_elements;
86 }
87 1 return( $self );
88 }
89  
90 0 ▶sub alias { return( shift->_set_get_hash( 'alias', @_ ) ); }
Subroutine alias: not called CC=1 SCAR=6.9
Pod documented
91  
92 0 ▶sub as_string { return( shift->{query} ); }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
93  
94 sub attach
95 0 ▶{
Subroutine attach: not called CC=8 SCAR=42.8
Pod documented
96 0 my $self = shift( @_ );
97 0 my $this = shift( @_ );
98 0 ▶ if( $self->_is_a( $this => 'DB::Object' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($this, 'DB::Object')) { } 0 0 0
elsif ($self->_is_a($this, 'DB::Object::Tables')) { } 0 0 0
99 {
100 0 $self->debug( $this->debug );
101 0 my $base_class = $self->base_class;
102 0 ▶ unless( $self->_is_a( $this => $base_class ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($this, $base_class)) 0 0 0
103 {
104 0 return( $self->error( "Value provided is not a ${base_class} object." ) );
105 }
106 0 ▶ $self->database_object( $this ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->database_object($this) or return $self->pass_error 0 0 0
107 }
108 elsif( $self->_is_a( $this => 'DB::Object::Tables' ) )
109 {
110 0 $self->debug( $this->debug );
111 0 my $base_class = $self->base_class;
112 0 ▶ unless( $self->_is_a( $this => "${base_class}::Tables" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($this, "${base_class}::Tables")) 0 0 0
113 {
114 0 return( $self->error( "Value provided is not a ${base_class}::Tables object." ) );
115 }
116 0 ▶ $self->table_object( $this ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->table_object($this) or return $self->pass_error 0 0 0
117 }
118 else
119 {
120 0 return( $self->error( "No DB::Object or DB::Object::Tables object was provided." ) );
121 }
122 0 $self->debug( $this->debug );
123 0 ▶ if( my $elems = $self->elements )
Branch: 1 branch
BranchTrueFalseTotal
if (my $elems = $self->elements) 0 0 0
124 {
125 0 $elems->attach( $self );
126 }
127 0 return( $self );
128 }
129  
130 0 ▶sub avoid { return( shift->_set_get_array_as_object( 'avoid', @_ ) ); }
Subroutine avoid: not called CC=1 SCAR=6.9
Pod documented
131  
132 0 ▶sub binded { return( shift->_set_get_array_as_object( 'binded', @_ ) ); }
Subroutine binded: not called CC=1 SCAR=6.9
Pod documented
133  
134 0 ▶sub binded_group { return( shift->group->values ); }
Subroutine binded_group: not called CC=1 SCAR=6.9
Pod documented
135  
136 0 ▶sub binded_limit { return( shift->limit->values ); }
Subroutine binded_limit: not called CC=1 SCAR=6.9
Pod documented
137  
138 0 ▶sub binded_order { return( shift->order->values ); }
Subroutine binded_order: not called CC=1 SCAR=6.9
Pod documented
139  
140 # NOTE: sub binded_types is not used anymore as of 2023-07-19 (v0.11.7)
141 0 ▶sub binded_types { return( shift->_set_get_array_as_object( 'binded_types', @_ ) ); }
Subroutine binded_types: not called CC=1 SCAR=6.9
Pod documented
142 # sub binded_types
143 # {
144 # my $self = shift( @_ );
145 # my $arr = $self->new_array;
146 # my $e = $self->elements;
147 # $e->keys->sort->foreach(sub
148 # {
149 # my $k = shift( @_ );
150 # $arr->push( $e->{ $k }->type );
151 # });
152 # return( $arr );
153 # }
154  
155 # sub binded_types_as_param
156 # {
157 # my $self = shift( @_ );
158 # return( $self->error( "The driver has not implemented the method binded_types_as_param." ) );
159 # }
160 sub binded_types_as_param
161 0 ▶{
Subroutine binded_types_as_param: not called CC=1 SCAR=6.9
Pod documented
162 0 my $self = shift( @_ );
163 0 my $params = $self->new_array;
164 $self->elements->foreach(sub
165 0 ▶ {
Subroutine __ANON__: not called CC=5 SCAR=34.0
166 0 my $elem = shift( @_ );
167 0 my $type;
168 0 ▶ if( $elem && $elem->as_is )
Branch: 2 branches
BranchTrueFalseTotal
if ($elem and $elem->as_is) { } 0 0 0
elsif ($elem and defined($type = $elem->type)) { } 0 0 0
Condition0%0/3
$elem and $elem->as_is
!ll&&!rl&&r
000
MC/DC0%0/2
$elem and $elem->as_is
$elem $elem->as_is
Truth table0%0/3
A and B
A= $elemB= $elem->as_is
ABresult
0X0
100
111
169 {
170 0 return;
171 }
172 ▶ elsif( $elem && defined( $type = $elem->type ) )
Condition0%0/3
$elem and defined($type = $elem->type)
!ll&&!rl&&r
000
MC/DC0%0/2
$elem and defined($type = $elem->type)
$elem defined($type = $elem->type)
Truth table0%0/3
A and B
A= $elemB= defined($type = $elem->type)
ABresult
0X0
100
111
173 {
174 0 $params->push( $type );
175 }
176 else
177 {
178 0 $params->push( '' );
179 }
180 0 });
181 0 return( $params );
182 }
183  
184 0 ▶sub binded_values { return( shift->_set_get_array_as_object( 'binded_values', @_ ) ); }
Subroutine binded_values: not called CC=1 SCAR=6.9
Pod documented
185  
186 0 ▶sub binded_where { return( shift->_set_get_array_as_object( 'binded_where', @_ ) ); }
Subroutine binded_where: not called CC=1 SCAR=6.9
Pod documented
187  
188 sub clone
189 0 ▶{
Subroutine clone: not called CC=7 SCAR=40.3
Pod documented
190 0 my $self = shift( @_ );
191 # We make sure to not clone the DBI database handle object
192 0 my $dbo = CORE::delete( $self->{database_object} );
193 0 my( $tbl, $tbl_dbo );
194 0 ▶ if( $tbl = $self->table_object )
Branch: 1 branch
BranchTrueFalseTotal
if ($tbl = $self->table_object) 0 0 0
195 {
196 0 $tbl_dbo = CORE::delete( $tbl->{dbo} );
197 }
198 0 ▶ my $new = $self->Module::Generic::clone ||
Condition0%0/2
$self->Module::Generic::clone || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->Module::Generic::clone || (return $self->pass_error)
$self->Module::Generic::clone
Truth table0%0/2
A
A= $self->Module::Generic::clone
Aresult
11
00
199 return( $self->pass_error );
200 0 ▶ $new->attach( $dbo ) if( defined( $dbo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $dbo 0 0 0
201 0 ▶ $tbl->attach( $tbl_dbo ) if( defined( $tbl_dbo ) && ( !$dbo || $tbl_dbo ne $dbo ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $tbl_dbo and !$dbo || $tbl_dbo ne $dbo 0 0 0
Condition0%0/6
defined $tbl_dbo and !$dbo || $tbl_dbo ne $dbo
!ll&&!rl&&r
000
not $dbo or $tbl_dbo ne $dbo
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $tbl_dbo and !$dbo || $tbl_dbo ne $dbo
defined $tbl_dbo not $dbo $tbl_dbo ne $dbo
Truth table0%0/4
A and not(B) or C
A= defined $tbl_dboB= not $dboC= $tbl_dbo ne $dbo
ABCresult
0XX0
1000
11X1
1011
202 0 return( $new );
203 }
204  
205 sub constant
206 0 ▶{
Subroutine constant: not called CC=8 SCAR=42.8
Pod documented
207 0 my $self = shift( @_ );
208 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
209 {
210 0 my $def = shift( @_ );
211 0 ▶ return( $self->error( "I was expecting a hash reference, but got '$def' instead." ) ) if( !$self->_is_hash( $def => 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($def, "strict") 0 0 0
212 0 foreach my $k (qw( pack file line ))
213 {
214 0 ▶ return( $self->error( "Parameter \"$k\" is missing in hash refernece provided." ) ) if( !$def->{ $k } );
Branch: 1 branch
BranchTrueFalseTotal
unless $def->{$k} 0 0 0
215 }
216 ## sth may or may not be there
217 0 ▶ return( $self->error( "Statement handler provided is not a DB::Object::Statement object." ) ) if( $def->{sth} && ( !$self->_is_object( $def->{sth} ) && !$def->{sth}->isa( 'DB::Object::Statement' ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if $def->{"sth"} and not $self->_is_object($def->{"sth"}) || $def->{"sth"}->isa("DB::Object::Statement") 0 0 0
Condition0%0/6
$def->{"sth"} and not $self->_is_object($def->{"sth"}) || $def->{"sth"}->isa("DB::Object::Statement")
!ll&&!rl&&r
000
$self->_is_object($def->{'sth'}) || $def->{'sth'}->isa('DB::Object::Statement')
l!l&&r!l&&!r
000
MC/DC0%0/3
$def->{"sth"} and not $self->_is_object($def->{"sth"}) || $def->{"sth"}->isa("DB::Object::Statement")
$def->{"sth"} $self->_is_object($def->{'sth'}) $def->{'sth'}->isa('DB::Object::Statement')
Truth table0%0/4
A and not(B || C)
A= $def->{"sth"}B= $self->_is_object($def->{'sth'})C= $def->{'sth'}->isa('DB::Object::Statement')
ABCresult
0XX0
11X0
1010
1001
218 0 $self->{constant} = $def;
219 }
220 0 return( $self->{constant} );
221 }
222  
223 # sub database_object { return( shift->table_object->database_object ) }
224 # NOTE: we cannot simply use the database object of the table, even if it would make sense, because a query object can be instantiated by a database object (see DB::Object->_query_object_create), and when that happens, this method would set the database object of our query object.
225 2 ▶sub database_object { return( shift->_set_get_object_without_init( 'database_object', 'DB::Object', @_ ) ); }
Subroutine database_object: called CC=1 SCAR=0.0
Pod documented
226  
227 sub delete
228 0 ▶{
Subroutine delete: not called CC=17 SCAR=57.2
Pod documented
229 0 my $self = shift( @_ );
230 0 my $constant = $self->constant;
231 0 ▶ if( scalar( keys( %$constant ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$constant) 0 0 0
232 {
233 0 ▶ return( $constant->{sth} ) if( $constant->{sth} && $self->_is_object( $constant->{sth} ) && $constant->{sth}->isa( 'DB::Object::Statement' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement") 0 0 0
Condition0%0/6
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
!ll&&!rl&&r
000
$constant->{"sth"} and $self->_is_object($constant->{"sth"})
!ll&&!rl&&r
000
MC/DC0%0/3
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
$constant->{"sth"} $self->_is_object($constant->{"sth"}) $constant->{"sth"}->isa("DB::Object::Statement")
Truth table0%0/4
A and B and C
A= $constant->{"sth"}B= $self->_is_object($constant->{"sth"})C= $constant->{"sth"}->isa("DB::Object::Statement")
ABCresult
0XX0
10X0
1100
1111
234 }
235 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
236 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
237 return( $self->error( "No database handle could be found." ) );
238 0 ▶ my $table = $tbl_o->name ||
Condition0%0/2
$tbl_o->name || (return $self->error('No table to delete entries from was set.'))
l!l
00
MC/DC0%0/1
$tbl_o->name || (return $self->error('No table to delete entries from was set.'))
$tbl_o->name
Truth table0%0/2
A
A= $tbl_o->name
Aresult
11
00
239 return( $self->error( "No table to delete entries from was set." ) );
240 0 my $where = '';
241 0 ▶ $self->where( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
242 # if( !$where && $self->{ 'query_reset' } )
243 0 ▶ if( !$where )
Branch: 1 branch
BranchTrueFalseTotal
unless ($where) 0 0 0
244 {
245 0 $where = $self->where();
246 }
247 0 ▶ if( !$where )
Branch: 1 branch
BranchTrueFalseTotal
unless ($where) 0 0 0
248 {
249 0 return( $self->error( "You have provided no where clause. If you intend to delete all records from table '$table', you must do explicitly by preparing the statement yourself." ) );
250 }
251 0 my $clauses = $self->_query_components( 'delete' );
252 0 my @query = ( "DELETE FROM $table" );
253 # 'query_reset' condition to avoid catching parameters from pervious queries.
254 0 ▶ push( @query, @$clauses ) if( scalar( @$clauses ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$clauses 0 0 0
255 0 my $query = $self->{query} = CORE::join( ' ', @query );
256 0 ▶ return( $self->error( "Refusing to do a bulk delete. Enable the allow_bulk_delete database object property if you want to do so. Original query was: $query" ) ) if( !$self->where && !$dbo->allow_bulk_delete );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->where or $dbo->allow_bulk_delete 0 0 0
Condition0%0/3
$self->where or $dbo->allow_bulk_delete
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->where or $dbo->allow_bulk_delete
$self->where $dbo->allow_bulk_delete
Truth table0%0/3
A or B
A= $self->whereB= $dbo->allow_bulk_delete
ABresult
1X1
011
000
257 0 $self->_save_bind();
258 0 ▶ my $sth = $tbl_o->_cache_this( $self ) ||
Condition0%0/2
$tbl_o->_cache_this($self) || (return $self->error("Error while preparing query to delete from table '${table}':\n$query"))
l!l
00
MC/DC0%0/1
$tbl_o->_cache_this($self) || (return $self->error("Error while preparing query to delete from table '${table}':\n$query"))
$tbl_o->_cache_this($self)
Truth table0%0/2
A
A= $tbl_o->_cache_this($self)
Aresult
11
00
259 return( $self->error( "Error while preparing query to delete from table '$table':\n$query" ) );
260 # Routines such as as_string() expect an array on pupose so we do not have to commit the action
261 # but rather get the statement string. At the end, we write:
262 # $obj->delete() to really delete
263 # $obj->delete->as_string() to ONLY get the formatted statement
264 # wantarray returns undef in void context, i.e. $obj->delete()
265 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
266 {
267 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing query to delete from table '${table}':\n$query") 0 0 0
268 return( $self->error( "Error while executing query to delete from table '$table':\n$query" ) );
269 # Will be destroyed anyway and permits the end user to manipulate the object if needed
270 # $sth->finish();
271 }
272 # wantarray returns false but not undef() otherwise, i.e.
273 # $obj->delete->as_string();
274 0 return( $sth );
275 }
276  
277 0 ▶sub dirty { return( shift->_set_get_boolean( 'dirty', @_ ) ); }
Subroutine dirty: not called CC=1 SCAR=6.9
Pod documented
278  
279 # sub elements { return( shift->_set_get_hash_as_mix_object( 'elements', @_ ) ); }
280 0 ▶sub elements { return( shift->_set_get_object_without_init( 'elements', 'DB::Object::Query::Elements', @_ ) ); }
Subroutine elements: not called CC=1 SCAR=6.9
Pod documented
281  
282 1 ▶sub enhance { return( shift->_set_get_boolean( 'enhance', @_ ) ); }
Subroutine enhance: called CC=1 SCAR=0.0
Pod documented
283  
284 sub error
285 0 ▶{
Subroutine error: not called CC=2 SCAR=17.9
Pod documented
286 0 my $self = shift( @_ );
287 # Query object is now in an error state and must not be re-used.
288 0 ▶ $self->{dirty} = 1 if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 0 0 0
289 0 return( $self->SUPER::error( @_ ) );
290 }
291  
292 # Used in conjonction with constant(), allows internally to know if the query has reached the end of the chain
293 # Such as $tbl->select->join( $tbl_object, $conditions )->join( $other_tbl_object, $other_conditions );
294 # final() enables to know the query reached the end, so that when constant is used, all the processing can be skipped
295 0 ▶sub final { return( shift->_set_get_scalar( 'final', @_ ) ); }
Subroutine final: not called CC=1 SCAR=6.9
Pod documented
296  
297 sub format_from_epoch
298 0 ▶{
Subroutine format_from_epoch: not called CC=2 SCAR=17.9
Pod documented
299 0 my $self = shift( @_ );
300 0 ▶ warn( "This method \"format_from_epoch\" was not superseded." ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
301 }
302  
303 sub format_to_epoch
304 0 ▶{
Subroutine format_to_epoch: not called CC=2 SCAR=17.9
Pod documented
305 0 my $self = shift( @_ );
306 0 ▶ warn( "This method \"format_to_epoch\" was not superseded." ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
307 }
308  
309 # NOTE: For select or insert queries
310 sub format_statement
311 0 ▶{
Subroutine format_statement: not called CC=40 SCAR=74.0
Pod documented
312 0 my $self = shift( @_ );
313 0 my $opts = $self->_get_args_as_hash( @_ );
314 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
315 0 ▶ my $dbo = $tbl_o->database_object ||
Condition0%0/2
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
l!l
00
MC/DC0%0/1
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
$tbl_o->database_object
Truth table0%0/2
A
A= $tbl_o->database_object
Aresult
11
00
316 return( $self->error( "No database object is currently set on this table object for table '", $tbl_o->name, "'" ) );
317 # Should we use bind statement?
318 0 my $bind = $dbo->use_bind;
319 0 ▶ $opts->{data} = $self->{_default} if( !$opts->{data} );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"data"} 0 0 0
320 0 ▶ $opts->{order} = $self->{_fields} if( !$opts->{order} );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"order"} 0 0 0
321 0 ▶ $opts->{table} = $tbl_o->qualified_name if( !$opts->{table} );
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"table"} 0 0 0
322 0 local $_;
323 0 my $data = $opts->{data};
324 0 my $order = $opts->{order};
325 0 my $table = $opts->{table};
326 0 my $prefix = $tbl_o->prefix;
327 0 my $from_unix = {};
328 0 my $unixtime = {};
329 0 my $args = $self->{_args};
330 0 my $fields = '';
331 0 my $values = '';
332 0 my $base_class = $self->base_class;
333 0 $from_unix = $self->{_from_unix};
334 0 my $tmp_ref = $self->from_unixtime();
335 0 map{ $from_unix->{ $_ }++ } @$tmp_ref;
336 0 $tmp_ref = $self->unix_timestamp();
337 0 map{ $unixtime->{ $_ }++ } @$tmp_ref;
338 0 my @format_fields = ();
339 0 my @format_values = ();
340 # my $binded = $self->{binded_values} = [];
341 0 my $multi_db = $tbl_o->prefix_database;
342 0 my $db = $tbl_o->database;
343 0 my $fields_ref = $tbl_o->fields_as_array;
344 0 my $ok_list = $fields_ref->join( '|' )->scalar;
345 0 my $tables = CORE::join( '|', @{$dbo->tables} );
346 0 ▶ my $struct = $tbl_o->structure || return( $self->pass_error( $tbl_o->error ) );
Condition0%0/2
$tbl_o->structure || (return $self->pass_error($tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->structure || (return $self->pass_error($tbl_o->error))
$tbl_o->structure
Truth table0%0/2
A
A= $tbl_o->structure
Aresult
11
00
347 0 my $query_type = $self->{query_type};
348 0 my @sorted = ();
349 0 ▶ if( $self->query_type eq 'insert' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->query_type eq "insert" and @$args and not @$args % 2) 0 0 0
Condition0%0/6
$self->query_type eq "insert" and @$args and not @$args % 2
!ll&&!rl&&r
000
$self->query_type eq "insert" and @$args
!ll&&!rl&&r
000
MC/DC0%0/3
$self->query_type eq "insert" and @$args and not @$args % 2
$self->query_type eq "insert" @$args not @$args % 2
Truth table0%0/4
A and B and not(C)
A= $self->query_type eq "insert"B= @$argsC= not @$args % 2
ABCresult
0XX0
10X0
1100
1111
350 @$args &&
351 !( @$args % 2 ) )
352 {
353 0 ▶ for( my $i = 0; $i < @$args; $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$args) 0 0 0
354 {
355 0 ▶ push( @sorted, $args->[ $i ] ) if( exists( $order->{ $args->[ $i ] } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $$order{$args->[$i]} 0 0 0
356 0 ▶ $data->{ $args->[ $i ] } = $args->[ $i + 1 ] if( !exists( $data->{ $args->[ $i ] } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$args->[$i]} 0 0 0
357 }
358 }
359 0 ▶ @sorted = sort{ $order->{ $a }->pos <=> $order->{ $b }->pos } keys( %$order ) if( !@sorted );
Branch: 1 branch
BranchTrueFalseTotal
unless @sorted 0 0 0
360 # Used for insert or update so that execute can take a hash of key => value pair and we would bind the values in the right order
361 # But or that we need to know the order of the fields.
362 0 $self->{sorted} = \@sorted;
363 0 my $placeholder_re = $dbo->_placeholder_regexp;
364 0 my $elems = $self->new_elements;
365  
366 0 foreach( @sorted )
367 {
368 0 my $elem = $self->new_element;
369 0 ▶ if( exists( $data->{ $_ } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{$_}) 0 0 0
370 {
371 0 my $value = $data->{ $_ };
372 0 ▶ if( $self->_is_a( $value => "${base_class}::Statement" ) )
Branch: 10 branches
BranchTrueFalseTotal
if ($self->_is_a($value, "${base_class}::Statement")) { } 0 0 0
elsif (exists $from_unix->{$_}) { } 0 0 0
elsif (exists $unixtime->{$_}) { } 0 0 0
elsif (ref $value eq 'SCALAR') { } 0 0 0
elsif ($value =~ /($placeholder_re)/) { } 0 0 0
elsif ($struct->{$_} =~ /^\s*\bBLOB\b/i) { } 0 0 0
elsif (not $bind) { } 0 0 0
elsif ($value =~ /^\d+$/ and $struct->{$_} =~ /\bSET\(/i) { } 0 0 0
elsif ($value =~ /^\d+$/ and $struct->{$_} =~ /\bENUM\(/i and $query_type eq 'insert' || $query_type eq 'update') { } 0 0 0
elsif ($bind) { } 0 0 0
373 {
374 # $elem->value( '(' . $value->as_string . ')' );
375 0 $elem->format( '(' . $value->as_string . ')' );
376 0 $elem->elements( $value->query_object->elements );
377 }
378 # This is for insert or update statement types
379 elsif( exists( $from_unix->{ $_ } ) )
380 {
381 0 ▶ if( $bind )
Branch: 1 branch
BranchTrueFalseTotal
if ($bind) { } 0 0 0
382 {
383 0 $elem->value( $value );
384 0 $elem->format( $self->format_from_epoch({ value => $value, bind => 1 }) );
385 }
386 else
387 {
388 0 $elem->format( $self->format_from_epoch({ value => $value, bind => 0 }) );
389 }
390 }
391 elsif( exists( $unixtime->{ $_ } ) )
392 {
393 0 ▶ if( $bind )
Branch: 1 branch
BranchTrueFalseTotal
if ($bind) { } 0 0 0
394 {
395 0 $elem->value( $value );
396 0 $elem->format( $self->format_to_epoch({ value => $value, bind => 1 }) );
397 }
398 else
399 {
400 0 $elem->format( $self->format_to_epoch({ value => $value, bind => 0 }) );
401 }
402 }
403 # A scalar reference implies this is used as-is
404 elsif( ref( $value ) eq 'SCALAR' )
405 {
406 0 $elem->format( $$value );
407 0 $elem->as_is(1);
408 }
409 # The placeholder may be embedded inside a function like `UPPER(?)'
410 elsif( $value =~ /($placeholder_re)/ )
411 {
412 0 $elem->placeholder( $1 );
413 0 $elem->format( $value );
414 }
415 elsif( $struct->{ $_ } =~ /^\s*\bBLOB\b/i )
416 {
417 0 $elem->placeholder( '?' );
418 0 $elem->format( '?' );
419 0 $elem->value( $value );
420 }
421 # If the value itself looks like a field name or like a SQL function
422 # or simply if bind option is inactive
423 # This stinks too much. It is way too complex to parse or guess a sql query
424 # use \( instead to pass a scalar reference
425 # elsif( $value =~ /(?:\.|\A)(?:$ok_list)\b/ ||
426 # $value =~ /[a-zA-Z_]{3,}\([^\)]*\)/ ||
427 # $value eq '?' )
428 # {
429 # push( @format_values, $value );
430 # }
431 elsif( !$bind )
432 {
433 0 $elem->format( sprintf( "%s", $dbo->quote( $value ) ) );
434 }
435 # We do this before testing for param binding because DBI puts quotes around SET number :-(
436 ▶ elsif( $value =~ /^\d+$/ && $struct->{ $_ } =~ /\bSET\(/i )
Condition0%0/3
$value =~ /^\d+$/ and $struct->{$_} =~ /\bSET\(/i
!ll&&!rl&&r
000
MC/DC0%0/2
$value =~ /^\d+$/ and $struct->{$_} =~ /\bSET\(/i
$value =~ /^\d+$/ $struct->{$_} =~ /\bSET\(/i
Truth table0%0/3
A and B
A= $value =~ /^\d+$/B= $struct->{$_} =~ /\bSET\(/i
ABresult
0X0
100
111
437 {
438 0 $elem->format( $value );
439 }
440 ▶ elsif( $value =~ /^\d+$/ &&
Condition0%0/9
$value =~ /^\d+$/ and $struct->{$_} =~ /\bENUM\(/i and $query_type eq "insert" || $query_type eq "update"
!ll&&!rl&&r
000
$value =~ /^\d+$/ and $struct->{$_} =~ /\bENUM\(/i
!ll&&!rl&&r
000
$query_type eq "insert" or $query_type eq "update"
l!l&&r!l&&!r
000
MC/DC0%0/4
$value =~ /^\d+$/ and $struct->{$_} =~ /\bENUM\(/i and $query_type eq "insert" || $query_type eq "update"
$value =~ /^\d+$/ $struct->{$_} =~ /\bENUM\(/i $query_type eq "insert" $query_type eq "update"
Truth table0%0/5
A and B and C or D
A= $value =~ /^\d+$/B= $struct->{$_} =~ /\bENUM\(/iC= $query_type eq "insert"D= $query_type eq "update"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
441 $struct->{ $_ } =~ /\bENUM\(/i &&
442 ( $query_type eq 'insert' || $query_type eq 'update' ) )
443 {
444 0 $elem->format( "'$value'" );
445 }
446 # Otherwise, bind option is enabled, we bind parameter
447 elsif( $bind )
448 {
449 0 $elem->placeholder( '?' );
450 0 $elem->format( '?' );
451 0 $elem->value( $value );
452 }
453 # In last resort, we handle the formatting ourself
454 else
455 {
456 0 $elem->format( $dbo->quote( $value ) );
457 }
458 }
459  
460 0 ▶ if( $prefix )
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix) 0 0 0
461 {
462 0 s{
463 (?<![\.\"])\b($ok_list)\b(\s*)?(?!\.)
464 }
465 {
466 0 my( $field, $spc ) = ( $1, $2 );
467 0 ▶ if( $` =~ /\s+(?:AS|FROM)\s+$/i )
Branch: 2 branches
BranchTrueFalseTotal
if ($` =~ /\s+(?:AS|FROM)\s+$/i) { } 0 0 0
elsif ($query_type eq 'select' and $prefix) { } 0 0 0
468 {
469 0 "$field$spc";
470 }
471 ▶ elsif( $query_type eq 'select' && $prefix )
Condition0%0/3
$query_type eq "select" and $prefix
!ll&&!rl&&r
000
MC/DC0%0/2
$query_type eq "select" and $prefix
$query_type eq "select" $prefix
Truth table0%0/3
A and B
A= $query_type eq "select"B= $prefix
ABresult
0X0
100
111
472 {
473 0 "$prefix.$field$spc";
474 }
475 else
476 {
477 0 "$field$spc";
478 }
479 }gex;
480 0 ▶ s/(?<!\.)($tables)(?:\.)/$db\.$1\./g if( $multi_db );
Branch: 1 branch
BranchTrueFalseTotal
if $multi_db 0 0 0
481 }
482 0 $elem->field( $_ );
483 0 $elems->push( $elem );
484 }
485 0 ▶ if( !wantarray() && scalar( @{$self->{_extra}} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not wantarray and scalar @{$self->{"_extra"};}) 0 0 0
Condition0%0/2
not wantarray and scalar @{$self->{"_extra"};}
!ll
00
MC/DC0%0/1
not wantarray and scalar @{$self->{"_extra"};}
not wantarray
Truth table0%0/2
not(A)
A= not wantarray
Aresult
00
11
486 {
487 0 foreach my $this ( @{$self->{_extra}} )
488 {
489 0 $elems->push({
490 field => $this,
491 debug => $self->debug,
492 });
493 }
494 }
495  
496 0 return( $elems );
497 }
498  
499 sub format_update
500 0 ▶{
Subroutine format_update: not called CC=42 SCAR=75.0
Pod documented
501 0 my $self = shift( @_ );
502 0 ▶ my $data = shift( @_ ) if( $self->_is_array( $_[0] ) || $self->_is_hash( $_[0] => 'strict' ) || @_ % 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_array($_[0]) or $self->_is_hash($_[0], "strict") or @_ % 2 0 0 0
Condition0%0/6
$self->_is_array($_[0]) or $self->_is_hash($_[0], "strict") or @_ % 2
l!l&&r!l&&!r
000
$self->_is_array($_[0]) or $self->_is_hash($_[0], "strict")
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->_is_array($_[0]) or $self->_is_hash($_[0], "strict") or @_ % 2
$self->_is_array($_[0]) $self->_is_hash($_[0], "strict") @_ % 2
Truth table0%0/4
A or B or C
A= $self->_is_array($_[0])B= $self->_is_hash($_[0], "strict")C= @_ % 2
ABCresult
1XX1
01X1
0011
0000
503 0 my @arg = @_;
504 0 ▶ if( !@arg && $data )
Branch: 1 branch
BranchTrueFalseTotal
if (not @arg and $data) 0 0 0
Condition0%0/3
not @arg and $data
!ll&&!rl&&r
000
MC/DC0%0/2
not @arg and $data
not @arg $data
Truth table0%0/3
not(A) and B
A= not @argB= $data
ABresult
0X0
100
111
505 {
506 0 ▶ if( $self->_is_hash( $data => 'strict' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_hash($data, 'strict')) { } 0 0 0
elsif ($self->_is_array($data)) { } 0 0 0
507 {
508 0 @arg = %$data;
509 }
510 elsif( $self->_is_array( $data ) )
511 {
512 0 @arg = @$data;
513 }
514 }
515  
516 0 ▶ return( $self->error( "Must provide key => value pairs. I received an odd number of arguments" ) ) if( @arg && ( scalar( @arg ) % 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if @arg and scalar(@arg) % 2 0 0 0
Condition0%0/3
@arg and scalar(@arg) % 2
!ll&&!rl&&r
000
MC/DC0%0/2
@arg and scalar(@arg) % 2
@arg scalar(@arg) % 2
Truth table0%0/3
A and B
A= @argB= scalar(@arg) % 2
ABresult
0X0
100
111
517 0 my %arg = ( @arg );
518 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
519 0 ▶ my $dbo = $tbl_o->database_object ||
Condition0%0/2
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
l!l
00
MC/DC0%0/1
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
$tbl_o->database_object
Truth table0%0/2
A
A= $tbl_o->database_object
Aresult
11
00
520 return( $self->error( "No database object is currently set on this table object for table '", $tbl_o->name, "'" ) );
521 0 ▶ $arg{default} ||= $self->{_default};
Condition0%0/3
$arg{"default"} ||= $self->{"_default"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{"default"} ||= $self->{"_default"}
$arg{"default"} $self->{"_default"}
Truth table0%0/3
A ||= B
A= $arg{"default"}B= $self->{"_default"}
ABresult
1X1
011
000
522 0 ▶ if( $arg{data} && !$data )
Branch: 2 branches
BranchTrueFalseTotal
if ($arg{'data'} and not $data) { } 0 0 0
elsif ($self->_is_hash($data, 'strict')) { } 0 0 0
Condition0%0/3
$arg{"data"} and not $data
!ll&&!rl&&r
000
MC/DC0%0/2
$arg{"data"} and not $data
$arg{"data"} not $data
Truth table0%0/3
A and not(B)
A= $arg{"data"}B= not $data
ABresult
0X0
100
111
523 {
524 0 my $hash = $arg{data};
525 0 my @vals = %$hash;
526 0 $data = \@vals;
527 }
528 elsif( $self->_is_hash( $data => 'strict' ) )
529 {
530 0 my @vals = %$data;
531 0 $data = \@vals;
532 }
533 0 ▶ my $info = $data || \@arg;
Condition0%0/2
$data || \@arg
l!l
00
MC/DC0%0/1
$data || \@arg
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
534 0 ▶ if( !$info || !scalar( @$info ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($info and scalar @$info) 0 0 0
Condition0%0/3
$info and scalar @$info
!ll&&!rl&&r
000
MC/DC0%0/2
$info and scalar @$info
$info scalar @$info
Truth table0%0/3
A and B
A= $infoB= scalar @$info
ABresult
0X0
100
111
535 {
536 0 return( $self->error( "No data to update was provided to format update." ) );
537 }
538 0 my $bind = $dbo->use_bind;
539 0 ▶ my $def = $arg{default} || $self->{_default};
Condition0%0/3
$arg{'default'} || $self->{'_default'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$arg{'default'} || $self->{'_default'}
$arg{'default'} $self->{'_default'}
Truth table0%0/3
A || B
A= $arg{'default'}B= $self->{'_default'}
ABresult
1X1
011
000
540 0 my $fields_ref = $tbl_o->fields;
541 0 my $fields_list = CORE::join( '|', keys( %$fields_ref ) );
542 0 ▶ my $struct = $tbl_o->structure || return( $self->pass_error( $tbl_o->error ) );
Condition0%0/2
$tbl_o->structure || (return $self->pass_error($tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->structure || (return $self->pass_error($tbl_o->error))
$tbl_o->structure
Truth table0%0/2
A
A= $tbl_o->structure
Aresult
11
00
543 0 my $types = $tbl_o->types;
544 0 my $from_unix = $self->from_unixtime();
545 0 my $from_unixtime = { map{ $_ => 1 } @$from_unix };
546 0 my @fields = ();
547 0 my @binded = ();
548 0 my @types = ();
549 # Get the constant has definition for each table fields
550 0 my $types_const = $tbl_o->types_const;
551 0 my $placeholder_re = $dbo->_placeholder_regexp;
552 # Before we used to call getdefault supplying it our new values and the
553 # format_statement() that would take the default supplied values.
554 # Now, this works differently since we use update() method and supply directly our
555 # value to update to it.
556 # In this context, getting the default values is dangerous, since resetting the values
557 # to their default ones is not was we want, is it?
558 0 my $elems = $self->new_elements;
559 0 ▶ while( @$info )
Branch: 1 branch
BranchTrueFalseTotal
if (@$info) 0 0 0
560 {
561 0 my( $field, $value ) = splice( @$info, 0, 2 );
562 # Do not update a field that does not belong in this table
563 0 ▶ next if( !exists( $fields_ref->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $fields_ref->{$field} 0 0 0
564 # DB::Object::Fields::Field object
565 0 my $fo = $fields_ref->{ $field };
566 0 my $elem = $self->new_element( field => $field );
567 # Make it a FROM_UNIXTIME field if this is what we need.
568 # $value = "FROM_UNIXTIME($value)" if( exists( $from_unixtime->{ $field } ) );
569 # $value = \"TO_TIMESTAMP($value)" if( exists( $from_unixtime->{ $field } ) );
570 # This is for insert or update statement types
571 0 ▶ if( exists( $from_unixtime->{ $field } ) )
Branch: 5 branches
BranchTrueFalseTotal
if (exists $from_unixtime->{$field}) { } 0 0 0
elsif (ref $value eq 'SCALAR') { } 0 0 0
elsif (not $bind) { } 0 0 0
elsif ($value =~ /^\d+$/ and $struct->{$field} =~ /\bSET\(/i) { } 0 0 0
elsif ($bind) { } 0 0 0
572 {
573 0 ▶ if( $bind )
Branch: 1 branch
BranchTrueFalseTotal
if ($bind) { } 0 0 0
574 {
575 0 $elem->value( $value );
576 0 $elem->format( "$field=" . $self->format_from_epoch({ value => $value, bind => 1 }) );
577 }
578 else
579 {
580 0 $elem->format( "$field=" . $self->format_from_epoch({ value => $value, bind => 0 }) );
581 }
582 }
583 elsif( ref( $value ) eq 'SCALAR' )
584 {
585 0 $elem->format( "$field=$$value" );
586 0 $elem->as_is(1);
587 }
588 # Maybe $bind is not enabled, but the user may have manually provided a placeholder, i.e. '?'
589 elsif( !$bind )
590 {
591 0 my $const;
592 # The placeholder could be embedded inside a function like 'UPPER(?)'
593 0 ▶ if( $value =~ /($placeholder_re)/ )
Branch: 4 branches
BranchTrueFalseTotal
if ($value =~ /($placeholder_re)/) { } 0 0 0
elsif ($self->_is_hash($value, 'strict') and $fo->type eq 'jsonb' || $fo->type eq 'json') { } 0 0 0
elsif ($dbo->placeholder->has($self->_is_scalar($value) ? $value : \$value)) { } 0 0 0
elsif ($const = $fo->datatype->constant) { } 0 0 0
594 {
595 0 $elem->placeholder( $1 );
596 0 $elem->format( "$field = $value" );
597 0 ▶ if( $const = $fo->datatype->constant )
Branch: 1 branch
BranchTrueFalseTotal
if ($const = $fo->datatype->constant) 0 0 0
598 {
599 0 $elem->type( $const );
600 }
601 }
602 ▶ elsif( $self->_is_hash( $value => 'strict' ) &&
Condition0%0/6
$self->_is_hash($value, "strict") and $fo->type eq "jsonb" || $fo->type eq "json"
!ll&&!rl&&r
000
$fo->type eq "jsonb" or $fo->type eq "json"
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->_is_hash($value, "strict") and $fo->type eq "jsonb" || $fo->type eq "json"
$self->_is_hash($value, "strict") $fo->type eq "jsonb" $fo->type eq "json"
Truth table0%0/4
A and B or C
A= $self->_is_hash($value, "strict")B= $fo->type eq "jsonb"C= $fo->type eq "json"
ABCresult
0XX0
1000
11X1
1011
603 ( $fo->type eq 'jsonb' || $fo->type eq 'json' ) )
604 {
605 0 my $this_json = $self->_encode_json( $value );
606 0 $const = $fo->datatype->constant;
607 0 $elem->format( sprintf( "$field=%s", $dbo->quote( $this_json, $const ) ) );
608 }
609 ▶ elsif( $dbo->placeholder->has( $self->_is_scalar( $value ) ? $value : \$value ) )
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_scalar($value) ? : 0 0 0
610 {
611 0 ▶ $dbo->placeholder->replace( $self->_is_scalar( $value ) ? $value : \$value );
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_scalar($value) ? : 0 0 0
612 0 $elem->placeholder( '?' );
613 0 $elem->format( "$field = ${value}" );
614 0 ▶ if( $const = $fo->datatype->constant )
Branch: 1 branch
BranchTrueFalseTotal
if ($const = $fo->datatype->constant) 0 0 0
615 {
616 0 $elem->type( $const );
617 }
618 }
619 elsif( $const = $fo->datatype->constant )
620 {
621 0 $elem->format( sprintf( "$field=%s", $dbo->quote( $value, $const ) ) );
622 }
623 else
624 {
625 0 $elem->format( sprintf( "$field=%s", $dbo->quote( $value ) ) );
626 }
627 }
628 # if this is a SET field type and value is a number, treat it as a number and not as a string
629 # We do this before testing for param binding because DBI puts quotes around SET number :-(
630 ▶ elsif( $value =~ /^\d+$/ && $struct->{ $field } =~ /\bSET\(/i )
Condition0%0/3
$value =~ /^\d+$/ and $struct->{$field} =~ /\bSET\(/i
!ll&&!rl&&r
000
MC/DC0%0/2
$value =~ /^\d+$/ and $struct->{$field} =~ /\bSET\(/i
$value =~ /^\d+$/ $struct->{$field} =~ /\bSET\(/i
Truth table0%0/3
A and B
A= $value =~ /^\d+$/B= $struct->{$field} =~ /\bSET\(/i
ABresult
0X0
100
111
631 {
632 0 $elem->format( "$field=$value" );
633 }
634 elsif( $bind )
635 {
636 0 $elem->placeholder( '?' );
637 0 $elem->format( "$field=?" );
638 0 $elem->value( $value );
639 0 my $const;
640 0 ▶ if( $const = $fo->datatype->constant )
Branch: 1 branch
BranchTrueFalseTotal
if ($const = $fo->datatype->constant) 0 0 0
641 {
642 0 $elem->type( $const );
643 }
644 }
645 else
646 {
647 0 my $const;
648 0 ▶ if( $const = $fo->datatype->constant )
Branch: 1 branch
BranchTrueFalseTotal
if ($const = $fo->datatype->constant) { } 0 0 0
649 {
650 0 $elem->format( "$field=" . $dbo->quote( $value, $const ) );
651 }
652 else
653 {
654 0 $elem->format( "$field=" . $dbo->quote( $value ) );
655 }
656 }
657 0 $elems->push( $elem );
658 }
659 0 return( $elems );
660 }
661  
662 0 ▶sub from_table { return( shift->_set_get_array_as_object( 'from_table', @_ ) ); }
Subroutine from_table: not called CC=1 SCAR=6.9
Pod documented
663  
664 0 ▶sub from_unixtime { return( shift->_set_get_array_as_object( 'from_unixtime', @_ ) ); }
Subroutine from_unixtime: not called CC=1 SCAR=6.9
Pod documented
665  
666 sub getdefault
667 0 ▶{
Subroutine getdefault: not called CC=69 SCAR=84.8
Pod documented
668 0 my $self = shift( @_ );
669 0 my $opts = $self->_get_args_as_hash( @_ );
670 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
671 0 ▶ my $table = $opts->{table} || $tbl_o->name;
Condition0%0/3
$opts->{'table'} || $tbl_o->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'table'} || $tbl_o->name
$opts->{'table'} $tbl_o->name
Truth table0%0/3
A || B
A= $opts->{'table'}B= $tbl_o->name
ABresult
1X1
011
000
672 0 ▶ my $prefix = $tbl_o->query_object->table_alias ? $tbl_o->query_object->table_alias : $tbl_o->prefix;
Branch: 1 branch
BranchTrueFalseTotal
$tbl_o->query_object->table_alias ? : 0 0 0
673 0 my $arg = [];
674 0 ▶ if( $opts->{arg} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"arg"}) 0 0 0
675 {
676 0 ▶ return( $self->error( "arg parameter provided, but is not an array reference." ) ) if( !$self->_is_array( $opts->{arg} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_array($opts->{"arg"}) 0 0 0
677 0 $arg = $opts->{arg};
678 0 ▶ return( $self->error( "arg parameter provided is not a key => value pair. Its number of elements should be an even number." ) ) if( scalar( @$arg ) && ( @$arg % 2 ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$arg and @$arg % 2 0 0 0
Condition0%0/3
scalar @$arg and @$arg % 2
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @$arg and @$arg % 2
scalar @$arg @$arg % 2
Truth table0%0/3
A and B
A= scalar @$argB= @$arg % 2
ABresult
0X0
100
111
679 }
680 0 my %arg = ();
681 0 my $default = {};
682 0 my $fields = [];
683 0 my $structure = {};
684 0 my $base_class = $self->base_class;
685 # Contains some extra parameters for SELECT queries only
686 # Right now a concatenation of 'last_name' and 'first_name' fields into field named 'name'
687 0 my @extra = ();
688 0 ▶ %arg = @$arg if( scalar( @$arg ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$arg 0 0 0
689 0 $opts->{table} = lc( $opts->{table} );
690 0 ▶ $opts->{time} = time() if( !defined( $opts->{time} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"time"} 0 0 0
691 0 my $time = '';
692 0 ▶ $time = $opts->{time} if( $opts->{time} =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"time"} =~ /^\d+$/ 0 0 0
693 0 ▶ $time ||= $opts->{unixtime} || time();
Condition0%0/5
$time ||= $opts->{"unixtime"} || time
l!l&&r!l&&!r
000
$opts->{'unixtime'} || time
l!l
00
MC/DC0%0/2
$time ||= $opts->{"unixtime"} || time
$time $opts->{'unixtime'}
Truth table0%0/3
A ||= B
A= $timeB= $opts->{'unixtime'}
ABresult
1X1
011
000
694 0 my $query_type = $opts->{query_type};
695 0 ▶ if( !$query_type )
Branch: 1 branch
BranchTrueFalseTotal
unless ($query_type) 0 0 0
696 {
697 0 my( $pkg, $file, $line, $sub ) = caller(1);
698 0 $sub =~ s/(.*):://;
699 0 $query_type = $sub;
700 }
701 0 my $alias = '';
702 0 ▶ if( $query_type ne 'insert' && $query_type ne 'delete' && $query_type ne 'replace' )
Branch: 1 branch
BranchTrueFalseTotal
if ($query_type ne "insert" and $query_type ne "delete" and $query_type ne "replace") 0 0 0
Condition0%0/6
$query_type ne "insert" and $query_type ne "delete" and $query_type ne "replace"
!ll&&!rl&&r
000
$query_type ne "insert" and $query_type ne "delete"
!ll&&!rl&&r
000
MC/DC0%0/3
$query_type ne "insert" and $query_type ne "delete" and $query_type ne "replace"
$query_type ne "insert" $query_type ne "delete" $query_type ne "replace"
Truth table0%0/4
A and B and C
A= $query_type ne "insert"B= $query_type ne "delete"C= $query_type ne "replace"
ABCresult
0XX0
10X0
1100
1111
703 {
704 0 $alias = $opts->{as};
705 0 ▶ $alias = $self->alias if( !$alias || !%$alias );
Branch: 1 branch
BranchTrueFalseTotal
unless $alias and %$alias 0 0 0
Condition0%0/3
$alias and %$alias
!ll&&!rl&&r
000
MC/DC0%0/2
$alias and %$alias
$alias %$alias
Truth table0%0/3
A and B
A= $aliasB= %$alias
ABresult
0X0
100
111
706 }
707 0 ▶ my $avoid = $opts->{avoid} || $self->avoid();
Condition0%0/3
$opts->{'avoid'} || $self->avoid
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'avoid'} || $self->avoid
$opts->{'avoid'} $self->avoid
Truth table0%0/3
A || B
A= $opts->{'avoid'}B= $self->avoid
ABresult
1X1
011
000
708 0 ▶ my $unix_time = $opts->{unix_timestamp} || $self->unix_timestamp;
Condition0%0/3
$opts->{'unix_timestamp'} || $self->unix_timestamp
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'unix_timestamp'} || $self->unix_timestamp
$opts->{'unix_timestamp'} $self->unix_timestamp
Truth table0%0/3
A || B
A= $opts->{'unix_timestamp'}B= $self->unix_timestamp
ABresult
1X1
011
000
709 0 ▶ my $from_unix = $opts->{from_unixtime} || $self->from_unixtime;
Condition0%0/3
$opts->{'from_unixtime'} || $self->from_unixtime
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'from_unixtime'} || $self->from_unixtime
$opts->{'from_unixtime'} $self->from_unixtime
Truth table0%0/3
A || B
A= $opts->{'from_unixtime'}B= $self->from_unixtime
ABresult
1X1
011
000
710  
711 0 my $enhance = $self->enhance;
712 # Need to do hard copy of hashes
713 0 ▶ $default = $tbl_o->default || return( $self->pass_error( $tbl_o->error ) );
Condition0%0/2
$tbl_o->default || (return $self->pass_error($tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->default || (return $self->pass_error($tbl_o->error))
$tbl_o->default
Truth table0%0/2
A
A= $tbl_o->default
Aresult
11
00
714 0 ▶ $fields = $tbl_o->fields || return( $self->pass_error( $tbl_o->error ) );
Condition0%0/2
$tbl_o->fields || (return $self->pass_error($tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->fields || (return $self->pass_error($tbl_o->error))
$tbl_o->fields
Truth table0%0/2
A
A= $tbl_o->fields
Aresult
11
00
715 0 ▶ $structure = $tbl_o->structure || return( $self->pass_error( $tbl_o->error ) );
Condition0%0/2
$tbl_o->structure || (return $self->pass_error($tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->structure || (return $self->pass_error($tbl_o->error))
$tbl_o->structure
Truth table0%0/2
A
A= $tbl_o->structure
Aresult
11
00
716  
717 0 ▶ if( !scalar( keys( %$fields ) ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar keys %$fields) 0 0 0
718 {
719 0 return( $self->error( "Missing fields (", scalar( keys( %$fields ) ), " found) for table \"$table\"." ) );
720 }
721  
722 0 ▶ if( $query_type eq 'select' && $enhance )
Branch: 1 branch
BranchTrueFalseTotal
if ($query_type eq "select" and $enhance) 0 0 0
Condition0%0/3
$query_type eq "select" and $enhance
!ll&&!rl&&r
000
MC/DC0%0/2
$query_type eq "select" and $enhance
$query_type eq "select" $enhance
Truth table0%0/3
A and B
A= $query_type eq "select"B= $enhance
ABresult
0X0
100
111
723 {
724 0 my @sorted = sort{ $fields->{ $a }->pos <=> $fields->{ $b }->pos } keys( %$fields );
725 0 foreach my $field ( @sorted )
726 {
727 0 ▶ if( $structure->{ $field } =~ /^\s*(?:DATE(?:TIME)?|TIMESTAMP)\s*/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($structure->{$field} =~ /^\s*(?:DATE(?:TIME)?|TIMESTAMP)\s*/i) 0 0 0
728 {
729 0 ▶ my $f = $self->format_to_epoch({
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
730 value => ( $prefix ? "${prefix}.${field}" : $field ),
731 bind => 0,
732 quote => 0,
733 });
734 0 ▶ my $fo = $tbl_o->fo->new_field(
Condition0%0/2
$tbl_o->fo->new_field('debug', $self->debug, 'name', "$f AS ${field}_unixtime", 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer') || (return $self->pass_error($tbl_o->fo->error))
l!l
00
MC/DC0%0/1
$tbl_o->fo->new_field('debug', $self->debug, 'name', "$f AS ${field}_unixtime", 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer') || (return $self->pass_error($tbl_o->fo->error))
$tbl_o->fo->new_field('debug', $self->debug, 'name', "$f AS ${field}_unixtime", 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer')
Truth table0%0/2
A
A= $tbl_o->fo->new_field('debug', $self->debug, 'name', "$f AS ${field}_unixtime", 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer')
Aresult
11
00
735 debug => $self->debug,
736 name => "$f AS ${field}_unixtime",
737 pos => ( scalar( keys( %$fields ) ) + 1 ),
738 query_object => $self,
739 table_object => $self->table_object,
740 type => 'integer',
741 ) || return( $self->pass_error( $tbl_o->fo->error ) );
742 # $fields->{ "$f AS ${field}_unixtime" } = scalar( keys( %$fields ) ) + 1;
743 0 $fields->{ "$f AS ${field}_unixtime" } = $fo;
744 }
745 }
746 }
747  
748 0 my %to_unixtime = ();
749 0 ▶ if( $self->_is_array( $unix_time ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($unix_time)) { } 0 0 0
elsif ($self->_is_hash($unix_time, 'strict')) { } 0 0 0
750 {
751 0 %to_unixtime = map{ $_ => 1 } @$unix_time;
752 }
753 elsif( $self->_is_hash( $unix_time => 'strict' ) )
754 {
755 0 %to_unixtime = %$unix_time;
756 }
757  
758 0 ▶ if( %to_unixtime && scalar( keys( %to_unixtime ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (%to_unixtime and scalar keys %to_unixtime) 0 0 0
Condition0%0/2
%to_unixtime and scalar keys %to_unixtime
!ll
00
MC/DC0%0/1
%to_unixtime and scalar keys %to_unixtime
%to_unixtime
Truth table0%0/2
A
A= %to_unixtime
Aresult
00
11
759 {
760 0 foreach my $field ( keys( %to_unixtime ) )
761 {
762 0 ▶ if( exists( $fields->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fields->{$field}) 0 0 0
763 {
764 0 ▶ my $func = $self->format_to_epoch({
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
765 value => ( $prefix ? "${prefix}.${field}" : $field ),
766 bind => 0,
767 quote => 0,
768 });
769 my $fo = $tbl_o->fo->new_field(
770 debug => $self->debug,
771 name => $func . ' AS ' . $field,
772 0 ▶ pos => $fields->{ $field }->pos,
Condition0%0/2
$tbl_o->fo->new_field('debug', $self->debug, 'name', $func . ' AS ' . $field, 'pos', $fields->{$field}->pos, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer') || (return $self->pass_error($tbl_o->fo->error))
l!l
00
MC/DC0%0/1
$tbl_o->fo->new_field('debug', $self->debug, 'name', $func . ' AS ' . $field, 'pos', $fields->{$field}->pos, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer') || (return $self->pass_error($tbl_o->fo->error))
$tbl_o->fo->new_field('debug', $self->debug, 'name', $func . ' AS ' . $field, 'pos', $fields->{$field}->pos, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer')
Truth table0%0/2
A
A= $tbl_o->fo->new_field('debug', $self->debug, 'name', $func . ' AS ' . $field, 'pos', $fields->{$field}->pos, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer')
Aresult
11
00
773 query_object => $self,
774 table_object => $self->table_object,
775 type => 'integer',
776 ) || return( $self->pass_error( $tbl_o->fo->error ) );
777 0 $fields->{ $func . ' AS ' . $field } = $fo;
778 0 delete( $fields->{ $field } );
779 }
780 }
781 }
782  
783 0 my %avoid = ();
784 0 ▶ if( $self->_is_array( $avoid ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($avoid)) { } 0 0 0
elsif ($self->_is_hash($avoid, 'strict')) { } 0 0 0
785 {
786 0 %avoid = map{ $_ => 1 } @$avoid;
787 }
788 elsif( $self->_is_hash( $avoid => 'strict' ) )
789 {
790 0 %avoid = %$avoid;
791 }
792  
793 0 ▶ if( %avoid && scalar( keys( %avoid ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (%avoid and scalar keys %avoid) 0 0 0
Condition0%0/2
%avoid and scalar keys %avoid
!ll
00
MC/DC0%0/1
%avoid and scalar keys %avoid
%avoid
Truth table0%0/2
A
A= %avoid
Aresult
00
11
794 {
795 0 foreach my $field ( keys( %avoid ) )
796 {
797 0 ▶ if( exists( $fields->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fields->{$field}) 0 0 0
798 {
799 0 delete( $fields->{ $field } );
800 0 delete( $default->{ $field } );
801 }
802 }
803 }
804  
805 0 my %as = ();
806 0 ▶ if( $self->_is_hash( $alias => 'strict' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_hash($alias, "strict")) 0 0 0
807 {
808 0 %as = %$alias;
809 0 foreach my $field ( keys( %as ) )
810 {
811 0 my $f;
812 0 ▶ if( exists( $fields->{ $field } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $fields->{$field}) { } 0 0 0
813 {
814 0 ▶ $f = $prefix
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
815 ? "${prefix}.${field}"
816 : $field;
817 # delete( $fields{ $field } );
818 }
819 else
820 {
821 0 $f = $field;
822 }
823 my $fo = $tbl_o->fo->new_field(
824 debug => $self->debug,
825 0 ▶ name => $f . ' AS "' . $as{ $field } . '"',
Condition0%0/2
$tbl_o->fo->new_field('debug', $self->debug, 'name', $f . ' AS "' . $as{$field} . '"', 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer') || (return $self->pass_error($tbl_o->fo->error))
l!l
00
MC/DC0%0/1
$tbl_o->fo->new_field('debug', $self->debug, 'name', $f . ' AS "' . $as{$field} . '"', 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer') || (return $self->pass_error($tbl_o->fo->error))
$tbl_o->fo->new_field('debug', $self->debug, 'name', $f . ' AS "' . $as{$field} . '"', 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer')
Truth table0%0/2
A
A= $tbl_o->fo->new_field('debug', $self->debug, 'name', $f . ' AS "' . $as{$field} . '"', 'pos', scalar(keys %$fields) + 1, 'query_object', $self, 'table_object', $self->table_object, 'type', 'integer')
Aresult
11
00
826 pos => ( scalar( keys( %$fields ) ) + 1 ),
827 query_object => $self,
828 table_object => $self->table_object,
829 type => 'integer',
830 ) || return( $self->pass_error( $tbl_o->fo->error ) );
831 0 $fields->{ $f . ' AS "' . $as{ $field } . '"' } = $fo;
832 }
833 }
834 0 ▶ if( $query_type eq 'select' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($query_type eq "select" and $enhance and exists $fields->{"last_name"} and exists $fields->{"first_name"} and not exists $fields->{"name"}) 0 0 0
Condition0%0/12
$query_type eq "select" and $enhance and exists $fields->{"last_name"} and exists $fields->{"first_name"} and not exists $fields->{"name"}
!ll&&!rl&&r
000
$query_type eq "select" and $enhance and exists $fields->{"last_name"} and exists $fields->{"first_name"}
!ll&&!rl&&r
000
$query_type eq "select" and $enhance and exists $fields->{"last_name"}
!ll&&!rl&&r
000
$query_type eq "select" and $enhance
!ll&&!rl&&r
000
MC/DC0%0/5
$query_type eq "select" and $enhance and exists $fields->{"last_name"} and exists $fields->{"first_name"} and not exists $fields->{"name"}
$query_type eq "select" $enhance exists $fields->{"last_name"} exists $fields->{"first_name"} not exists $fields->{"name"}
Truth table0%0/6
A and B and C and D and not(E)
A= $query_type eq "select"B= $enhanceC= exists $fields->{"last_name"}D= exists $fields->{"first_name"}E= not exists $fields->{"name"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
835 $enhance &&
836 exists( $fields->{last_name} ) &&
837 exists( $fields->{first_name} ) &&
838 !exists( $fields->{name} ) )
839 {
840  
841 0 ▶ my $f = $prefix
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
842 ? "CONCAT(${prefix}.first_name, ' ', ${prefix}.last_name)"
843 : "CONCAT(first_name, ' ', last_name)";
844 0 push( @extra, "$f AS name" );
845 }
846  
847 0 ▶ if( ( exists( $default->{auth} ) && !defined( $arg{auth} ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default->{"auth"} and not defined $arg{"auth"} or defined $arg{"auth"}) 0 0 0
Condition0%0/6
exists $default->{"auth"} and not defined $arg{"auth"} or defined $arg{"auth"}
l!l&&r!l&&!r
000
exists $default->{"auth"} and not defined $arg{"auth"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $default->{"auth"} and not defined $arg{"auth"} or defined $arg{"auth"}
exists $default->{"auth"} not defined $arg{"auth"} defined $arg{"auth"}
Truth table0%0/5
A and not(B) or C
A= exists $default->{"auth"}B= not defined $arg{"auth"}C= defined $arg{"auth"}
ABCresult
11X1
0X11
1011
0X00
1000
848 defined( $arg{auth} ) )
849 {
850 $default->{auth} = defined( $arg{auth} )
851 ? $arg{auth}
852 0 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'auth'} ? : 0 0 0
853 }
854 0 ▶ if( ( exists( $default->{status} ) && !defined( $default->{status} ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default->{"status"} and not defined $default->{"status"} or defined $arg{"status"}) 0 0 0
Condition0%0/6
exists $default->{"status"} and not defined $default->{"status"} or defined $arg{"status"}
l!l&&r!l&&!r
000
exists $default->{"status"} and not defined $default->{"status"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $default->{"status"} and not defined $default->{"status"} or defined $arg{"status"}
exists $default->{"status"} not defined $default->{"status"} defined $arg{"status"}
Truth table0%0/5
A and not(B) or C
A= exists $default->{"status"}B= not defined $default->{"status"}C= defined $arg{"status"}
ABCresult
11X1
0X11
1011
0X00
1000
855 defined( $arg{status} ) )
856 {
857 $default->{status} = defined( $arg{status} )
858 ? $arg{status}
859 0 ▶ : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'status'} ? : 0 0 0
860 }
861  
862 0 foreach my $data ( keys( %arg ) )
863 {
864 0 ▶ if( exists( $default->{ $data } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $default->{$data}) 0 0 0
865 {
866 0 $default->{ $data } = $arg{ $data };
867 }
868 }
869 0 my %from_unixtime = ();
870 0 ▶ if( $self->_is_array( $from_unix ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($from_unix)) { } 0 0 0
elsif ($self->_is_hash($from_unix, 'strict')) { } 0 0 0
871 {
872 0 %from_unixtime = map{ $_ => 1 } @$from_unix;
873 }
874 elsif( $self->_is_hash( $from_unix => 'strict' ) )
875 {
876 0 %from_unixtime = %$from_unix;
877 }
878  
879 0 $self->{_args} = $arg;
880 0 $self->{_default} = $default;
881 0 $self->{_fields} = $fields;
882 0 $self->{_extra} = \@extra;
883 0 $self->{_structure} = $structure;
884 0 $self->{_from_unix} = \%from_unixtime;
885 0 $self->{_to_unix} = \%to_unixtime;
886 0 $self->{query_type} = $query_type;
887 0 $self->{bind} = $tbl_o->database_object->use_bind;
888 0 return( $self );
889 }
890  
891 0 ▶sub group { return( shift->_group_order( 'group', 'group_by', @_ ) ); }
Subroutine group: not called CC=1 SCAR=6.9
Pod documented
892  
893 0 ▶sub having { return( shift->error( "Having clause is not supported by this driver." ) ); }
Subroutine having: not called CC=1 SCAR=6.9
Pod documented
894  
895 # $tbl->insert( field1 => $val1, field2 => $val2 );
896 # or
897 # $tbl->insert([ field1 => $val1, field2 => $val2 ]);
898 # or
899 # $tbl->insert({ field1 => $val1, field2 => $val2 });
900 # or
901 # my $select_statement_object = $tbl2->select || die( $tbl2->error );
902 # $tbl->insert( $select_statement_object );
903 # or
904 # my $select_statement_object = $tbl2->select || die( $tbl2->error );
905 # $tbl->insert( field1 => $val1, field2 => $val2, $select_statement_object );
906 # or
907 # my $select_statement_object = $tbl2->select || die( $tbl2->error );
908 # $tbl->insert([ field1 => $val1, field2 => $val2, $select_statement_object ]);
909 sub insert
910 0 ▶{
Subroutine insert: not called CC=46 SCAR=76.8
Pod documented
911 0 my $self = shift( @_ );
912 # Could be an array of fields, or a SQL statement object.
913 0 ▶ my $data = shift( @_ ) if( @_ == 1 && ref( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and ref $_[0] 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
914 0 my @arg = @_;
915 0 my $constant = $self->constant;
916 0 ▶ if( scalar( keys( %$constant ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$constant) 0 0 0
917 {
918 0 ▶ return( $constant->{sth} ) if( $constant->{sth} && $self->_is_object( $constant->{sth} ) && $constant->{sth}->isa( 'DB::Object::Statement' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement") 0 0 0
Condition0%0/6
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
!ll&&!rl&&r
000
$constant->{"sth"} and $self->_is_object($constant->{"sth"})
!ll&&!rl&&r
000
MC/DC0%0/3
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
$constant->{"sth"} $self->_is_object($constant->{"sth"}) $constant->{"sth"}->isa("DB::Object::Statement")
Truth table0%0/4
A and B and C
A= $constant->{"sth"}B= $self->_is_object($constant->{"sth"})C= $constant->{"sth"}->isa("DB::Object::Statement")
ABCresult
0XX0
10X0
1100
1111
919 }
920 0 my %arg = ();
921 0 my $select = '';
922 0 my $base_class = $self->base_class;
923 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
924 0 ▶ my $table = $tbl_o->name ||
Condition0%0/2
$tbl_o->name || (return $self->error('No table was provided to insert data.'))
l!l
00
MC/DC0%0/1
$tbl_o->name || (return $self->error('No table was provided to insert data.'))
$tbl_o->name
Truth table0%0/2
A
A= $tbl_o->name
Aresult
11
00
925 return( $self->error( "No table was provided to insert data." ) );
926 # We do not decide of the value of AUTO_INCREMENT fields, so we do not use them in
927 # our INSERT statement.
928 0 ▶ my $fields_ref = $tbl_o->fields || return( $self->pass_error( $tbl_o->error ) );
Condition0%0/2
$tbl_o->fields || (return $self->pass_error($tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->fields || (return $self->pass_error($tbl_o->error))
$tbl_o->fields
Truth table0%0/2
A
A= $tbl_o->fields
Aresult
11
00
929 0 my @avoid = ();
930 0 my( $fields, $values, $elems );
931 0 my $el = $self->elements;
932  
933 0 ▶ if( !@arg && $data && $self->_is_hash( $data => 'strict' ) )
Branch: 4 branches
BranchTrueFalseTotal
if (not @arg and $data and $self->_is_hash($data, 'strict')) { } 0 0 0
elsif (not @arg and ref $data and $self->_is_array($data)) { } 0 0 0
elsif ($data and ref $data eq "${base_class}::Statement") { } 0 0 0
elsif (scalar @arg and $self->_is_a($arg[-1], "${base_class}::Statement")) { } 0 0 0
Condition0%0/6
not @arg and $data and $self->_is_hash($data, "strict")
!ll&&!rl&&r
000
not @arg and $data
!ll&&!rl&&r
000
MC/DC0%0/3
not @arg and $data and $self->_is_hash($data, "strict")
not @arg $data $self->_is_hash($data, "strict")
Truth table0%0/4
not(A) and B and C
A= not @argB= $dataC= $self->_is_hash($data, "strict")
ABCresult
0XX0
10X0
1100
1111
934 {
935 0 @arg = %$data;
936 }
937 # User passed an array reference
938 ▶ elsif( !@arg && ref( $data ) && $self->_is_array( $data ) )
Condition0%0/6
not @arg and ref $data and $self->_is_array($data)
!ll&&!rl&&r
000
not @arg and ref $data
!ll&&!rl&&r
000
MC/DC0%0/3
not @arg and ref $data and $self->_is_array($data)
not @arg ref $data $self->_is_array($data)
Truth table0%0/4
not(A) and B and C
A= not @argB= ref $dataC= $self->_is_array($data)
ABCresult
0XX0
10X0
1100
1111
939 {
940 0 @arg = @$data;
941 0 ▶ if( scalar( @arg ) && $self->_is_a( $arg[-1] => "${base_class}::Statement" ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @arg and $self->_is_a($arg[-1], "${base_class}::Statement")) 0 0 0
Condition0%0/3
scalar @arg and $self->_is_a($arg[-1], "${base_class}::Statement")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @arg and $self->_is_a($arg[-1], "${base_class}::Statement")
scalar @arg $self->_is_a($arg[-1], "${base_class}::Statement")
Truth table0%0/3
A and B
A= scalar @argB= $self->_is_a($arg[-1], "${base_class}::Statement")
ABresult
0X0
100
111
942 {
943 0 my $sth = pop( @arg );
944 0 $select = $sth->as_string;
945 0 $el->merge( $sth->query_object->elements );
946 }
947 }
948 # insert into (field1, field2, field3) select field1, field2, field3 from some_table where some_id=12
949 ▶ elsif( $data && ref( $data ) eq "${base_class}::Statement" )
Condition0%0/3
$data and ref $data eq "${base_class}::Statement"
!ll&&!rl&&r
000
MC/DC0%0/2
$data and ref $data eq "${base_class}::Statement"
$data ref $data eq "${base_class}::Statement"
Truth table0%0/3
A and B
A= $dataB= ref $data eq "${base_class}::Statement"
ABresult
0X0
100
111
950 {
951 0 $select = $data->as_string;
952 0 $el->merge( $data->query_object->elements );
953 }
954 ▶ elsif( scalar( @arg ) && $self->_is_a( $arg[-1] => "${base_class}::Statement" ) )
Condition0%0/3
scalar @arg and $self->_is_a($arg[-1], "${base_class}::Statement")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @arg and $self->_is_a($arg[-1], "${base_class}::Statement")
scalar @arg $self->_is_a($arg[-1], "${base_class}::Statement")
Truth table0%0/3
A and B
A= scalar @argB= $self->_is_a($arg[-1], "${base_class}::Statement")
ABresult
0X0
100
111
955 {
956 0 my $sth = pop( @arg );
957 0 $select = $sth->as_string;
958 0 $el->merge( $sth->query_object->elements );
959 }
960 0 my @query = ();
961 0 ▶ if( $select )
Branch: 1 branch
BranchTrueFalseTotal
if ($select) { } 0 0 0
962 {
963 0 my $sql;
964 0 ▶ if( scalar( @arg ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @arg) { } 0 0 0
965 {
966 0 ▶ for( my $i = 0; $i < scalar( @arg ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @arg) 0 0 0
967 {
968 0 ▶ if( $self->_is_a( $arg[$i] => 'DB::Object::Fields::Unknown' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($arg[$i], "DB::Object::Fields::Unknown")) 0 0 0
969 {
970 0 ▶ warn( "Unknown field object '", $arg[$i]->field, "' provided for INSERT into table '", $arg[$i], "'" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
971 0 splice( @arg, $i, 1 );
972 }
973 }
974 0 $sql = "INSERT INTO $table (" . join( ', ', @arg ) . ") $select";
975 }
976 else
977 {
978 0 $sql = "INSERT INTO $table $select";
979 }
980 0 @query = ( $sql );
981 }
982 else
983 {
984 0 ▶ %arg = @arg if( @arg );
Branch: 1 branch
BranchTrueFalseTotal
if @arg 0 0 0
985 0 foreach my $field ( keys( %$fields_ref ) )
986 {
987 0 my $fo = $fields_ref->{ $field };
988 # push( @avoid, $field ) if( $fields_ref->{ $field } =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/i && !$arg{ $field } );
989 0 ▶ if( defined( $fo->default ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fo->default and $fo->default =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/i and not $arg{$field}) 0 0 0
Condition0%0/6
defined $fo->default and $fo->default =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/i and not $arg{$field}
!ll&&!rl&&r
000
defined $fo->default and $fo->default =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/i
!ll&&!rl&&r
000
MC/DC0%0/3
defined $fo->default and $fo->default =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/i and not $arg{$field}
defined $fo->default $fo->default =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/i not $arg{$field}
Truth table0%0/4
A and B and not(C)
A= defined $fo->defaultB= $fo->default =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/iC= not $arg{$field}
ABCresult
0XX0
10X0
1100
1111
990 $fo->default =~ /\b(AUTO_INCREMENT|SERIAL|nextval)\b/i &&
991 !$arg{ $field } )
992 {
993 0 push( @avoid, $field );
994 }
995 # It is useless to insert a blank data in a field whose default value is NULL.
996 # Especially since a test on a NULL field may be made specifically.
997 0 ▶ if( scalar( @arg ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @arg and not exists $arg{$field} and $fo->is_nullable) 0 0 0
Condition0%0/6
scalar @arg and not exists $arg{$field} and $fo->is_nullable
!ll&&!rl&&r
000
scalar @arg and not exists $arg{$field}
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @arg and not exists $arg{$field} and $fo->is_nullable
scalar @arg not exists $arg{$field} $fo->is_nullable
Truth table0%0/4
A and not(B) and C
A= scalar @argB= not exists $arg{$field}C= $fo->is_nullable
ABCresult
0XX0
10X0
1100
1111
998 !exists( $arg{ $field } ) &&
999 $fo->is_nullable )
1000 {
1001 0 push( @avoid, $field );
1002 }
1003 }
1004 $self->getdefault(
1005 0 ▶ table => $table,
Branch: 1 branch
BranchTrueFalseTotal
$self->getdefault("table", $table, "arg", \@arg, "avoid", \@avoid) or return $self->pass_error 0 0 0
1006 arg => \@arg,
1007 avoid => \@avoid,
1008 ) || return( $self->pass_error );
1009 0 ▶ $elems = $self->format_statement || return( $self->pass_error );
Condition0%0/2
$self->format_statement || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->format_statement || (return $self->pass_error)
$self->format_statement
Truth table0%0/2
A
A= $self->format_statement
Aresult
11
00
1010 0 $fields = $elems->fields->join( ', ' );
1011 0 $values = $elems->formats->join( ', ' );
1012 0 $el->merge( $elems );
1013 0 @query = ( "INSERT INTO $table ($fields) VALUES($values)" );
1014 }
1015  
1016 0 ▶ if( $data && $self->_is_hash( $data => 'strict' ) && $el->types->length )
Branch: 1 branch
BranchTrueFalseTotal
if ($data and $self->_is_hash($data, "strict") and $el->types->length) 0 0 0
Condition0%0/6
$data and $self->_is_hash($data, "strict") and $el->types->length
!ll&&!rl&&r
000
$data and $self->_is_hash($data, "strict")
!ll&&!rl&&r
000
MC/DC0%0/3
$data and $self->_is_hash($data, "strict") and $el->types->length
$data $self->_is_hash($data, "strict") $el->types->length
Truth table0%0/4
A and B and C
A= $dataB= $self->_is_hash($data, "strict")C= $el->types->length
ABCresult
0XX0
10X0
1100
1111
1017 {
1018 0 ▶ warn( "You have passed arguments to this insert as hash reference, and you are using placeholders. Using placeholders requires fixed order of arguments which an hash reference cannot guarantee. This will potentially lead to error when executing the query. I recommend you switch to an array of arguments instead, i.e. from { field1 => value1, field2 => value2 } to ( field1 => value1, field2 => value2 ), or to use numbered placeholders like \$1, \$2, etc..." ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
1019 }
1020 0 ▶ my $clauses = $self->_query_components( 'insert' ) || return( $self->pass_error );
Condition0%0/2
$self->_query_components('insert') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_query_components('insert') || (return $self->pass_error)
$self->_query_components('insert')
Truth table0%0/2
A
A= $self->_query_components('insert')
Aresult
11
00
1021 0 ▶ push( @query, @$clauses ) if( scalar( @$clauses ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$clauses 0 0 0
1022 0 my $query = $self->{query} = CORE::join( ' ', @query );
1023 # Everything meaningfull lies within the object
1024 # If no bind should be done _save_bind does nothing
1025 0 $self->_save_bind();
1026 # Query string should lie within the object
1027 # _cache_this sends back an object no matter what or unde() if an error occurs
1028 0 my $sth = $tbl_o->_cache_this( $self );
1029 # STOP! No need to go further
1030 0 ▶ if( !defined( $sth ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sth) 0 0 0
1031 {
1032 0 return( $self->error( "Error '", $tbl_o->error, "' while preparing query to insert data into table '$table':\n$query" ) );
1033 }
1034 # Called in void context
1035 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
1036 {
1037 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing query to insert data to table '${table}':\n$query") 0 0 0
1038 return( $self->error( "Error while executing query to insert data to table '$table':\n$query" ) );
1039 }
1040 0 return( $sth );
1041 }
1042  
1043 0 ▶sub is_upsert { return( shift->_set_get_boolean( 'is_upsert', @_ ) ); }
Subroutine is_upsert: not called CC=1 SCAR=6.9
Pod documented
1044  
1045 0 ▶sub join_fields { return( shift->_set_get_scalar( 'join_fields', @_ ) ); }
Subroutine join_fields: not called CC=1 SCAR=6.9
Pod documented
1046  
1047 0 ▶sub join_tables { return( shift->_set_get_object_array_object( 'join_tables', 'DB::Object::Tables', @_ ) ); }
Subroutine join_tables: not called CC=1 SCAR=6.9
Pod documented
1048  
1049 0 ▶sub left_join { return( shift->_set_get_hash( 'left_join', @_ ) ); }
Subroutine left_join: not called CC=1 SCAR=6.9
Pod documented
1050  
1051 sub limit
1052 0 ▶{
Subroutine limit: not called CC=11 SCAR=48.8
Pod documented
1053 0 my $self = shift( @_ );
1054 0 my $limit = $self->{limit};
1055 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1056 {
1057 # Returns a DB::Object::Query::Clause
1058 0 ▶ $limit = $self->_process_limit( @_ ) ||
Condition0%0/2
$self->_process_limit(@_) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_process_limit(@_) || (return $self->pass_error)
$self->_process_limit(@_)
Truth table0%0/2
A
A= $self->_process_limit(@_)
Aresult
11
00
1059 return( $self->pass_error );
1060 0 ▶ if( CORE::length( $limit->metadata->limit // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length($limit->metadata->limit // "")) 0 0 0
Condition0%0/2
$limit->metadata->limit // ""
l!l
00
MC/DC0%0/1
$limit->metadata->limit // ""
$limit->metadata->limit
Truth table0%0/2
A
A= $limit->metadata->limit
Aresult
11
00
1061 {
1062 0 ▶ $limit->generic( CORE::length( $limit->metadata->offset // '' ) ? 'LIMIT ?, ?' : 'LIMIT ?' );
Branch: 1 branch
BranchTrueFalseTotal
length($limit->metadata->offset // '') ? : 0 0 0
Condition0%0/2
$limit->metadata->offset // ""
l!l
00
MC/DC0%0/1
$limit->metadata->offset // ""
$limit->metadata->offset
Truth table0%0/2
A
A= $limit->metadata->offset
Aresult
11
00
1063 # %s works for integer, and also for numbered placeholders like $1 or ?1, or regular placeholder like ?
1064 0 ▶ $limit->value(
Branch: 1 branch
BranchTrueFalseTotal
length($limit->metadata->offset // '') ? : 0 0 0
Condition0%0/2
$limit->metadata->offset // ""
l!l
00
MC/DC0%0/1
$limit->metadata->offset // ""
$limit->metadata->offset
Truth table0%0/2
A
A= $limit->metadata->offset
Aresult
11
00
1065 CORE::length( $limit->metadata->offset // '' )
1066 ? sprintf( "LIMIT %s, %s", $limit->metadata->offset, $limit->metadata->limit )
1067 : sprintf( "LIMIT %s", $limit->metadata->limit )
1068 );
1069 }
1070 }
1071  
1072 0 ▶ if( !$limit && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $limit and want("OBJECT")) 0 0 0
Condition0%0/3
not $limit and want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not $limit and want("OBJECT")
not $limit want("OBJECT")
Truth table0%0/3
not(A) and B
A= not $limitB= want("OBJECT")
ABresult
0X0
100
111
1073 {
1074 0 return( $self->new_null( type => 'object' ) );
1075 }
1076 0 return( $limit );
1077 }
1078  
1079 sub local
1080 0 ▶{
Subroutine local: not called CC=8 SCAR=42.8
Pod documented
1081 0 my $self = shift( @_ );
1082 0 ▶ $self->{local} ||= {};
Condition0%0/2
$self->{"local"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"local"} ||= {}
$self->{"local"}
Truth table0%0/2
A
A= $self->{"local"}
Aresult
11
00
1083 0 my $local = $self->{local};
1084 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1085 {
1086 0 my $data = $self->_get_args_as_hash( @_ );
1087 0 my $str = '';
1088 0 ▶ if( scalar( keys( %$data ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$data) 0 0 0
1089 {
1090 0 my @keys = keys( %$data );
1091 0 @$local{ @keys } = @$data{ @keys };
1092 }
1093 }
1094 0 ▶ return( wantarray() ? () : undef() ) if( !$local || !%$local );
Branch: 2 branches
BranchTrueFalseTotal
unless $local and %$local 0 0 0
wantarray ? : 0 0 0
Condition0%0/3
$local and %$local
!ll&&!rl&&r
000
MC/DC0%0/2
$local and %$local
$local %$local
Truth table0%0/3
A and B
A= $localB= %$local
ABresult
0X0
100
111
1095 0 ▶ return( %$local ) if( wantarray() );
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
1096 0 my $str = join( ', ', map{ "\@${_} = '" . $local->{ $_ } . "'" } keys( %$local ) );
1097 # return( "SET $str" );
1098 0 return( $str );
1099 }
1100  
1101 0 ▶sub lock { return( shift->error( "Locking mechanism is not supported by this driver." ) ); }
Subroutine lock: not called CC=1 SCAR=6.9
Pod documented
1102  
1103 sub new_clause
1104 0 ▶{
Subroutine new_clause: not called CC=4 SCAR=30.0
Pod documented
1105 0 my $self = shift( @_ );
1106 0 my $opts = $self->_get_args_as_hash( @_ );
1107 0 ▶ $opts->{debug} = $self->debug if( !exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"debug"} 0 0 0
1108 0 $opts->{query_object} = $self;
1109 0 ▶ my $o = DB::Object::Query::Clause->new( %$opts ) ||
Condition0%0/2
'DB::Object::Query::Clause'->new(%$opts) || (return $self->error('Unable to create a DB::Object::Query::Clause object: ', 'DB::Object::Query::Clause'->error))
l!l
00
MC/DC0%0/1
'DB::Object::Query::Clause'->new(%$opts) || (return $self->error('Unable to create a DB::Object::Query::Clause object: ', 'DB::Object::Query::Clause'->error))
'DB::Object::Query::Clause'->new(%$opts)
Truth table0%0/2
A
A= 'DB::Object::Query::Clause'->new(%$opts)
Aresult
11
00
1110 return( $self->error( "Unable to create a DB::Object::Query::Clause object: ", DB::Object::Query::Clause->error ) );
1111 # Weaken the back-reference to the query object to prevent circular reference memory leaks.
1112 0 ▶ weaken( $o->{query_object} ) if( $o->{query_object} );
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"query_object"} 0 0 0
1113 0 return( $o );
1114 }
1115  
1116 sub new_element
1117 0 ▶{
Subroutine new_element: not called CC=4 SCAR=30.0
Pod documented
1118 0 my $self = shift( @_ );
1119 0 my $opts = $self->_get_args_as_hash( @_ );
1120 0 ▶ $opts->{debug} = $self->debug if( !exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"debug"} 0 0 0
1121 0 $opts->{query_object} = $self;
1122 0 ▶ my $elem = DB::Object::Query::Element->new( %$opts ) ||
Condition0%0/2
'DB::Object::Query::Element'->new(%$opts) || (return $self->pass_error('DB::Object::Query::Element'->error))
l!l
00
MC/DC0%0/1
'DB::Object::Query::Element'->new(%$opts) || (return $self->pass_error('DB::Object::Query::Element'->error))
'DB::Object::Query::Element'->new(%$opts)
Truth table0%0/2
A
A= 'DB::Object::Query::Element'->new(%$opts)
Aresult
11
00
1123 return( $self->pass_error( DB::Object::Query::Element->error ) );
1124 # Weaken the back-reference to the query object to prevent circular reference memory leaks.
1125 0 ▶ weaken( $elem->{query_object} ) if( $elem->{query_object} );
Branch: 1 branch
BranchTrueFalseTotal
if $elem->{"query_object"} 0 0 0
1126 0 return( $elem );
1127 }
1128  
1129 sub new_elements
1130 1 ▶{
Subroutine new_elements: called CC=4 SCAR=14.3
Pod documented
1131 1 my $self = shift( @_ );
1132 1 my $opts = $self->_get_args_as_hash( @_ );
1133 1 ▶ $opts->{debug} = $self->debug if( !exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"debug"} 1 0 1
1134 1 $opts->{query_object} = $self;
1135 1 ▶ my $e = DB::Object::Query::Elements->new( %$opts ) ||
Condition50%1/2
'DB::Object::Query::Elements'->new(%$opts) || (return $self->pass_error('DB::Object::Query::Elements'->error))
l!l
10
MC/DC0%0/1
'DB::Object::Query::Elements'->new(%$opts) || (return $self->pass_error('DB::Object::Query::Elements'->error))
'DB::Object::Query::Elements'->new(%$opts)
Truth table50%1/2
A
A= 'DB::Object::Query::Elements'->new(%$opts)
Aresult
11
00
1136 return( $self->pass_error( DB::Object::Query::Elements->error ) );
1137 # Weaken the back-reference to the query object to prevent circular reference memory leaks.
1138 1 ▶ weaken( $e->{query_object} ) if( $e->{query_object} );
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"query_object"} 1 0 1
1139 1 return( $e );
1140 }
1141  
1142 0 ▶sub order { return( shift->_group_order( 'order', 'order_by', @_ ) ); }
Subroutine order: not called CC=1 SCAR=6.9
Pod documented
1143  
1144 sub pass_error
1145 0 ▶{
Subroutine pass_error: not called CC=2 SCAR=17.9
Pod documented
1146 0 my $self = shift( @_ );
1147  
1148 # Propagating an error also taints this query object.
1149 0 ▶ $self->{dirty} = 1 if( ref( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 0 0 0
1150  
1151 0 return( $self->SUPER::pass_error( @_ ) );
1152 }
1153  
1154 0 ▶sub prepare_options { return( shift->_set_get_hash_as_mix_object( 'prepare_options', @_ ) ); }
Subroutine prepare_options: not called CC=1 SCAR=6.9
Pod documented
1155  
1156 0 ▶sub query { return( shift->_set_get_scalar( 'query', @_ ) ); }
Subroutine query: not called CC=1 SCAR=6.9
Pod documented
1157  
1158 0 ▶sub query_reset { return( shift->_set_get_boolean( 'query_reset', @_ ) ); }
Subroutine query_reset: not called CC=1 SCAR=6.9
Pod documented
1159  
1160 0 ▶sub query_reset_core_keys { return( shift->_set_get_array_as_object( 'query_reset_core_keys', @_ ) ); }
Subroutine query_reset_core_keys: not called CC=1 SCAR=6.9
Pod documented
1161  
1162 0 ▶sub query_reset_keys { return( shift->_set_get_array_as_object( 'query_reset_keys', @_ ) ); }
Subroutine query_reset_keys: not called CC=1 SCAR=6.9
Pod documented
1163  
1164 0 ▶sub query_type { return( shift->_set_get_scalar( 'query_type', @_ ) ); }
Subroutine query_type: not called CC=1 SCAR=6.9
Pod documented
1165  
1166 0 ▶sub query_values { return( shift->_set_get_scalar_as_object( 'query_values', @_ ) ); }
Subroutine query_values: not called CC=1 SCAR=6.9
Pod documented
1167  
1168 0 ▶sub replace { return( shift->error( "The replace sql query is not supported by this driver." ) ); }
Subroutine replace: not called CC=1 SCAR=6.9
Pod documented
1169  
1170 sub reset
1171 0 ▶{
Subroutine reset: not called CC=3 SCAR=24.8
Pod documented
1172 0 my $self = shift( @_ );
1173 0 ▶ if( !$self->{query_reset} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"query_reset"}) 0 0 0
1174 {
1175 0 my $core_keys = $self->query_reset_core_keys;
1176 0 my $keys = $self->query_reset_keys;
1177 # Make sure the driver's list of keys for query reset is complete by merging this base class keys with the diver's one
1178 0 ▶ unless( $core_keys == $keys )
Branch: 1 branch
BranchTrueFalseTotal
unless ($core_keys == $keys) 0 0 0
1179 {
1180 0 my $new_keys = $keys->merge( $core_keys )->unique->sort;
1181 0 $keys = $self->query_reset_keys( $new_keys );
1182 }
1183 0 CORE::delete( @$self{ @$keys } );
1184 # elements is not in query_reset_core_keys because CORE::delete would leave it undef
1185 # and there is no re-init pass after reset(). We clear it explicitly here instead,
1186 # so that _save_bind() on each fresh select() starts from an empty element stack.
1187 0 $self->{elements} = $self->new_elements;
1188 0 $self->{query_reset}++;
1189 # $self->{enhance} = 1;
1190 }
1191 0 return( $self );
1192 }
1193  
1194 sub reset_bind
1195 0 ▶{
Subroutine reset_bind: not called CC=2 SCAR=17.9
Pod documented
1196 0 my $self = shift( @_ );
1197 0 my @f = qw( binded binded_group binded_limit binded_order binded_types binded_where );
1198 0 foreach my $field ( @f )
1199 {
1200 0 $self->{ $field } = [];
1201 }
1202 0 return( $self );
1203 }
1204  
1205 0 ▶sub returning { return( shift->error( "Returning clause is not supported by this driver" ) ); }
Subroutine returning: not called CC=1 SCAR=6.9
Pod documented
1206  
1207 sub reverse
1208 0 ▶{
Subroutine reverse: not called CC=2 SCAR=17.9
Pod documented
1209 0 my $self = shift( @_ );
1210 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1211 {
1212 0 $self->{reverse}++;
1213 }
1214 0 return( $self->{reverse} );
1215 }
1216  
1217 sub select
1218 0 ▶{
Subroutine select: not called CC=50 SCAR=78.4
Pod documented
1219 0 my $self = shift( @_ );
1220 0 my $constant = $self->constant;
1221 0 ▶ if( scalar( keys( %$constant ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$constant) 0 0 0
1222 {
1223 0 ▶ return( $constant->{sth} ) if( $constant->{sth} && $self->_is_object( $constant->{sth} ) && $constant->{sth}->isa( 'DB::Object::Statement' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement") 0 0 0
Condition0%0/6
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
!ll&&!rl&&r
000
$constant->{"sth"} and $self->_is_object($constant->{"sth"})
!ll&&!rl&&r
000
MC/DC0%0/3
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
$constant->{"sth"} $self->_is_object($constant->{"sth"}) $constant->{"sth"}->isa("DB::Object::Statement")
Truth table0%0/4
A and B and C
A= $constant->{"sth"}B= $self->_is_object($constant->{"sth"})C= $constant->{"sth"}->isa("DB::Object::Statement")
ABCresult
0XX0
10X0
1100
1111
1224 }
1225 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
1226 0 ▶ my $prefix = $tbl_o->query_object->table_alias ? $tbl_o->query_object->table_alias : $tbl_o->prefix;
Branch: 1 branch
BranchTrueFalseTotal
$tbl_o->query_object->table_alias ? : 0 0 0
1227 0 ▶ my $table = $tbl_o->qualified_name ||
Condition0%0/2
$tbl_o->qualified_name || (return $self->error('No table name provided to perform select statement.'))
l!l
00
MC/DC0%0/1
$tbl_o->qualified_name || (return $self->error('No table name provided to perform select statement.'))
$tbl_o->qualified_name
Truth table0%0/2
A
A= $tbl_o->qualified_name
Aresult
11
00
1228 return( $self->error( "No table name provided to perform select statement." ) );
1229 0 my $bind = $tbl_o->use_bind;
1230 0 my $cache = $tbl_o->use_cache;
1231 0 my $multi_db = $tbl_o->prefix_database;
1232 0 my $db = $tbl_o->database();
1233 0 my $fields = '';
1234 0 my $ok_ref = $tbl_o->fields;
1235 0 my $ok_list = CORE::join( '|', keys( %$ok_ref ) );
1236 0 my $tables = CORE::join( '|', @{$tbl_o->database_object->tables} );
1237 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1238 {
1239 # Get aliases
1240 0 my $alias = $self->alias();
1241 0 ▶ my $data = ( @_ == 1 && ref( $_[0] ) ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] ? : 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
1242 0 ▶ if( ref( $data ) eq 'SCALAR' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'SCALAR') { } 0 0 0
elsif ($self->_is_array($data)) { } 0 0 0
1243 {
1244 0 $fields = $$data;
1245 }
1246 elsif( $self->_is_array( $data ) )
1247 {
1248 # Remove from the provided list any name that are aliases
1249 0 ▶ FIELD: for( my $i = 0; $i < scalar( @$data ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$data) 0 0 0
1250 {
1251 0 ▶ if( $self->_is_a( $data->[$i] => 'DB::Object::Fields::Unknown' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($data->[$i], "DB::Object::Fields::Unknown")) 0 0 0
1252 {
1253 0 ▶ warn( "Unknown field object '", $data->[$i]->field, "' of table '", $data->[$i]->table, "' used in SELECT statement" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
1254 0 splice( @$data, $i, 1 );
1255 0 $i--;
1256 0 next;
1257 }
1258  
1259 0 foreach my $n ( keys( %$alias ) )
1260 {
1261 0 ▶ if( lc( $alias->{ $n } ) eq lc( $data->[$i] ) )
Branch: 1 branch
BranchTrueFalseTotal
if (lc $alias->{$n} eq lc $data->[$i]) 0 0 0
1262 {
1263 0 splice( @$data, $i, 1 );
1264 0 $i--;
1265 0 next FIELD;
1266 }
1267 }
1268 }
1269 # No fields provided after all? We fallback to use the magic '*' optimizer
1270 0 ▶ $fields = @$data
Branch: 3 branches
BranchTrueFalseTotal
@$data ? : 0 0 0
scalar keys %$alias ? : 0 0 0
$prefix ? : 0 0 0
1271 ? CORE::join( ', ', @$data )
1272 : scalar( keys( %$alias ) )
1273 ? ''
1274 : ( $prefix ? "${prefix}.*" : '*' );
1275 }
1276 else
1277 {
1278 0 $fields = $data;
1279 }
1280  
1281 0 ▶ if( length( $fields ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $fields) 0 0 0
1282 {
1283 # Now, we eventually add the table and database specification to the fields
1284 0 $fields =~ s{
1285 (?<![\.\"])\b($ok_list)\b(\s*)?(?!\.)
1286 }
1287 {
1288 0 my( $field, $spc ) = ( $1, $2 );
1289 0 ▶ if( $` =~ /\s+(?:AS|FROM)\s+$/i || !$field )
Branch: 2 branches
BranchTrueFalseTotal
if ($` =~ /\s+(?:AS|FROM)\s+$/i or not $field) { } 0 0 0
elsif ($prefix) { } 0 0 0
Condition0%0/3
$` =~ /\s+(?:AS|FROM)\s+$/i or not $field
l!l&&r!l&&!r
000
MC/DC0%0/2
$` =~ /\s+(?:AS|FROM)\s+$/i or not $field
$` =~ /\s+(?:AS|FROM)\s+$/i not $field
Truth table0%0/3
A or not(B)
A= $` =~ /\s+(?:AS|FROM)\s+$/iB= not $field
ABresult
1X1
011
000
1290 {
1291 0 "${field}${spc}";
1292 }
1293 elsif( $prefix )
1294 {
1295 0 "${prefix}.${field}${spc}";
1296 }
1297 else
1298 {
1299 0 "${field}${spc}";
1300 }
1301 }gex;
1302 0 ▶ $fields =~ s/(?<!\.)($tables)(?:\.)/$db\.$1\./g if( $multi_db );
Branch: 1 branch
BranchTrueFalseTotal
if $multi_db 0 0 0
1303 }
1304  
1305 0 ▶ if( $alias && %$alias )
Branch: 1 branch
BranchTrueFalseTotal
if ($alias and %$alias) 0 0 0
Condition0%0/3
$alias and %$alias
!ll&&!rl&&r
000
MC/DC0%0/2
$alias and %$alias
$alias %$alias
Truth table0%0/3
A and B
A= $aliasB= %$alias
ABresult
0X0
100
111
1306 {
1307 0 my @aliases = ();
1308 0 foreach my $f ( keys( %$alias ) )
1309 {
1310 0 ▶ if( ref( $alias->{ $f } ) eq 'SCALAR' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $alias->{$f} eq 'SCALAR') { } 0 0 0
elsif (exists $ok_ref->{$f} and $prefix) { } 0 0 0
elsif ($f =~ /\b(?:$ok_list)\b/ or $f =~ /\w\([^\)]*\)/) { } 0 0 0
1311 {
1312 0 CORE::push( @aliases, "$f AS " . ${$alias->{ $f }} );
1313 }
1314 ▶ elsif( CORE::exists( $ok_ref->{ $f } ) && $prefix )
Condition0%0/3
exists $ok_ref->{$f} and $prefix
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ok_ref->{$f} and $prefix
exists $ok_ref->{$f} $prefix
Truth table0%0/3
A and B
A= exists $ok_ref->{$f}B= $prefix
ABresult
0X0
100
111
1315 {
1316 0 CORE::push( @aliases, "${prefix}.${f} AS \"" . $alias->{ $f } . "\"" );
1317 }
1318 ▶ elsif( $f =~ /\b(?:$ok_list)\b/ ||
Condition0%0/3
$f =~ /\b(?:$ok_list)\b/ or $f =~ /\w\([^\)]*\)/
l!l&&r!l&&!r
000
MC/DC0%0/2
$f =~ /\b(?:$ok_list)\b/ or $f =~ /\w\([^\)]*\)/
$f =~ /\b(?:$ok_list)\b/ $f =~ /\w\([^\)]*\)/
Truth table0%0/3
A or B
A= $f =~ /\b(?:$ok_list)\b/B= $f =~ /\w\([^\)]*\)/
ABresult
1X1
011
000
1319 $f =~ /\w\([^\)]*\)/ )
1320 {
1321 0 ▶ $f =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
1322 (?<![\.\"])\b($ok_list)\b(\s*)?(?!\.)
1323 }
1324 {
1325 0 my( $ok, $spc ) = ( $1, $2 );
1326 0 "${prefix}.${ok}${spc}";
1327 }gex if( $prefix );
1328 0 ▶ $f =~ s/(?<!\.)($tables)(?:\.)/$db\.$1\./g if( $multi_db );
Branch: 1 branch
BranchTrueFalseTotal
if $multi_db 0 0 0
1329 0 CORE::push( @aliases, "$f AS " . "\"" . $alias->{ $f } . "\"" );
1330 }
1331 else
1332 {
1333 0 CORE::push( @aliases, "$f AS " . "\"" . $alias->{ $f } . "\"" );
1334 }
1335 }
1336 0 ▶ $fields = length( $fields )
Branch: 1 branch
BranchTrueFalseTotal
length $fields ? : 0 0 0
1337 ? join( ', ', $fields, @aliases )
1338 : join( ', ', @aliases );
1339 }
1340 }
1341 else
1342 {
1343 0 ▶ $self->getdefault( table => $table ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->getdefault("table", $table) or return $self->pass_error 0 0 0
1344 0 ▶ my $elems = $self->format_statement || return( $self->pass_error );
Condition0%0/2
$self->format_statement || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->format_statement || (return $self->pass_error)
$self->format_statement
Truth table0%0/2
A
A= $self->format_statement
Aresult
11
00
1345 0 $fields = $elems->fields->join( ', ' );
1346 }
1347  
1348 0 my $tie = $self->tie();
1349 0 ▶ my $clauses = $self->_query_components( 'select' ) || return( $self->pass_error );
Condition0%0/2
$self->_query_components('select') || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->_query_components('select') || (return $self->pass_error)
$self->_query_components('select')
Truth table0%0/2
A
A= $self->_query_components('select')
Aresult
11
00
1350 0 my $vars = $self->local();
1351 # You may not sort if there is no order clause
1352 0 ▶ my $sort = $self->reverse() ? 'DESC' : $self->sort() ? 'ASC' : '';
Branch: 2 branches
BranchTrueFalseTotal
$self->reverse ? : 0 0 0
$self->sort ? : 0 0 0
1353 # my @query = $multi_db ? ( "SELECT $fields FROM $db.$table" ) : ( "SELECT $fields FROM $table" );
1354 # $table comes from $tbl->qualified_name which automatically sets itself with the right prefixes based on the prefixed() settings
1355 0 my $table_alias = '';
1356 0 ▶ if( length( $table_alias = $self->table_alias ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length($table_alias = $self->table_alias)) 0 0 0
1357 {
1358 0 $table_alias = " AS $table_alias";
1359 }
1360 0 my @query = ( "SELECT $fields FROM ${table}${table_alias}" );
1361 0 my $prev_fields = $self->selected_fields;
1362 0 my $last_sth = '';
1363 # my $queries = $self->_cache_queries;
1364 # # A simple check to avoid to do this test on each query, but rather only on those who deserve it.
1365 # if( $fields eq $prev_fields && @$queries )
1366 # {
1367 # my @last_query = grep
1368 # {
1369 # $_->selected_fields ||= '';
1370 # $_->selected_fields eq $fields
1371 # } @$queries;
1372 # $last_sth = $last_query[ 0 ] || {};
1373 # }
1374 # If the selected fields in the last query performed were the same than those ones and
1375 # that the last query object has the flag 'as_string' set to true, this would mean that
1376 # user has made a statement as string and is now really executing it
1377 # Now, if the special flag 'query_reset' is true, this means that the user has accessed the methods
1378 # where(), group(), order() or limit() and hence this is a brain new query for which we need
1379 # to get the clause conditions
1380 #if( $fields eq $$prev_fields && $last_sth->{ 'as_string' } )
1381 #{
1382 # unshift( @query, "${vars};" ) if( $vars );
1383 0 ▶ push( @query, @$clauses ) if( @$clauses );
Branch: 1 branch
BranchTrueFalseTotal
if @$clauses 0 0 0
1384 #}
1385 # used by join()
1386 0 $self->selected_fields( $fields );
1387 0 my $query = $self->{query} = CORE::join( ' ', @query );
1388 0 my @tie_order = ();
1389 0 ▶ if( $tie && %$tie )
Branch: 1 branch
BranchTrueFalseTotal
if ($tie and %$tie) 0 0 0
Condition0%0/3
$tie and %$tie
!ll&&!rl&&r
000
MC/DC0%0/2
$tie and %$tie
$tie %$tie
Truth table0%0/3
A and B
A= $tieB= %$tie
ABresult
0X0
100
111
1390 {
1391 0 my $copy = $fields;
1392 # According to bind_col() specifications, we need to bind perl variable
1393 # in the right column order.
1394 # We make it easy for our user, to only provide the column name and its corresponding variable
1395 # We will do the job of matching
1396 0 ▶ while( $copy =~ s/^.*?\b([a-zA-Z0-9\_]+)\s*(?:\,|\Z)// )
Branch: 1 branch
BranchTrueFalseTotal
if ($copy =~ s/^.*?\b([a-zA-Z0-9\_]+)\s*(?:\,|\Z)//) 0 0 0
1397 {
1398 0 push( @tie_order, $1 );
1399 }
1400 0 $self->{tie_order} = \@tie_order;
1401 }
1402 # Everything meaningfull lies within the object
1403 # If no bind should be done _save_bind does nothing
1404 0 $self->_save_bind();
1405  
1406 # Predeclare variables if any.
1407 0 $tbl_o->set();
1408  
1409 # Query string should lie within the object
1410 # _cache_this sends back an object no matter what or undef() if an error occurs
1411 0 my $sth = $tbl_o->_cache_this( $self );
1412 # STOP! No need to go further
1413 0 ▶ if( !defined( $sth ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sth) 0 0 0
1414 {
1415 0 return( $self->error( "Error while preparing query to select on table '", $tbl_o->name, "':\n$query\n", $tbl_o->error() ) );
1416 }
1417 # Routines such as as_string() expect an array on pupose so we do not have to commit the action
1418 # but rather get the statement string. At the end, we write:
1419 # $obj->select() to really select
1420 # $obj->select->as_string() to ONLY get the formatted statement
1421 # wantarray() returns the undefined value in void context, which is typical use of a real select command
1422 # i.e. $obj->select();
1423 # Straight forward declaration: $obj->select(); or $obj->select->execute() || die( $obj->error() );
1424 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
1425 {
1426 0 ▶ $sth->execute ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing query to select:\n", $self->as_string, "\n", $sth->errstr) 0 0 0
1427 return( $self->error( "Error while executing query to select:\n", $self->as_string(), "\n", $sth->errstr() ) );
1428 }
1429 0 return( $sth );
1430 }
1431  
1432 0 ▶sub selected_fields { return( shift->_set_get( 'selected_fields', @_ ) ); }
Subroutine selected_fields: not called CC=1 SCAR=6.9
Pod documented
1433  
1434 sub sort
1435 0 ▶{
Subroutine sort: not called CC=2 SCAR=17.9
Pod documented
1436 0 my $self = shift( @_ );
1437 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1438 {
1439 0 $self->{reverse} = 0;
1440 }
1441 0 return( $self->{reverse} );
1442 }
1443  
1444 # The fields in their order of appearance in insert and update
1445 # so that following ->exec( $hash ) would be able to allocate the bind values in the right order
1446 0 ▶sub sorted { return( shift->_set_get_array_as_object( 'sorted', @_ ) ); }
Subroutine sorted: not called CC=1 SCAR=6.9
Pod documented
1447  
1448 21 ▶sub table_alias { return( shift->_set_get_scalar( 'table_alias', @_ ) ); }
Subroutine table_alias: called CC=1 SCAR=0.0
Pod documented
1449  
1450 1 ▶sub table_object { return( shift->_set_get_object_without_init( 'table_object', 'DB::Object::Tables', @_ ) ); }
Subroutine table_object: called CC=1 SCAR=0.0
Pod documented
1451  
1452 sub tie
1453 0 ▶{
Subroutine tie: not called CC=6 SCAR=37.4
Pod documented
1454 0 my $self = shift( @_ );
1455 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1456 {
1457 0 my $ref = '';
1458 0 ▶ $ref = shift( @_ ) if( @_ && @_ % 2 );
Branch: 1 branch
BranchTrueFalseTotal
if @_ and @_ % 2 0 0 0
Condition0%0/3
@_ and @_ % 2
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and @_ % 2
@_ @_ % 2
Truth table0%0/3
A and B
A= @_B= @_ % 2
ABresult
0X0
100
111
1459 0 my %hash = ( @_ );
1460 0 ▶ $ref ||= \%hash;
Condition0%0/2
$ref ||= \%hash
l!l
00
MC/DC0%0/1
$ref ||= \%hash
$ref
Truth table0%0/2
A
A= $ref
Aresult
11
00
1461 0 $self->{tie} = $ref;
1462 }
1463 0 ▶ return( wantarray() ? %{$self->{tie}} : $self->{tie} );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1464 }
1465  
1466 0 ▶sub unix_timestamp { return( shift->_set_get_array_as_object( 'unix_timestamp', @_ ) ); }
Subroutine unix_timestamp: not called CC=1 SCAR=6.9
Pod documented
1467  
1468 sub update
1469 0 ▶{
Subroutine update: not called CC=23 SCAR=63.1
Pod documented
1470 0 my $self = shift( @_ );
1471 0 ▶ my $data = shift( @_ ) if( @_ == 1 && ref( $_[ 0 ] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and ref $_[0] 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
1472 0 my @arg = @_;
1473 0 ▶ if( !@arg && $data )
Branch: 1 branch
BranchTrueFalseTotal
if (not @arg and $data) 0 0 0
Condition0%0/3
not @arg and $data
!ll&&!rl&&r
000
MC/DC0%0/2
not @arg and $data
not @arg $data
Truth table0%0/3
not(A) and B
A= not @argB= $data
ABresult
0X0
100
111
1474 {
1475 0 ▶ if( $self->_is_hash( $data => 'strict' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_hash($data, 'strict')) { } 0 0 0
elsif ($self->_is_array($data)) { } 0 0 0
1476 {
1477 0 @arg = %$data;
1478 }
1479 elsif( $self->_is_array( $data ) )
1480 {
1481 0 @arg = @$data;
1482 }
1483 }
1484 0 my $constant = $self->constant;
1485 0 ▶ if( scalar( keys( %$constant ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$constant) 0 0 0
1486 {
1487 0 ▶ return( $constant->{sth} ) if( $constant->{sth} && $self->_is_object( $constant->{sth} ) && $constant->{sth}->isa( 'DB::Object::Statement' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement") 0 0 0
Condition0%0/6
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
!ll&&!rl&&r
000
$constant->{"sth"} and $self->_is_object($constant->{"sth"})
!ll&&!rl&&r
000
MC/DC0%0/3
$constant->{"sth"} and $self->_is_object($constant->{"sth"}) and $constant->{"sth"}->isa("DB::Object::Statement")
$constant->{"sth"} $self->_is_object($constant->{"sth"}) $constant->{"sth"}->isa("DB::Object::Statement")
Truth table0%0/4
A and B and C
A= $constant->{"sth"}B= $self->_is_object($constant->{"sth"})C= $constant->{"sth"}->isa("DB::Object::Statement")
ABCresult
0XX0
10X0
1100
1111
1488 }
1489 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
1490 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
1491 return( $self->error( "No database handle could be found." ) );
1492 0 ▶ my $table = $tbl_o->name ||
Condition0%0/2
$tbl_o->name || (return $self->error('No table to update was provided.'))
l!l
00
MC/DC0%0/1
$tbl_o->name || (return $self->error('No table to update was provided.'))
$tbl_o->name
Truth table0%0/2
A
A= $tbl_o->name
Aresult
11
00
1493 return( $self->error( "No table to update was provided." ) );
1494 0 ▶ if( !scalar( @arg ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @arg) 0 0 0
1495 {
1496 0 return( $self->error( "No data to update was provided." ) );
1497 }
1498 0 my $el = $self->elements;
1499 0 ▶ my $elems = $self->format_update( \@arg ) || return( $self->pass_error );
Condition0%0/2
$self->format_update(\@arg) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
$self->format_update(\@arg) || (return $self->pass_error)
$self->format_update(\@arg)
Truth table0%0/2
A
A= $self->format_update(\@arg)
Aresult
11
00
1500 0 ▶ $el->merge( $elems ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$el->merge($elems) or return $self->pass_error 0 0 0
1501 0 my $values = $elems->formats->join( ', ' );
1502 0 my $clauses = $self->_query_components( 'update' );
1503 0 my @query = ( "UPDATE $table SET $values" );
1504 0 ▶ push( @query, @$clauses ) if( scalar( @$clauses ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$clauses 0 0 0
1505 0 my $query = $self->{query} = CORE::join( ' ', @query );
1506 0 ▶ if( !$self->where && !$dbo->allow_bulk_update )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->where or $dbo->allow_bulk_update) 0 0 0
Condition0%0/3
$self->where or $dbo->allow_bulk_update
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->where or $dbo->allow_bulk_update
$self->where $dbo->allow_bulk_update
Truth table0%0/3
A or B
A= $self->whereB= $dbo->allow_bulk_update
ABresult
1X1
011
000
1507 {
1508 0 my( $p, $f, $l ) = caller();
1509 0 my $call_sub = ( caller(1) )[3];
1510 0 return( $self->error( "Refusing to do a bulk update. Called from package $p in file $f at line $l from sub $call_sub. Enable the allow_bulk_update database object property if you want to do so. Original query was: $query" ) );
1511 }
1512 0 $self->query_values( $values );
1513 0 $self->_save_bind();
1514 0 ▶ my $sth = $tbl_o->_cache_this( $self ) || return( $self->pass_error( $tbl_o->error ) );
Condition0%0/2
$tbl_o->_cache_this($self) || (return $self->pass_error($tbl_o->error))
l!l
00
MC/DC0%0/1
$tbl_o->_cache_this($self) || (return $self->pass_error($tbl_o->error))
$tbl_o->_cache_this($self)
Truth table0%0/2
A
A= $tbl_o->_cache_this($self)
Aresult
11
00
1515 # return( $self->error( "Error while preparing query to update table '$table':\n$query" ) );
1516 # $obj->update() to really delete
1517 # $obj->update->as_string() to ONLY get the formatted statement
1518 # wantarray() returns the undefined value in void context, which is typical use of a real update command
1519 # i.e. $obj->update();
1520 0 ▶ if( !defined( wantarray() ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 0 0 0
1521 {
1522 0 ▶ $sth->execute() ||
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute or return $self->error("Error while executing query to update table '${table}':\n$query\n", $sth->error) 0 0 0
1523 return( $self->error( "Error while executing query to update table '$table':\n$query\n", $sth->error ) );
1524 # $sth->finish();
1525 }
1526 # wantarray returns false but not undefined when $obj->update->as_string();
1527 0 return( $sth );
1528 }
1529  
1530 0 ▶sub where { return( shift->_where_having( 'where', 'where', @_ ) ); }
Subroutine where: not called CC=1 SCAR=6.9
Pod documented
1531  
1532 sub _group_order
1533 0 ▶{
Subroutine _group_order: not called CC=40 SCAR=74.0
1534 0 my $self = shift( @_ );
1535 # This is the type, ie 'group', 'order' and used to initiate the DB::Object::Query::Clause
1536 0 ▶ my $type = shift( @_ ) || return( $self->error( "No clause type was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No clause type was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No clause type was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1537 # This is used to store the data in $self such as $self->{ $prop } = $clause;
1538 0 ▶ my $prop = shift( @_ ) || return( $self->error( "No object data property name was provided for clause type '$type'." ) );
Condition0%0/2
shift @_ || (return $self->error("No object data property name was provided for clause type '${type}'."))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error("No object data property name was provided for clause type '${type}'."))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1539 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
1540 0 ▶ my $dbo = $tbl_o->database_object ||
Condition0%0/2
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
l!l
00
MC/DC0%0/1
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
$tbl_o->database_object
Truth table0%0/2
A
A= $tbl_o->database_object
Aresult
11
00
1541 return( $self->error( "No database object is currently set on this table object for table '", $tbl_o->name, "'" ) );
1542 0 my $bind = $tbl_o->use_bind;
1543 0 my $table = $tbl_o->name;
1544 # $self->{ $prop } = $self->new_clause if( !CORE::length( $self->{ $prop } ) && !ref( $self->{ $prop } ) );
1545 0 my $placeholder_re = $dbo->_placeholder_regexp;
1546 0 my $clause;
1547 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1548 {
1549 0 my $fields_ref = $tbl_o->fields;
1550 0 my $fields = join( '|', keys( %$fields_ref ) );
1551 0 my $prefix = $tbl_o->prefix;
1552 0 my $db = $tbl_o->database;
1553 0 my $tables = CORE::join( '|', @{$dbo->tables} );
1554 0 my $multi_db = $tbl_o->prefix_database;
1555 0 ▶ my $data = ( @_ == 1 && ( !$self->_is_object( $_[0] ) || $self->_is_array( $_[0] ) ) && !exists( $fields_ref->{ "$_[0]" } ) )
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && (!$self->_is_object($_[0]) || $self->_is_array($_[0])) && !exists($$fields_ref{"$_[0]"}) ? : 0 0 0
Condition0%0/9
@_ == 1 and !$self->_is_object($_[0]) || $self->_is_array($_[0]) and not exists $$fields_ref{"$_[0]"}
!ll&&!rl&&r
000
@_ == 1 and !$self->_is_object($_[0]) || $self->_is_array($_[0])
!ll&&!rl&&r
000
not $self->_is_object($_[0]) or $self->_is_array($_[0])
l!l&&r!l&&!r
000
MC/DC0%0/4
@_ == 1 and !$self->_is_object($_[0]) || $self->_is_array($_[0]) and not exists $$fields_ref{"$_[0]"}
@_ == 1 not $self->_is_object($_[0]) $self->_is_array($_[0]) not exists $$fields_ref{"$_[0]"}
Truth table0%0/6
A and not(B) or C and not(D)
A= @_ == 1B= not $self->_is_object($_[0])C= $self->_is_array($_[0])D= not exists $$fields_ref{"$_[0]"}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
1556 ? shift( @_ )
1557 : [ @_ ];
1558 0 ▶ if( $self->_is_array( $data ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($data)) { } 0 0 0
elsif ($self->_is_a($data, 'DB::Object::Query::Clause')) { } 0 0 0
1559 {
1560 0 $clause = $self->new_clause(
1561 type => $type,
1562 debug => $self->debug,
1563 );
1564  
1565 0 foreach my $field ( @$data )
1566 {
1567 # Some garbage reached us
1568 0 ▶ next if( !CORE::length( $field // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($field // "") 0 0 0
Condition0%0/2
$field // ""
l!l
00
MC/DC0%0/1
$field // ""
$field
Truth table0%0/2
A
A= $field
Aresult
11
00
1569  
1570 # Special treatment if we are being provided multiple clause to merge with ours
1571 0 ▶ if( $self->_is_a( $field => 'DB::Object::Query::Clause' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($field, "DB::Object::Query::Clause")) 0 0 0
1572 {
1573 0 ▶ if( !$self->{ $prop } )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{$prop}) { } 0 0 0
1574 {
1575 0 $self->{ $prop } = $clause;
1576 }
1577 else
1578 {
1579 0 $clause = $self->{ $prop };
1580 }
1581 0 $clause->merge( $field );
1582 0 next;
1583 }
1584  
1585 # Transform a simple 'field' into a field object
1586 0 ▶ $field = $tbl_o->fo->$field if( CORE::exists( $fields_ref->{ $field } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $fields_ref->{$field} 0 0 0
1587 # my $elem = $self->new_element( field => $field );
1588 0 my $elem;
1589 0 ▶ if( $self->_is_a( $field => 'DB::Object::Fields::Field' ) )
Branch: 5 branches
BranchTrueFalseTotal
if ($self->_is_a($field, 'DB::Object::Fields::Field')) { } 0 0 0
elsif ($self->_is_a($field, 'DB::Object::Fields::Unknown')) { } 0 0 0
elsif (ref $field eq 'SCALAR') { } 0 0 0
elsif ($field =~ /($placeholder_re)/) { } 0 0 0
elsif ($field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/ or not $bind) { } 0 0 0
1590 {
1591 0 $elem = $self->new_element(
1592 field => $field,
1593 # Not necessary; this is already the default value
1594 # generic => '?',
1595 type => '',
1596 value => $field,
1597 );
1598 }
1599 elsif( $self->_is_a( $field => 'DB::Object::Fields::Unknown' ) )
1600 {
1601 # warn( "Unnown field provided with field object for field ", $field->field ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
1602 # next;
1603 0 return( $self->error( "Unnown field provided with field object for field '", $field->field, "'" ) );
1604 }
1605 # i.e. GROUP BY width => GROUP BY table.width
1606 elsif( ref( $field ) eq 'SCALAR' )
1607 {
1608 0 $elem = $self->new_element(
1609 field => $field,
1610 type => '',
1611 value => $$field,
1612 );
1613 }
1614 elsif( $field =~ /($placeholder_re)/ )
1615 {
1616 0 $elem = $self->new_element(
1617 field => $field,
1618 placeholder => $1,
1619 type => '',
1620 value => $field,
1621 );
1622 }
1623 ▶ elsif( $field =~ /\b(?:$fields)\b/ ||
Condition0%0/6
$field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/ or not $bind
l!l&&r!l&&!r
000
$field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/
l!l&&r!l&&!r
000
MC/DC0%0/3
$field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/ or not $bind
$field =~ /\b(?:$fields)\b/ $field =~ /\w\([^\)]*\)/ not $bind
Truth table0%0/4
A or B or not(C)
A= $field =~ /\b(?:$fields)\b/B= $field =~ /\w\([^\)]*\)/C= not $bind
ABCresult
1XX1
01X1
0011
0000
1624 $field =~ /\w\([^\)]*\)/ ||
1625 !$bind )
1626 {
1627 0 ▶ $field =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
1628 (?<![\.\"])\b($fields)\b(\s*)?(?!\.)
1629 }
1630 {
1631 0 my( $ok, $spc ) = ( $1, $2 );
1632 0 "${prefix}.${ok}${spc}";
1633 }gex if( $prefix );
1634 0 ▶ $field =~ s/(?<!\.)($tables)(?:\.)/$db\.$1\./g if( $multi_db );
Branch: 1 branch
BranchTrueFalseTotal
if $multi_db 0 0 0
1635 0 $elem = $self->new_element(
1636 field => $field,
1637 type => '',
1638 value => $field,
1639 );
1640 }
1641 else
1642 {
1643 0 $elem = $self->new_element(
1644 field => $field,
1645 # Not necessary; this is already the default value
1646 # generic => '?',
1647 type => '',
1648 value => $field,
1649 );
1650 }
1651 0 $clause->push( $elem );
1652 }
1653 0 $clause->value( $clause->values->join( ', ' ) );
1654 0 $clause->generic( $clause->generics->join( ', ' ) );
1655 }
1656 # Merging our clause with a new one
1657 elsif( $self->_is_a( $data => 'DB::Object::Query::Clause' ) )
1658 {
1659 $clause = $self->{ $prop }
1660 0 ▶ ? $self->{ $prop }
Branch: 1 branch
BranchTrueFalseTotal
$self->{$prop} ? : 0 0 0
1661 : $self->new_clause( type => $type );
1662 0 $clause->merge( $data );
1663 }
1664 else
1665 {
1666 0 $clause = $self->new_clause({
1667 value => $data,
1668 type => $type,
1669 });
1670 0 my $elem;
1671 0 ▶ if( ref( $data ) eq 'SCALAR' )
Branch: 4 branches
BranchTrueFalseTotal
if (ref $data eq 'SCALAR') { } 0 0 0
elsif ($data =~ /($placeholder_re)/) { } 0 0 0
elsif ($data =~ /\b(?:$fields)\b/ or $data =~ /\w\([^\)]*\)/ or not $bind) { } 0 0 0
elsif ($bind) { } 0 0 0
1672 {
1673 0 $elem = $self->new_element(
1674 field => $data,
1675 type => '',
1676 value => $$data,
1677 );
1678 0 $clause->push( $elem );
1679 }
1680 elsif( $data =~ /($placeholder_re)/ )
1681 {
1682 0 $elem = $self->new_element(
1683 field => $data,
1684 placeholder => $1,
1685 type => '',
1686 value => $data,
1687 );
1688 0 $clause->push( $elem );
1689 }
1690 ▶ elsif( $data =~ /\b(?:$fields)\b/ ||
Condition0%0/6
$data =~ /\b(?:$fields)\b/ or $data =~ /\w\([^\)]*\)/ or not $bind
l!l&&r!l&&!r
000
$data =~ /\b(?:$fields)\b/ or $data =~ /\w\([^\)]*\)/
l!l&&r!l&&!r
000
MC/DC0%0/3
$data =~ /\b(?:$fields)\b/ or $data =~ /\w\([^\)]*\)/ or not $bind
$data =~ /\b(?:$fields)\b/ $data =~ /\w\([^\)]*\)/ not $bind
Truth table0%0/4
A or B or not(C)
A= $data =~ /\b(?:$fields)\b/B= $data =~ /\w\([^\)]*\)/C= not $bind
ABCresult
1XX1
01X1
0011
0000
1691 $data =~ /\w\([^\)]*\)/ ||
1692 !$bind )
1693 {
1694 0 ▶ $data =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
1695 (?<![\.\"])\b($fields)\b(\s*)?(?!\.)
1696 }
1697 {
1698 0 my( $ok, $spc ) = ( $1, $2 );
1699 0 "${prefix}.${ok}${spc}";
1700 }gex if( $prefix );
1701 0 ▶ $data =~ s/(?<!\.)($tables)(?:\.)/$db\.$1\./g if( $multi_db );
Branch: 1 branch
BranchTrueFalseTotal
if $multi_db 0 0 0
1702 0 $elem = $self->new_element(
1703 field => $data,
1704 type => '',
1705 value => $data,
1706 );
1707 0 $clause->push( $elem );
1708 }
1709 elsif( $bind )
1710 {
1711 # $self->_value2bind( \$data, $ref );
1712 0 my $elems = $self->_value2bind( \$data );
1713 # $clause->bind->values( $ref );
1714 # $clause->bind->types( ( '' ) x scalar( @$ref ) );
1715 0 ▶ $clause->push( $elems->elements->list ) if( $elems->elements->length );
Branch: 1 branch
BranchTrueFalseTotal
if $elems->elements->length 0 0 0
1716 }
1717 else
1718 {
1719 0 $elem = $self->new_element(
1720 field => $data,
1721 # Not necessary; this is already the default value
1722 # generic => '?',
1723 type => '',
1724 value => $data,
1725 );
1726 0 $clause->push( $elem );
1727 }
1728 }
1729 0 ▶ $self->{ $prop } = $clause if( $clause->elements->length );
Branch: 1 branch
BranchTrueFalseTotal
if $clause->elements->length 0 0 0
1730 }
1731 else
1732 {
1733 0 $clause = $self->{ $prop };
1734 }
1735  
1736 0 ▶ if( !$clause && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $clause and want("OBJECT")) 0 0 0
Condition0%0/3
not $clause and want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not $clause and want("OBJECT")
not $clause want("OBJECT")
Truth table0%0/3
not(A) and B
A= not $clauseB= want("OBJECT")
ABresult
0X0
100
111
1737 {
1738 0 return( $self->new_null( type => 'object' ) );
1739 }
1740 0 return( $clause );
1741 }
1742  
1743 # Each driver can call on this private method like sub having { return( shift->_having( @_ ) ); }
1744 # to avoid recreating it themselve
1745 sub _having
1746 0 ▶{
Subroutine _having: not called CC=21 SCAR=61.4
1747 0 my $self = shift( @_ );
1748 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
1749 0 my $bind = $tbl_o->use_bind;
1750 0 my $table = $tbl_o->name;
1751 0 my $prefix = $tbl_o->prefix;
1752 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
1753 return( $self->error( "No database handle could be found." ) );
1754 0 my $placeholder_re = $tbl_o->database_object->_placeholder_regexp;
1755 0 my $clause;
1756 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1757 {
1758 0 ▶ my $data = ( @_ == 1 ) ? shift( @_ ) : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
1759 0 ▶ if( $self->_is_array( $data ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($data)) { } 0 0 0
1760 {
1761 0 my $fields_ref = $tbl_o->fields;
1762 0 my $fields = join( '|', keys( %$fields_ref ) );
1763 0 my $db = $tbl_o->database;
1764 0 my $tables = CORE::join( '|', @{$self->{tables}->{ $db }} );
1765 0 my $multi_db = $tbl_o->prefix_database;
1766 0 my @values = ();
1767 0 my @clause = ();
1768 0 my @types = ();
1769 0 foreach my $field ( @$data )
1770 {
1771 # In case we received some garbage
1772 0 ▶ next if( !CORE::length( $field ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $field 0 0 0
1773  
1774 # Special treatment if we are being provided multiple clause to merge with ours
1775 0 ▶ if( $self->_is_a( $field => 'DB::Object::Query::Clause' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($field, "DB::Object::Query::Clause")) 0 0 0
1776 {
1777 0 ▶ if( !$self->{having} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'having'}) { } 0 0 0
1778 {
1779 0 $self->{having} = $self->new_clause( type => 'having' );
1780 }
1781 else
1782 {
1783 0 $clause = $self->{having};
1784 }
1785 0 $clause->merge( $field );
1786 0 next;
1787 }
1788  
1789 # i.e. HAVING width => HAVING table.width
1790 0 ▶ if( ref( $field ) eq 'SCALAR' )
Branch: 4 branches
BranchTrueFalseTotal
if (ref $field eq 'SCALAR') { } 0 0 0
elsif ($field =~ /($placeholder_re)/) { } 0 0 0
elsif ($field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/ or not $bind) { } 0 0 0
elsif ($bind) { } 0 0 0
1791 {
1792 0 push( @clause, $self->new_clause({
1793 value => $$field,
1794 type => 'having',
1795 }) );
1796 }
1797 elsif( $field =~ /($placeholder_re)/ )
1798 {
1799 0 my $plh = $1;
1800 0 my $cl = $self->new_clause(
1801 value => $field,
1802 type => 'having',
1803 );
1804  
1805 0 my $elem = $self->new_element(
1806 format => $field,
1807 placeholder => $plh,
1808 );
1809 0 $cl->push( $elem );
1810 0 CORE::push( @clause, $cl );
1811 }
1812 ▶ elsif( $field =~ /\b(?:$fields)\b/ ||
Condition0%0/6
$field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/ or not $bind
l!l&&r!l&&!r
000
$field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/
l!l&&r!l&&!r
000
MC/DC0%0/3
$field =~ /\b(?:$fields)\b/ or $field =~ /\w\([^\)]*\)/ or not $bind
$field =~ /\b(?:$fields)\b/ $field =~ /\w\([^\)]*\)/ not $bind
Truth table0%0/4
A or B or not(C)
A= $field =~ /\b(?:$fields)\b/B= $field =~ /\w\([^\)]*\)/C= not $bind
ABCresult
1XX1
01X1
0011
0000
1813 $field =~ /\w\([^\)]*\)/ ||
1814 !$bind )
1815 {
1816 0 ▶ $field =~ s{
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
1817 (?<![\.\"])\b($fields)\b(\s*)?(?!\.)
1818 }
1819 {
1820 0 my( $ok, $spc ) = ( $1, $2 );
1821 0 "${prefix}.${ok}${spc}";
1822 }gex if( $prefix );
1823 0 ▶ $field =~ s/(?<!\.)($tables)(?:\.)/$db\.$1\./g if( $multi_db );
Branch: 1 branch
BranchTrueFalseTotal
if $multi_db 0 0 0
1824 0 push( @clause, $self->new_clause({
1825 value => $field,
1826 type => 'having',
1827 }) );
1828 }
1829 elsif( $bind )
1830 {
1831 0 my $elem = $self->new_element(
1832 placeholder => '?',
1833 value => $field,
1834 );
1835 0 my $cl = $self->new_clause(
1836 value => '?',
1837 type => 'having',
1838 );
1839 0 $cl->push( $elem );
1840 0 CORE::push( @clause, $cl );
1841 }
1842 else
1843 {
1844 0 push( @clause, $self->new_clause({
1845 value => $field,
1846 type => 'having',
1847 }) );
1848 }
1849 }
1850 0 $clause = $self->new_clause( type => 'having' )->merge( $dbo->AND( @clause ) );
1851 # $clause->bind->values( @values ) if( $bind );
1852 # $clause->bind->types( @types ) if( $bind );
1853 }
1854 else
1855 {
1856 # my $ref = [];
1857 # if( $bind )
1858 # {
1859 # $self->_value2bind( \$clause, $ref );
1860 # $clause->bind->values( @$ref ) if( $bind && scalar( @$ref ) );
1861 # $clause->bind->types( ( '' ) x scalar( @$ref ) ) if( $bind );
1862 # }
1863 0 my $elems = $self->_value2bind( \$data );
1864 0 $clause = $self->new_clause(
1865 value => $data,
1866 type => 'having',
1867 );
1868 0 ▶ $clause->push( $elems->elements->list ) if( $elems->elements->length );
Branch: 1 branch
BranchTrueFalseTotal
if $elems->elements->length 0 0 0
1869 }
1870 0 $self->{having} = $clause;
1871 }
1872 else
1873 {
1874 0 $clause = $self->{having};
1875 }
1876  
1877 0 ▶ if( !$clause && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $clause and want("OBJECT")) 0 0 0
Condition0%0/3
not $clause and want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not $clause and want("OBJECT")
not $clause want("OBJECT")
Truth table0%0/3
not(A) and B
A= not $clauseB= want("OBJECT")
ABresult
0X0
100
111
1878 {
1879 0 return( $self->new_null( type => 'object' ) );
1880 }
1881 0 return( $clause );
1882 }
1883  
1884 sub _initiate_clause_object
1885 0 ▶{
Subroutine _initiate_clause_object: not called CC=1 SCAR=6.9
1886 0 my $self = shift( @_ );
1887 0 return( DB::Object::Query::Clause->new( @_ ) );
1888 }
1889  
1890 0 ▶sub _limit { return( shift->_set_get_object( 'limit', 'DB::Object::Query::Clause', @_ ) ); }
Subroutine _limit: not called CC=1 SCAR=6.9
1891  
1892 sub _process_limit
1893 0 ▶{
Subroutine _process_limit: not called CC=25 SCAR=64.8
1894 0 my $self = shift( @_ );
1895 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
1896 0 my $bind = $tbl_o->use_bind;
1897 0 my $placeholder_re = $tbl_o->database_object->_placeholder_regexp;
1898 0 my $limit;
1899  
1900 # $self->limit can be used to set the offset and limit, but can also be used to
1901 # pass limit clause object to be merged, so here we check it, and if found, we do not go further.
1902 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
1903 {
1904 # First check if what we are being provided is not clause objects
1905 0 my @clauses = ();
1906 0 ▶ for( my $i = 0; $i < scalar( @_ ); $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @_) 0 0 0
1907 {
1908 # Special treatment if we are being provided multiple clause to merge with ours
1909 0 ▶ if( $self->_is_a( $_[$i] => 'DB::Object::Query::Clause' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($_[$i], "DB::Object::Query::Clause")) 0 0 0
1910 {
1911 0 push( @clauses, $_[$i] );
1912 0 splice( @_, $i, 1 );
1913 0 $i--;
1914 }
1915 }
1916  
1917 0 ▶ if( scalar( @clauses ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @clauses) 0 0 0
1918 {
1919 0 ▶ if( !$self->{limit} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'limit'}) { } 0 0 0
1920 {
1921 0 $self->{limit} = $limit = $self->new_clause( type => 'limit' );
1922 }
1923 else
1924 {
1925 0 $limit = $self->{limit};
1926 }
1927 0 $limit->merge( @clauses );
1928 0 return( $limit );
1929 }
1930  
1931 0 my( $start, $end );
1932 0 ▶ if( @_ == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
1933 {
1934 0 $end = shift( @_ );
1935 }
1936 else
1937 {
1938 0 ( $start, $end ) = splice( @_, 0, 2 );
1939 }
1940 0 my @binded = ();
1941 0 my @list = ();
1942 0 my @types = ();
1943 0 my @generic = ();
1944 0 $limit = $self->new_clause( type => 'limit' );
1945 0 foreach my $value ( $start, $end )
1946 {
1947 0 ▶ next if( !CORE::length( $value // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length($value // "") 0 0 0
Condition0%0/2
$value // ""
l!l
00
MC/DC0%0/1
$value // ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
1948 0 my $elem = $self->new_element;
1949 # This is a raw parameter - being a ref to a SCALAR means we must not modify it
1950 0 ▶ if( ref( $value ) eq 'SCALAR' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'SCALAR') { } 0 0 0
elsif ($value =~ /($placeholder_re)/) { } 0 0 0
1951 {
1952 0 push( @list, $$value );
1953 }
1954 # A value to be a place holder - forward it
1955 # elsif( $value eq '?' )
1956 elsif( $value =~ /($placeholder_re)/ )
1957 {
1958 # Maybe ? or $1, or ?1
1959 0 push( @list, $1 );
1960 0 push( @generic, $1 );
1961 0 $elem->placeholder( $1 );
1962 # push( @binded, $value );
1963 # push( @types, '' );
1964 0 $elem->value( $value );
1965 }
1966 # Normal processing
1967 else
1968 {
1969 0 push( @list, $value );
1970 0 push( @generic, '?' );
1971 # push( @binded, $value );
1972 # push( @types, '' );
1973 0 $elem->placeholder( '?' );
1974 0 $elem->value( $value );
1975 }
1976 0 $limit->push( $elem );
1977 }
1978 # $limit = $self->{limit} = [ @list ];
1979 0 ▶ $limit->value( CORE::join( ', ', @list ) ) if( scalar( @list ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @list 0 0 0
1980 0 ▶ $limit->generic( CORE::join( ', ', @generic ) ) if( scalar( @generic ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @generic 0 0 0
1981 # $limit->bind->values( \@binded );
1982 # $limit->bind->types( \@types );
1983 0 ▶ if( scalar( @list ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @list) 0 0 0
1984 {
1985 0 ▶ if( scalar( @list ) > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @list > 1) { } 0 0 0
1986 {
1987 0 ▶ $limit->metadata->offset( $list[0] ) if( CORE::length( $list[0] // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if length($list[0] // "") 0 0 0
Condition0%0/2
$list[0] // ""
l!l
00
MC/DC0%0/1
$list[0] // ""
$list[0]
Truth table0%0/2
A
A= $list[0]
Aresult
11
00
1988 0 ▶ $limit->metadata->limit( $list[1] ) if( CORE::length( $list[1] // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if length($list[1] // "") 0 0 0
Condition0%0/2
$list[1] // ""
l!l
00
MC/DC0%0/1
$list[1] // ""
$list[1]
Truth table0%0/2
A
A= $list[1]
Aresult
11
00
1989 }
1990 else
1991 {
1992 0 $limit->metadata->offset( '' );
1993 0 ▶ $limit->metadata->limit( $list[0] ) if( CORE::length( $list[0] // '' ) );
Branch: 1 branch
BranchTrueFalseTotal
if length($list[0] // "") 0 0 0
Condition0%0/2
$list[0] // ""
l!l
00
MC/DC0%0/1
$list[0] // ""
$list[0]
Truth table0%0/2
A
A= $list[0]
Aresult
11
00
1994 }
1995 }
1996 0 $self->{limit} = $limit;
1997 }
1998 else
1999 {
2000 0 $limit = $self->{limit};
2001 }
2002  
2003 0 ▶ if( !$limit && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $limit and want("OBJECT")) 0 0 0
Condition0%0/3
not $limit and want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not $limit and want("OBJECT")
not $limit want("OBJECT")
Truth table0%0/3
not(A) and B
A= not $limitB= want("OBJECT")
ABresult
0X0
100
111
2004 {
2005 0 return( $self->new_null( type => 'object' ) );
2006 }
2007 0 return( $limit );
2008 }
2009  
2010 sub _query_components
2011 0 ▶{
Subroutine _query_components: not called CC=17 SCAR=57.2
2012 0 my $self = shift( @_ );
2013 0 ▶ my $type = lc( shift( @_ ) ) || $self->_query_type() || return( $self->error( "You must specify a query type: select, insert, update or delete" ) );
Condition0%0/5
lc shift @_ || $self->_query_type || (return $self->error('You must specify a query type: select, insert, update or delete'))
l!l
00
lc shift @_ or $self->_query_type
l!l&&r!l&&!r
000
MC/DC0%0/2
lc shift @_ || $self->_query_type || (return $self->error('You must specify a query type: select, insert, update or delete'))
lc shift @_ $self->_query_type
Truth table0%0/3
A or B
A= lc shift @_B= $self->_query_type
ABresult
1X1
011
000
2014 0 my( $where, $group, $sort, $order, $limit );
2015 0 $where = $self->where;
2016 0 ▶ if( $type eq 'select' )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "select") 0 0 0
2017 {
2018 0 $group = $self->group;
2019 0 ▶ $sort = $self->reverse ? 'DESC' : $self->sort ? 'ASC' : '';
Branch: 2 branches
BranchTrueFalseTotal
$self->reverse ? : 0 0 0
$self->sort ? : 0 0 0
2020 0 $order = $self->order;
2021 }
2022 0 $limit = $self->limit;
2023 0 my @query = ();
2024 0 ▶ push( @query, "WHERE $where" ) if( $where && $type ne 'insert' );
Branch: 1 branch
BranchTrueFalseTotal
if $where and $type ne "insert" 0 0 0
Condition0%0/3
$where and $type ne "insert"
!ll&&!rl&&r
000
MC/DC0%0/2
$where and $type ne "insert"
$where $type ne "insert"
Truth table0%0/3
A and B
A= $whereB= $type ne "insert"
ABresult
0X0
100
111
2025 0 ▶ push( @query, "GROUP BY $group" ) if( $group && $type eq 'select' );
Branch: 1 branch
BranchTrueFalseTotal
if $group and $type eq "select" 0 0 0
Condition0%0/3
$group and $type eq "select"
!ll&&!rl&&r
000
MC/DC0%0/2
$group and $type eq "select"
$group $type eq "select"
Truth table0%0/3
A and B
A= $groupB= $type eq "select"
ABresult
0X0
100
111
2026 0 ▶ push( @query, "ORDER BY $order" ) if( $order && $type eq 'select' );
Branch: 1 branch
BranchTrueFalseTotal
if $order and $type eq "select" 0 0 0
Condition0%0/3
$order and $type eq "select"
!ll&&!rl&&r
000
MC/DC0%0/2
$order and $type eq "select"
$order $type eq "select"
Truth table0%0/3
A and B
A= $orderB= $type eq "select"
ABresult
0X0
100
111
2027 0 ▶ push( @query, $sort ) if( $sort && $order && $type eq 'select' );
Branch: 1 branch
BranchTrueFalseTotal
if $sort and $order and $type eq "select" 0 0 0
Condition0%0/6
$sort and $order and $type eq "select"
!ll&&!rl&&r
000
$sort and $order
!ll&&!rl&&r
000
MC/DC0%0/3
$sort and $order and $type eq "select"
$sort $order $type eq "select"
Truth table0%0/4
A and B and C
A= $sortB= $orderC= $type eq "select"
ABCresult
0XX0
10X0
1100
1111
2028 0 ▶ push( @query, "LIMIT $limit" ) if( $limit && $type ne 'insert' );
Branch: 1 branch
BranchTrueFalseTotal
if $limit and $type ne "insert" 0 0 0
Condition0%0/3
$limit and $type ne "insert"
!ll&&!rl&&r
000
MC/DC0%0/2
$limit and $type ne "insert"
$limit $type ne "insert"
Truth table0%0/3
A and B
A= $limitB= $type ne "insert"
ABresult
0X0
100
111
2029 0 return( \@query );
2030 }
2031  
2032 sub _query_type
2033 0 ▶{
Subroutine _query_type: not called CC=3 SCAR=24.8
2034 0 my $self = shift( @_ );
2035 0 ▶ if( $self->{query} && length( $self->{query} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"query"} and length $self->{"query"}) 0 0 0
Condition0%0/3
$self->{"query"} and length $self->{"query"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"query"} and length $self->{"query"}
$self->{"query"} length $self->{"query"}
Truth table0%0/3
A and B
A= $self->{"query"}B= length $self->{"query"}
ABresult
0X0
100
111
2036 {
2037 0 return( lc( ( $self->{query} =~ /^[[:blank:]]*(ALTER|CREATE|DROP|GRANT|LISTEN|NOTIFY|INSERT|UPDATE|DELETE|SELECT|TRUNCATE)\b/i )[0] ) )
2038 }
2039 0 return;
2040 }
2041  
2042 sub _save_bind
2043 0 ▶{
Subroutine _save_bind: not called CC=12 SCAR=50.5
2044 0 my $self = shift( @_ );
2045 0 my $type = shift( @_ );
2046 0 ▶ if( !$type )
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 0 0 0
2047 {
2048 0 my( $pkg, $file, $line, $sub ) = caller( 1 );
2049 0 $sub =~ s/(.*):://;
2050 0 $type = $sub;
2051 }
2052 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
2053 0 my $bind = $tbl_o->use_bind;
2054 0 my $where = $self->where;
2055 0 my $group = $self->group;
2056 0 my $order = $self->order;
2057 0 my $limit = $self->limit;
2058 # This is used so upon execute, the saved binded parameters get sent to the DBI::execute method
2059 0 ▶ if( $bind )
Branch: 1 branch
BranchTrueFalseTotal
if ($bind) 0 0 0
2060 {
2061 # Build a fresh Elements object and assign it directly, rather than calling
2062 # $self->elements (which may return a copy) and pushing onto it. This ensures
2063 # the stored reference is always up-to-date and never accumulates across calls.
2064 0 my $elems = $self->new_elements;
2065 0 ▶ $elems->push( $where->elements ) if( $where->length && !$where->elements->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $where->length and not $where->elements->is_empty 0 0 0
Condition0%0/3
$where->length and not $where->elements->is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$where->length and not $where->elements->is_empty
$where->length not $where->elements->is_empty
Truth table0%0/3
A and not(B)
A= $where->lengthB= not $where->elements->is_empty
ABresult
0X0
100
111
2066 0 ▶ $elems->push( $group->elements ) if( $group->length && !$group->elements->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $group->length and not $group->elements->is_empty 0 0 0
Condition0%0/3
$group->length and not $group->elements->is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$group->length and not $group->elements->is_empty
$group->length not $group->elements->is_empty
Truth table0%0/3
A and not(B)
A= $group->lengthB= not $group->elements->is_empty
ABresult
0X0
100
111
2067 0 ▶ $elems->push( $order->elements ) if( $order->length && !$order->elements->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $order->length and not $order->elements->is_empty 0 0 0
Condition0%0/3
$order->length and not $order->elements->is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$order->length and not $order->elements->is_empty
$order->length not $order->elements->is_empty
Truth table0%0/3
A and not(B)
A= $order->lengthB= not $order->elements->is_empty
ABresult
0X0
100
111
2068 0 ▶ $elems->push( $limit->elements ) if( $limit->length && !$limit->elements->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
if $limit->length and not $limit->elements->is_empty 0 0 0
Condition0%0/3
$limit->length and not $limit->elements->is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$limit->length and not $limit->elements->is_empty
$limit->length not $limit->elements->is_empty
Truth table0%0/3
A and not(B)
A= $limit->lengthB= not $limit->elements->is_empty
ABresult
0X0
100
111
2069 0 $self->{elements} = $elems;
2070  
2071 }
2072 0 return( $self );
2073 }
2074  
2075 sub _value2bind
2076 0 ▶{
Subroutine _value2bind: not called CC=12 SCAR=50.5
2077 0 my $self = shift( @_ );
2078 # If we are not suppose to bind any values, there is no point to go on.
2079 # return(1) if( !$self->{ 'bind' } );
2080 0 my $str = shift( @_ );
2081 0 my $ref = shift( @_ );
2082 0 ▶ my $tbl_o = $self->{table_object} || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->{'table_object'} || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->{'table_object'} || (return $self->error('No table object is set.'))
$self->{'table_object'}
Truth table0%0/2
A
A= $self->{'table_object'}
Aresult
11
00
2083 0 ▶ my $dbo = $tbl_o->database_object ||
Condition0%0/2
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
l!l
00
MC/DC0%0/1
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
$tbl_o->database_object
Truth table0%0/2
A
A= $tbl_o->database_object
Aresult
11
00
2084 return( $self->error( "No database object is currently set on this table object for table '", $tbl_o->name, "'" ) );
2085 0 my $table = $tbl_o->name;
2086 0 my $bind = $tbl_o->use_bind;
2087 0 my $db = $tbl_o->database;
2088 0 my $prefix = $tbl_o->prefix;
2089 0 my $fields_ref = $tbl_o->fields;
2090 0 my $fields = CORE::join( '|', keys( %$fields_ref ) );
2091 0 my $tables = CORE::join( '|', @{$dbo->tables} );
2092 0 my $multi_db = $tbl_o->param( 'multi_db' );
2093 0 my @binded = ();
2094 0 my $placeholder_re = $dbo->_placeholder_regexp;
2095 0 my $elems = $self->new_elements;
2096 0 $$str =~ s
2097 {
2098 (([\w\_]+)(?:\.))?\b([a-zA-Z\_]+)\b\s*(=|\!=|LIKE)\s*['"]([^'"]+)['"]
2099 }
2100 {
2101 do
2102 0 {
2103 0 my( $this_table, $field, $equity, $value ) = ( $2, $3, $4, $5 );
2104 # Add to the list of value to bind on execute() only if this is not already a place holder
2105 # push( @binded, $value ) if( $bind && $value ne '?' );
2106 0 ▶ $this_table ||= $table;
Condition0%0/3
$this_table ||= $table
l!l&&r!l&&!r
000
MC/DC0%0/2
$this_table ||= $table
$this_table $table
Truth table0%0/3
A ||= B
A= $this_tableB= $table
ABresult
1X1
011
000
2107 0 $this_table .= '.';
2108 # $bind ? "${this_table}${field}=?" : "${this_table}${field}='$value'";
2109 0 my $elem = $self->new_element( field => "${this_table}${field}" );
2110 0 my $result;
2111 0 ▶ if( $value !~ /[\r\n]+/ &&
Branch: 2 branches
BranchTrueFalseTotal
if (not $value =~ /[\r\n]+/ and $value =~ /\b(?:$fields)\b/ || $value =~ /\w\([^\)]*\)/ || $value =~ /$placeholder_re/) { } 0 0 0
elsif ($bind) { } 0 0 0
Condition0%0/9
not $value =~ /[\r\n]+/ and $value =~ /\b(?:$fields)\b/ || $value =~ /\w\([^\)]*\)/ || $value =~ /$placeholder_re/
!ll&&!rl&&r
000
$value =~ /\b(?:$fields)\b/ or $value =~ /\w\([^\)]*\)/ or $value =~ /$placeholder_re/
l!l&&r!l&&!r
000
$value =~ /\b(?:$fields)\b/ or $value =~ /\w\([^\)]*\)/
l!l&&r!l&&!r
000
MC/DC0%0/4
not $value =~ /[\r\n]+/ and $value =~ /\b(?:$fields)\b/ || $value =~ /\w\([^\)]*\)/ || $value =~ /$placeholder_re/
not $value =~ /[\r\n]+/ $value =~ /\b(?:$fields)\b/ $value =~ /\w\([^\)]*\)/ $value =~ /$placeholder_re/
Truth table0%0/5
not(A) and B or C or D
A= not $value =~ /[\r\n]+/B= $value =~ /\b(?:$fields)\b/C= $value =~ /\w\([^\)]*\)/D= $value =~ /$placeholder_re/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
2112 ( $value =~ /\b(?:$fields)\b/ ||
2113 $value =~ /\w\([^\)]*\)/ ||
2114 $value =~ /$placeholder_re/ ) )
2115 {
2116 0 ▶ if( $value =~ /($placeholder_re)/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /($placeholder_re)/) 0 0 0
2117 {
2118 0 $elem->placeholder( $1 );
2119 0 $elem->format( $value );
2120 }
2121 0 $result = "${this_table}${field} $equity $value";
2122 0 $elems->push( $elem );
2123 }
2124 elsif( $bind )
2125 {
2126 # push( @binded, $value );
2127 0 $result = "${this_table}${field} $equity ?";
2128 0 $elem->placeholder( '?' );
2129 0 $elem->value( $value );
2130 0 $elems->push( $elem );
2131 }
2132 else
2133 {
2134 0 $result = "${this_table}${field} $equity '$value'";
2135 }
2136 0 $result;
2137 };
2138 }geix;
2139 0 ▶ $$str =~ s
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
2140 {
2141 (?<![\.\"])\b($fields)\b(\s*)?(?!\.)
2142 }
2143 {
2144 0 my( $ok, $spc ) = ( $1, $2 );
2145 0 "$prefix.$ok$spc";
2146 }gex if( $prefix );
2147 0 ▶ $$str =~ s/(?<!\.)($tables)(?:\.)/$db\.$1\./g if( $multi_db );
Branch: 1 branch
BranchTrueFalseTotal
if $multi_db 0 0 0
2148 # push( @$ref, @binded ) if( @binded );
2149 # return(1);
2150 0 return( $elems );
2151 }
2152  
2153 sub _where_having
2154 0 ▶{
Subroutine _where_having: not called CC=9 SCAR=45.0
2155 0 my $self = shift( @_ );
2156 # This is the type, ie 'group', 'order' and used to initiate the DB::Object::Query::Clause
2157 0 ▶ my $type = shift( @_ ) || return( $self->error( "No clause type was provided." ) );
Condition0%0/2
shift @_ || (return $self->error('No clause type was provided.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No clause type was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2158 # This is used to store the data in $self such as $self->{ $prop } = $clause;
2159 0 ▶ my $prop = shift( @_ ) || return( $self->error( "No object data property name was provided for clause type '$type'." ) );
Condition0%0/2
shift @_ || (return $self->error("No object data property name was provided for clause type '${type}'."))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error("No object data property name was provided for clause type '${type}'."))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
2160 0 ▶ my $tbl_o = $self->table_object || return( $self->error( "No table object is set." ) );
Condition0%0/2
$self->table_object || (return $self->error('No table object is set.'))
l!l
00
MC/DC0%0/1
$self->table_object || (return $self->error('No table object is set.'))
$self->table_object
Truth table0%0/2
A
A= $self->table_object
Aresult
11
00
2161 0 ▶ my $dbo = $tbl_o->database_object ||
Condition0%0/2
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
l!l
00
MC/DC0%0/1
$tbl_o->database_object || (return $self->error(q[No database object is currently set on this table object for table '], $tbl_o->name, q[']))
$tbl_o->database_object
Truth table0%0/2
A
A= $tbl_o->database_object
Aresult
11
00
2162 return( $self->error( "No database object is currently set on this table object for table '", $tbl_o->name, "'" ) );
2163 0 my $base_class = $tbl_o->base_class;
2164 0 my $bind = $tbl_o->use_bind;
2165 # $self->{ $prop } = $self->new_clause if( !CORE::length( $self->{ $prop } ) || !$self->_is_object( $self->{ $prop } ) );
2166 # my $where = $self->{ $prop };
2167 0 my $where;
2168 0 my $placeholder_re = $dbo->_placeholder_regexp;
2169 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
2170 {
2171 0 my @params = @_;
2172 # This will change the belonging of the object $self to the class DB::Object::Prepare so method
2173 # such as select, insert, update, delete know there are some conditionning clause to be added
2174 0 my $table = $tbl_o->name;
2175 0 my $db = $tbl_o->database;
2176 0 my $multi_db = $tbl_o->prefix_database;
2177 0 my $prefix = $tbl_o->prefix;
2178 0 my $fields_ref = $tbl_o->fields;
2179 0 my $fields = CORE::join( '|', keys( %$fields_ref ) );
2180 0 my $fields_type = $tbl_o->types;
2181  
2182 0 my $process_where_condition;
2183 $process_where_condition = sub
2184 0 ▶ {
Subroutine __ANON__: not called CC=81 SCAR=88.0
2185 # my @parameters = @_;
2186 # my $data = shift( @_ ) if( @_ % 2 && !( scalar( @_ ) == 1 && $self->_is_object( $_[0] ) ) );
2187 0 my $data;
2188 0 ▶ unless( scalar( @_ ) == 1 && $self->_is_object( $_[0] ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @_ == 1 and $self->_is_object($_[0])) 0 0 0
Condition0%0/3
scalar @_ == 1 and $self->_is_object($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and $self->_is_object($_[0])
scalar @_ == 1 $self->_is_object($_[0])
Truth table0%0/3
A and B
A= scalar @_ == 1B= $self->_is_object($_[0])
ABresult
0X0
100
111
2189 {
2190 0 ▶ $data = shift( @_ ) if( ( @_ % 2 ) && !$self->_is_object( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 and not $self->_is_object($_[0]) 0 0 0
Condition0%0/3
@_ % 2 and not $self->_is_object($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@_ % 2 and not $self->_is_object($_[0])
@_ % 2 not $self->_is_object($_[0])
Truth table0%0/3
A and not(B)
A= @_ % 2B= not $self->_is_object($_[0])
ABresult
0X0
100
111
2191 }
2192 # Implicit AND operator by default to join multiple fields
2193 0 my $agg_op = 'AND';
2194 0 my @arg = ();
2195 0 ▶ if( $self->_is_a( $_[0], 'DB::Object::Operator' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($_[0], 'DB::Object::Operator')) { } 0 0 0
2196 {
2197 0 ▶ return( $self->error( "I was expecting an operator object, but got \"", $_[0], "\" instead." ) ) if( !$_[0]->isa( 'DB::Object::Operator' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("DB::Object::Operator") 0 0 0
2198 0 ▶ $agg_op = $_[0]->operator || return( $self->error( "Unknown operator for \"", $_[0], "\"." ) );
Condition0%0/2
$_[0]->operator || (return $self->error('Unknown operator for "', $_[0], '".'))
l!l
00
MC/DC0%0/1
$_[0]->operator || (return $self->error('Unknown operator for "', $_[0], '".'))
$_[0]->operator
Truth table0%0/2
A
A= $_[0]->operator
Aresult
11
00
2199 # We filter out any unknown field
2200 0 ( @arg ) = grep( !$self->_is_a( $_ => 'DB::Object::Fields::Unknown' ), $_[0]->value );
2201 }
2202 else
2203 {
2204 0 @arg = @_;
2205 }
2206 0 ▶ $data = \@arg if( @arg );
Branch: 1 branch
BranchTrueFalseTotal
if @arg 0 0 0
2207 0 my $str = '';
2208 0 my @binded = ();
2209 0 my @types = ();
2210 0 my $clause;
2211 # A simple scalar
2212 0 ▶ if( ref( $data ) eq 'SCALAR' )
Branch: 3 branches
BranchTrueFalseTotal
if (ref $data eq 'SCALAR') { } 0 0 0
elsif (ref $data) { } 0 0 0
elsif ($data) { } 0 0 0
2213 {
2214 0 $str = $$data;
2215 }
2216 elsif( ref( $data ) )
2217 {
2218 0 my @list = ();
2219 0 my( $field, $value );
2220 0 ▶ while( @arg )
Branch: 1 branch
BranchTrueFalseTotal
if (@arg) 0 0 0
2221 {
2222 0 ▶ if( $self->_is_object( $arg[0] ) && $arg[0]->isa( 'DB::Object::Operator' ) )
Branch: 8 branches
BranchTrueFalseTotal
if ($self->_is_object($arg[0]) and $arg[0]->isa('DB::Object::Operator')) { } 0 0 0
elsif ($self->_is_object($arg[0]) and $arg[0]->isa('DB::Object::Query::Clause')) { } 0 0 0
elsif ($self->_is_a($arg[0], 'DB::Object::Expression')) { } 0 0 0
elsif ($self->_is_object($arg[0]) and $arg[0]->isa('DB::Object::Fields::Overloaded')) { } 0 0 0
elsif ($self->_is_a($arg[0], 'DB::Object::Fields::Unknown')) { } 0 0 0
elsif (scalar(@arg) % 2 and not ref $arg[0]) { } 0 0 0
elsif (scalar(@arg) % 2 and ref $arg[0] eq 'SCALAR') { } 0 0 0
elsif ($self->_is_a($arg[0], 'DB::Object::Fields::Field') and scalar @arg == 1) { } 0 0 0
Condition0%0/3
$self->_is_object($arg[0]) and $arg[0]->isa("DB::Object::Operator")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($arg[0]) and $arg[0]->isa("DB::Object::Operator")
$self->_is_object($arg[0]) $arg[0]->isa("DB::Object::Operator")
Truth table0%0/3
A and B
A= $self->_is_object($arg[0])B= $arg[0]->isa("DB::Object::Operator")
ABresult
0X0
100
111
2223 {
2224 0 my $op_object = shift( @arg );
2225 0 $clause = $process_where_condition->( $op_object );
2226 0 push( @list, $clause );
2227 0 next;
2228 }
2229 # This is an already formulated clause
2230 ▶ elsif( $self->_is_object( $arg[0] ) && $arg[0]->isa( 'DB::Object::Query::Clause' ) )
Condition0%0/3
$self->_is_object($arg[0]) and $arg[0]->isa("DB::Object::Query::Clause")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($arg[0]) and $arg[0]->isa("DB::Object::Query::Clause")
$self->_is_object($arg[0]) $arg[0]->isa("DB::Object::Query::Clause")
Truth table0%0/3
A and B
A= $self->_is_object($arg[0])B= $arg[0]->isa("DB::Object::Query::Clause")
ABresult
0X0
100
111
2231 {
2232 0 push( @list, shift( @arg ) );
2233 0 next;
2234 }
2235 # An expression
2236 elsif( $self->_is_a( $arg[0] => 'DB::Object::Expression' ) )
2237 {
2238 0 push( @list, shift( @arg ) );
2239 0 next;
2240 }
2241 ▶ elsif( $self->_is_object( $arg[0] ) && $arg[0]->isa( 'DB::Object::Fields::Overloaded' ) )
Condition0%0/3
$self->_is_object($arg[0]) and $arg[0]->isa("DB::Object::Fields::Overloaded")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_object($arg[0]) and $arg[0]->isa("DB::Object::Fields::Overloaded")
$self->_is_object($arg[0]) $arg[0]->isa("DB::Object::Fields::Overloaded")
Truth table0%0/3
A and B
A= $self->_is_object($arg[0])B= $arg[0]->isa("DB::Object::Fields::Overloaded")
ABresult
0X0
100
111
2242 {
2243 0 my $f = shift( @arg );
2244 0 my $cl = $self->new_clause(
2245 value => $f,
2246 type => 'where',
2247 );
2248 # $cl->bind->types->push( '' ) if( $f->binded );
2249 0 ▶ if( $f->placeholder )
Branch: 1 branch
BranchTrueFalseTotal
if ($f->placeholder) 0 0 0
2250 {
2251 0 my $const = $f->field->datatype->constant;
2252 0 my $offset = $f->index;
2253 # $cl->push({
2254 # field => $f->field,
2255 # # Use the offset expressly provided (e.g. $1 (PostgreSQL) or ?1 (SQLite), or the last position in the array
2256 # ( defined( $offset ) ? ( index => $offset ) : () ),
2257 # ( $const ? ( type => $const ) : () ),
2258 # }) || return( $self->pass_error( $cl->error ) );
2259 # Even better than instantiating a new DB::Object::Element object, we just use as-is the DB::Object::Fields::Overloaded object, which inherits from DB::Object::Element :)
2260 0 $cl->push( $f );
2261  
2262 # if( $const )
2263 # {
2264 # $cl->bind->types->push( $const );
2265 # }
2266 # else
2267 # {
2268 # $cl->bind->types->push( '' );
2269 # }
2270 }
2271 0 push( @list, $cl );
2272  
2273 # If this field value assignment is followed (as a pair) by just a regular field, this is likely a typo.
2274 # Catching some typical typo errors for the benefit of the coder (from experience)
2275 0 ▶ if( scalar( @arg ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @arg and $self->_is_a($arg[0], "DB::Object::Fields::Field")) 0 0 0
Condition0%0/3
scalar @arg and $self->_is_a($arg[0], "DB::Object::Fields::Field")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @arg and $self->_is_a($arg[0], "DB::Object::Fields::Field")
scalar @arg $self->_is_a($arg[0], "DB::Object::Fields::Field")
Truth table0%0/3
A and B
A= scalar @argB= $self->_is_a($arg[0], "DB::Object::Fields::Field")
ABresult
0X0
100
111
2276 $self->_is_a( $arg[0], 'DB::Object::Fields::Field' ) )
2277 {
2278 0 ▶ warn( "Warning only: found a (proper) field value assignment ($f) followed by a field object '$arg[0]' (never mind the surrounding quotes) (", overload::StrVal( $arg[0] ), "). Did you forget to assign a value such as \$tbl->fo->$arg[0] == 'something' ?" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
2279 }
2280 0 next;
2281 }
2282 # Ignore it
2283 elsif( $self->_is_a( $arg[0] => 'DB::Object::Fields::Unknown' ) )
2284 {
2285 # warn( "Found an unknown field object DB::Object::Fields::Unknown '", $arg[0]->field, "' of table '", $arg[0]->table, "' in WHERE or HAVING clause: ", $arg[0]->error ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
2286 # shift( @arg );
2287 # next;
2288 0 return( $self->error( "Found an unknown field object DB::Object::Fields::Unknown '", $arg[0]->field, "' of table '", $arg[0]->table, "' in WHERE or HAVING clause: ", $arg[0]->error ) );
2289 }
2290 # Case where there is a litteral query component, e.g. "LENGTH(lang) = 2" and the number of arguments is odd which means there is no second argument such as: ->where( "LENGTH(lang) = 2", $tbl->fo->user_id => "something );
2291 ▶ elsif( ( scalar( @arg ) % 2 ) && !ref( $arg[0] ) )
Condition0%0/3
scalar(@arg) % 2 and not ref $arg[0]
!ll&&!rl&&r
000
MC/DC0%0/2
scalar(@arg) % 2 and not ref $arg[0]
scalar(@arg) % 2 not ref $arg[0]
Truth table0%0/3
A and not(B)
A= scalar(@arg) % 2B= not ref $arg[0]
ABresult
0X0
100
111
2292 {
2293 0 push( @list, $self->new_clause( value => shift( @arg ), type => 'where' ) );
2294 0 next;
2295 }
2296 ▶ elsif( ( scalar( @arg ) % 2 ) && ref( $arg[0] ) eq 'SCALAR' )
Condition0%0/3
scalar(@arg) % 2 and ref $arg[0] eq "SCALAR"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar(@arg) % 2 and ref $arg[0] eq "SCALAR"
scalar(@arg) % 2 ref $arg[0] eq "SCALAR"
Truth table0%0/3
A and B
A= scalar(@arg) % 2B= ref $arg[0] eq "SCALAR"
ABresult
0X0
100
111
2297 {
2298 0 my $scalar = shift( @arg );
2299 0 push( @list, $self->new_clause( value => $$scalar, type => 'where' ) );
2300 0 next;
2301 }
2302 # Catching some typical typo errors for the benefit of the coder (from experience)
2303 # The coder provided a field object without associated value and there are no other argument passed to the where clause. He/she probably forget the assignment like $tbl->fo->field == 'something'
2304 ▶ elsif( $self->_is_a( $arg[0], 'DB::Object::Fields::Field' ) && scalar( @arg ) == 1 )
Condition0%0/3
$self->_is_a($arg[0], "DB::Object::Fields::Field") and scalar @arg == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_a($arg[0], "DB::Object::Fields::Field") and scalar @arg == 1
$self->_is_a($arg[0], "DB::Object::Fields::Field") scalar @arg == 1
Truth table0%0/3
A and B
A= $self->_is_a($arg[0], "DB::Object::Fields::Field")B= scalar @arg == 1
ABresult
0X0
100
111
2305 {
2306 0 ▶ warn( "Warning only: found a field object '$arg[0]' (never mind the surrounding quotes) (", overload::StrVal( $arg[0] ), ") followed by no other argument. Did you forget to assign a value such as \$tbl->fo->$arg[0] == 'something' ?" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
2307 }
2308  
2309 0 my( $field, $value ) = splice( @arg, 0, 2 );
2310 # Catching some typical typo errors for the benefit of the coder (from experience)
2311 0 ▶ if( $self->_is_a( $field, 'DB::Object::Fields::Field' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($field, "DB::Object::Fields::Field") and $self->_is_a($value, "DB::Object::Fields::Overloaded")) 0 0 0
Condition0%0/3
$self->_is_a($field, "DB::Object::Fields::Field") and $self->_is_a($value, "DB::Object::Fields::Overloaded")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_a($field, "DB::Object::Fields::Field") and $self->_is_a($value, "DB::Object::Fields::Overloaded")
$self->_is_a($field, "DB::Object::Fields::Field") $self->_is_a($value, "DB::Object::Fields::Overloaded")
Truth table0%0/3
A and B
A= $self->_is_a($field, "DB::Object::Fields::Field")B= $self->_is_a($value, "DB::Object::Fields::Overloaded")
ABresult
0X0
100
111
2312 $self->_is_a( $value, 'DB::Object::Fields::Overloaded' ) )
2313 {
2314 0 ▶ warn( "Warning only: found a field object '$field' (never mind the surrounding quotes) (", overload::StrVal( $field ), ") followed by an another (proper) field value assignment ($value). Did you forget to assign a value such as \$tbl->fo->$field == 'something' ?" ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
2315 }
2316  
2317 0 ▶ unless( $self->_is_a( $field => 'DB::Object::Fields::Field' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($field, "DB::Object::Fields::Field")) 0 0 0
2318 {
2319 0 ▶ $field =~ s/\b(?<![\.\"])($fields)\b/$prefix.$1/gs if( $prefix );
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 0 0 0
2320 }
2321 0 my $i_am_negative = 0;
2322 0 ▶ if( $self->_is_a( $value, 'DB::Object::NOT' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($value, 'DB::Object::NOT')) { } 0 0 0
elsif (not defined $value or lc $value eq 'null') { } 0 0 0
2323 {
2324 0 ( $value ) = $value->value;
2325 0 ▶ $value = $dbo->NULL if( !defined( $value ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
2326 # https://www.postgresql.org/docs/8.3/functions-comparison.html
2327 0 ▶ if( lc( $value ) eq 'null' )
Branch: 1 branch
BranchTrueFalseTotal
if (lc $value eq "null") 0 0 0
2328 {
2329 # If e do not first copy the value to a separate variable, we would end up with a circular reference (type REF)
2330 0 push( @list, $self->new_clause({
2331 value => "$field IS NOT NULL",
2332 type => 'where',
2333 })
2334 );
2335 0 next;
2336 }
2337 0 $i_am_negative++;
2338 }
2339 # When value is undef() or explicitly set to NULL, we need to write this as IS NULL to be sql compliant
2340 ▶ elsif( !defined( $value ) || lc( $value ) eq 'null' )
Condition0%0/3
not defined $value or lc $value eq "null"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $value or lc $value eq "null"
not defined $value lc $value eq "null"
Truth table0%0/3
not(A) or B
A= not defined $valueB= lc $value eq "null"
ABresult
1X1
011
000
2341 {
2342 0 push( @list, $self->new_clause({
2343 value => "$field IS NULL",
2344 type => 'where',
2345 })
2346 );
2347 0 next;
2348 }
2349  
2350 0 my $f;
2351 0 ▶ if( $self->_is_a( $field => 'DB::Object::Fields::Field' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($field, 'DB::Object::Fields::Field')) { } 0 0 0
2352 {
2353 0 $f = '%s';
2354 }
2355 else
2356 {
2357 0 ▶ $f = $prefix ? "$prefix.$field" : $field;
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
2358 }
2359  
2360 0 ▶ if( ref( $value ) eq 'SCALAR' )
Branch: 6 branches
BranchTrueFalseTotal
if (ref $value eq 'SCALAR') { } 0 0 0
elsif (ref $value eq 'HASH') { } 0 0 0
elsif (ref $value eq "${base_class}::Statement") { } 0 0 0
elsif (ref $value eq 'Regexp') { } 0 0 0
elsif ($value =~ /($placeholder_re)/) { } 0 0 0
elsif ($value =~ /[\s\(\)\.\'\"]+(?:$fields)[\s\(\)\.\'\"]+/ or $value =~ /\w\([^\)]*\)/) { } 0 0 0
2361 {
2362 0 ▶ push( @list, $self->new_clause({
Branch: 1 branch
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
2363 value => $i_am_negative ? "$field != $$value" : "$field = $$value",
2364 type => 'where'
2365 })
2366 );
2367 }
2368 elsif( ref( $value ) eq 'HASH' )
2369 {
2370 0 foreach my $json_key ( keys( %$value ) )
2371 {
2372 0 my $json_value = $value->{ $json_key };
2373 # Assuming default "=" operator for now
2374 0 my $clause = $self->new_clause(
2375 value => "${field}->>'${json_key}' = '${json_value}'",
2376 generic => "${field}->>'${json_key}' = ?",
2377 type => 'where',
2378 );
2379 # Bind the value if it is not a DB::Object reference
2380 # if( !$self->_is_object( $json_value ) )
2381 # {
2382 # $clause->push({ value => $json_value });
2383 # }
2384 0 $clause->push({ value => $json_value });
2385 0 push( @list, $clause );
2386 }
2387 }
2388 # If this is a sub-select - i.e.
2389 # SELECT article, dealer, price
2390 # FROM shop
2391 # WHERE price=(SELECT MAX(price) FROM shop)
2392 # By default we get the value and use it in our clause, but sub classes like DB::Object::Postgres::Query would use the statement as is to form a native sub-query
2393 elsif( ref( $value ) eq "${base_class}::Statement" )
2394 {
2395 0 my $res = $value->fetchrow();
2396 0 ▶ my $cl = $self->new_clause({
Branch: 2 branches
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
$i_am_negative ? : 0 0 0
2397 value => $i_am_negative ? "$f != '$res'" : "$f = '$res'",
2398 generic => $i_am_negative ? "$f != ?" : "$f = ?",
2399 type => 'where',
2400 });
2401 # $cl->bind->values( $res );
2402 # $cl->bind->types( '' );
2403 # $cl->fields( $field ) if( $self->_is_a( $field => 'DB::Object::Fields::Field' ) );
2404 0 $cl->push( $value->query_object->elements );
2405 0 push( @list, $cl );
2406 }
2407 elsif( ref( $value ) eq 'Regexp' )
2408 {
2409 # (?^:^want-(.*?)) => ^want-(.*?)
2410 0 ▶ if( $value =~ s/^\(\?\^\:// )
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ s/^\(\?\^\://) 0 0 0
2411 {
2412 0 $value =~ s/\)$//;
2413 }
2414 0 my $cl;
2415 0 ▶ if( $dbo->driver eq 'Pg' )
Branch: 2 branches
BranchTrueFalseTotal
if ($dbo->driver eq 'Pg') { } 0 0 0
elsif ($dbo->driver eq 'SQLite' or $dbo->driver eq 'mysql') { } 0 0 0
2416 {
2417 0 ▶ $cl = $self->new_clause({
Branch: 2 branches
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
$i_am_negative ? : 0 0 0
2418 value => $i_am_negative ? "$f !~ '$value'" : "$f ~ '$value'",
2419 generic => $i_am_negative ? "$f !~ ?" : "$f ~ ?",
2420 type => 'where',
2421 });
2422 }
2423 ▶ elsif( $dbo->driver eq 'SQLite' ||
Condition0%0/3
$dbo->driver eq "SQLite" or $dbo->driver eq "mysql"
l!l&&r!l&&!r
000
MC/DC0%0/2
$dbo->driver eq "SQLite" or $dbo->driver eq "mysql"
$dbo->driver eq "SQLite" $dbo->driver eq "mysql"
Truth table0%0/3
A or B
A= $dbo->driver eq "SQLite"B= $dbo->driver eq "mysql"
ABresult
1X1
011
000
2424 $dbo->driver eq 'mysql' )
2425 {
2426 0 ▶ $cl = $self->new_clause({
Branch: 2 branches
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
$i_am_negative ? : 0 0 0
2427 value => $i_am_negative ? "$f NOT REGEXP('$value')" : "$f REGEXP('$value')",
2428 generic => $i_am_negative ? "$f NOT REGEXP(?)" : "$f REGEXP(?)",
2429 type => 'where',
2430 });
2431 }
2432 # $cl->bind->values( $value );
2433 # $cl->bind->types( '' );
2434 $cl->push({
2435 0 ▶ ( $self->_is_a( $field => 'DB::Object::Fields::Field' ) ? ( field => $field ) : () ),
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($field, 'DB::Object::Fields::Field') ? : 0 0 0
2436 value => $value,
2437 });
2438 # $cl->fields( $field ) if( $self->_is_a( $field => 'DB::Object::Fields::Field' ) );
2439 0 push( @list, $cl );
2440 }
2441 elsif( $value =~ /($placeholder_re)/ )
2442 {
2443 0 my $plh = $1;
2444 0 ▶ my $cl = $self->new_clause(
Branch: 1 branch
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
2445 value => $i_am_negative ? "$f != $value" : "$f = $value",
2446 type => 'where',
2447 );
2448 0 my $el = $self->new_element(
2449 field => $field,
2450 placeholder => $plh,
2451 format => $value,
2452 );
2453 0 my $const;
2454 0 ▶ if( lc( $fields_type->{ $field } // '' ) eq 'bytea' &&
Branch: 1 branch
BranchTrueFalseTotal
if (lc($fields_type->{$field} // "") eq "bytea" and $const = $dbo->get_sql_type("bytea")) 0 0 0
Condition0%0/5
lc($fields_type->{$field} // "") eq "bytea" and $const = $dbo->get_sql_type("bytea")
!ll&&!rl&&r
000
$fields_type->{$field} // ""
l!l
00
MC/DC0%0/2
lc($fields_type->{$field} // "") eq "bytea" and $const = $dbo->get_sql_type("bytea")
$fields_type->{$field} $const = $dbo->get_sql_type("bytea")
Truth table0%0/3
A and B
A= $fields_type->{$field}B= $const = $dbo->get_sql_type("bytea")
ABresult
0X0
100
111
2455 ( $const = $dbo->get_sql_type( 'bytea' ) ) )
2456 {
2457 0 $el->type( $const );
2458 }
2459 0 $cl->push( $el );
2460 0 push( @list, $cl );
2461 }
2462 ▶ elsif( $value =~ /[\s\(\)\.\'\"]+(?:$fields)[\s\(\)\.\'\"]+/ ||
Condition0%0/3
$value =~ /[\s\(\)\.\'\"]+(?:$fields)[\s\(\)\.\'\"]+/ or $value =~ /\w\([^\)]*\)/
l!l&&r!l&&!r
000
MC/DC0%0/2
$value =~ /[\s\(\)\.\'\"]+(?:$fields)[\s\(\)\.\'\"]+/ or $value =~ /\w\([^\)]*\)/
$value =~ /[\s\(\)\.\'\"]+(?:$fields)[\s\(\)\.\'\"]+/ $value =~ /\w\([^\)]*\)/
Truth table0%0/3
A or B
A= $value =~ /[\s\(\)\.\'\"]+(?:$fields)[\s\(\)\.\'\"]+/B= $value =~ /\w\([^\)]*\)/
ABresult
1X1
011
000
2463 $value =~ /\w\([^\)]*\)/ )
2464 {
2465 # Nothing fancy, as is. Even with binding option on, it will still return the clause without placeholder, because we don't know what $value is
2466 0 ▶ my $cl = $self->new_clause(
Branch: 1 branch
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
2467 value => $i_am_negative ? "$f != $value" : "$f = $value",
2468 type => 'where',
2469 );
2470 # $cl->bind->types( '' ) if( $value =~ /^$placeholder_re$/ );
2471 # $cl->fields( $field ) if( $self->_is_a( $field => 'DB::Object::Fields::Field' ) );
2472 0 ▶ if( $self->_is_a( $field => 'DB::Object::Fields::Field' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($field, "DB::Object::Fields::Field")) 0 0 0
2473 {
2474 0 my $el = $self->new_element(
2475 field => $field,
2476 );
2477 0 $cl->push( $el );
2478 }
2479 0 push( @list, $cl );
2480 }
2481 else
2482 {
2483 0 my( $cl, $const, $el );
2484 0 ▶ if( lc( $fields_type->{ $field } ) eq 'bytea' && ( $const = $dbo->get_sql_type( 'bytea' ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (lc $fields_type->{$field} eq 'bytea' and $const = $dbo->get_sql_type('bytea')) { } 0 0 0
Condition0%0/3
lc $fields_type->{$field} eq "bytea" and $const = $dbo->get_sql_type("bytea")
!ll&&!rl&&r
000
MC/DC0%0/2
lc $fields_type->{$field} eq "bytea" and $const = $dbo->get_sql_type("bytea")
lc $fields_type->{$field} eq "bytea" $const = $dbo->get_sql_type("bytea")
Truth table0%0/3
A and B
A= lc $fields_type->{$field} eq "bytea"B= $const = $dbo->get_sql_type("bytea")
ABresult
0X0
100
111
2485 {
2486 0 ▶ $cl = $self->new_clause(
Branch: 1 branch
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
2487 value => "$f" . ( $i_am_negative ? '!=' : '=' ) . $dbo->quote( $value, $const ),
2488 type => 'where',
2489 );
2490 0 $el = $self->new_element;
2491 }
2492 else
2493 {
2494 0 ▶ $cl = $self->new_clause(
Branch: 2 branches
BranchTrueFalseTotal
$i_am_negative ? : 0 0 0
$i_am_negative ? : 0 0 0
2495 value => "$f" . ( $i_am_negative ? '!=' : '=' ) . $dbo->quote( $value ),
2496 generic => $i_am_negative ? "$f != ?" : "$f = ?",
2497 type => 'where',
2498 );
2499 # $cl->bind->values( $value );
2500 0 $cl->push({
2501 value => $value,
2502 });
2503 0 $el = $self->new_element( value => $value );
2504 }
2505  
2506 0 ▶ $el->field( $field ) if( $self->_is_a( $field => 'DB::Object::Fields::Field' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_a($field, "DB::Object::Fields::Field") 0 0 0
2507 0 ▶ if( lc( $fields_type->{ $field } ) eq 'bytea' &&
Branch: 1 branch
BranchTrueFalseTotal
if (lc $fields_type->{$field} eq "bytea" and $const = $dbo->get_sql_type("bytea")) 0 0 0
Condition0%0/3
lc $fields_type->{$field} eq "bytea" and $const = $dbo->get_sql_type("bytea")
!ll&&!rl&&r
000
MC/DC0%0/2
lc $fields_type->{$field} eq "bytea" and $const = $dbo->get_sql_type("bytea")
lc $fields_type->{$field} eq "bytea" $const = $dbo->get_sql_type("bytea")
Truth table0%0/3
A and B
A= lc $fields_type->{$field} eq "bytea"B= $const = $dbo->get_sql_type("bytea")
ABresult
0X0
100
111
2508 ( $const = $dbo->get_sql_type( 'bytea' ) ) )
2509 {
2510 0 $el->type( $const );
2511 }
2512 # else
2513 # {
2514 # $cl->bind->types( '' ) if( $value =~ /^$placeholder_re$/ );
2515 # }
2516 0 ▶ $cl->push( $el ) if( defined( $el ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $el 0 0 0
2517 0 CORE::push( @list, $cl );
2518 }
2519 }
2520 # End while @arg loop
2521 0 ▶ if( scalar( @list ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @list) 0 0 0
2522 {
2523 0 $clause = $self->new_clause->merge( $dbo->$agg_op( @list ) );
2524 }
2525 }
2526 elsif( $data )
2527 {
2528 # $self->_value2bind( \$data, \@binded ) if( $bind );
2529 # $str = $data;
2530 # @types = ( '' ) x scalar( @binded );
2531 # $clause = $self->new_clause({
2532 # value => $str,
2533 # bind =>
2534 # {
2535 # values => \@binded,
2536 # types => \@types,
2537 # }
2538 # });
2539 0 my $elems = $self->_value2bind( \$data );
2540 0 $clause = $self->new_clause(
2541 value => $data,
2542 type => 'where',
2543 );
2544 0 ▶ $clause->push( $elems ) if( $elems->elements->length );
Branch: 1 branch
BranchTrueFalseTotal
if $elems->elements->length 0 0 0
2545 }
2546 0 return( $clause );
2547 0 };
2548 0 ▶ $where = $self->{ $prop } = $process_where_condition->( @params ) ||
Condition0%0/2
&$process_where_condition(@params) || (return $self->pass_error)
l!l
00
MC/DC0%0/1
&$process_where_condition(@params) || (return $self->pass_error)
&$process_where_condition(@params)
Truth table0%0/2
A
A= &$process_where_condition(@params)
Aresult
11
00
2549 return( $self->pass_error );
2550 0 return( $where );
2551 }
2552 else
2553 {
2554 0 $where = $self->{ $prop };
2555 }
2556  
2557 0 ▶ if( !$where && want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $where and want("OBJECT")) 0 0 0
Condition0%0/3
not $where and want("OBJECT")
!ll&&!rl&&r
000
MC/DC0%0/2
not $where and want("OBJECT")
not $where want("OBJECT")
Truth table0%0/3
not(A) and B
A= not $whereB= want("OBJECT")
ABresult
0X0
100
111
2558 {
2559 0 return( $self->new_null( type => 'object' ) );
2560 }
2561 0 return( $where );
2562 }
2563  
2564 # NOTE: For CBOR and Sereal
2565 sub FREEZE
2566 0 ▶{
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
2567 0 my $self = CORE::shift( @_ );
2568 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
2569 0 my $class = CORE::ref( $self );
2570 0 my $hash = {};
2571 0 my @keys = grep{ !/^binded_/ } @{$self->{query_reset_core_keys}};
2572 0 push( @keys, qw( elements table_object enhance ) );
2573 0 foreach my $prop ( @keys )
2574 {
2575 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
2576 defined( $self->{ $prop } ) &&
2577 # Because we cannot reliably freeze code reference, and we do not usually need to.
2578 CORE::ref( $self->{ $prop } ) ne 'CODE' )
2579 {
2580 0 $hash->{ $prop } = $self->{ $prop };
2581 }
2582 }
2583  
2584 # Return an array reference rather than a list so this works with Sereal and CBOR
2585 # Before Sereal version 4.023, Sereal did not support multiple values returned
2586 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
2587 {
2588 0 require Sereal::Encoder;
2589 0 require version;
2590
2591 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
2592 {
2593 0 CORE::return( [$class, $hash] );
2594 }
2595 }
2596 # But Storable want a list with the first element being the serialised element
2597 0 CORE::return( $class, $hash );
2598 }
2599  
2600 0 ▶sub STORABLE_freeze { return( shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
2601  
2602 0 ▶sub STORABLE_thaw { return( shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
2603  
2604 sub STORABLE_thaw_post_processing
2605 0 ▶{
Subroutine STORABLE_thaw_post_processing: not called CC=1 SCAR=6.9
Pod undocumented
2606 0 my $obj = shift( @_ );
2607 0 my @keys = %$obj;
2608 0 my $class = ref( $obj );
2609 0 my $hash = {};
2610 0 @$hash{ @keys } = @$obj{ @keys };
2611 0 my $self = bless( $hash => $class );
2612 0 return( $self );
2613 }
2614  
2615 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
2616 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
2617 sub THAW
2618 0 ▶{
Subroutine THAW: not called CC=18 SCAR=57.1
Pod undocumented
2619 # STORABLE_thaw would issue $cloning as the 2nd argument, while CBOR would issue
2620 # 'CBOR' as the second value.
2621 0 my( $self, undef, @args ) = @_;
2622 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
2623 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
2624 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
2625 # Since this class is inherited, we also need to load from which we depend, if necessary.
2626 0 ▶ if( $class ne 'DB::Object::Query' )
Branch: 1 branch
BranchTrueFalseTotal
if ($class ne "DB::Object::Query") 0 0 0
2627 {
2628 0 require DB::Object::Query;
2629  
2630 # If inheritance is still missing (or incomplete) for any reason, repair it explicitly.
2631 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
2632  
2633 0 my $stash = \%{"${class}\::"};
2634 0 my $isa_ref;
2635 # We check if the 'ISA' symbol exists in the stash and its ARRAY slot is defined
2636 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
2637 0 defined( *{"${class}\::ISA"}{ARRAY} ) )
2638 {
2639 0 $isa_ref = *{"${class}\::ISA"}{ARRAY};
2640 }
2641 else
2642 {
2643 # # Force creation of @ISA array slot
2644 # @{"${class}::ISA"} = ();
2645 # $isa_ref = *{"${class}::ISA"}{ARRAY};
2646 # But I want it to die, so this can be dealt with, and not swept under the rug.
2647 0 die( "Unable to find the \@ISA value in $class. The package contains the following stashes:\n", $self->Module::Generic::dump( $stash ) );
2648 }
2649 0 my $has_qo = 0;
2650  
2651 0 foreach my $p ( @$isa_ref )
2652 {
2653 0 ▶ $has_qo = 1 if( CORE::defined( $p ) && $p eq 'DB::Object::Query' );
Branch: 1 branch
BranchTrueFalseTotal
if defined $p and $p eq "DB::Object::Query" 0 0 0
Condition0%0/3
defined $p and $p eq "DB::Object::Query"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p and $p eq "DB::Object::Query"
defined $p $p eq "DB::Object::Query"
Truth table0%0/3
A and B
A= defined $pB= $p eq "DB::Object::Query"
ABresult
0X0
100
111
2654 }
2655  
2656 0 ▶ if( !$has_qo )
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_qo) 0 0 0
2657 {
2658 # Same as what we can find in modules DB::Object::(Postgres|SQLite|Mysql)::Query
2659 0 @$isa_ref = ( 'DB::Object::Query' );
2660 }
2661 }
2662 0 my $new;
2663 # Storable pattern requires to modify the object it created rather than returning a new one
2664 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
2665 {
2666 0 foreach( CORE::keys( %$hash ) )
2667 {
2668 # No, this was a bad idea, because the instance property, such as 'where' bears the same name as the method
2669 # So, we would be calling the method 'where', but there is no table object or database object...
2670 # if( my $ref = $self->can( $_ ) )
2671 # {
2672 # $ref->( $self, CORE::delete( $hash->{ $_ } ) );
2673 # }
2674 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
2675 }
2676 0 $new = CORE::bless( $self => $class );
2677 }
2678 else
2679 {
2680 0 $new = CORE::bless( $hash => $class );
2681 }
2682 0 ▶ unless( $new->{elements} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($new->{"elements"}) 0 0 0
2683 {
2684 0 $new->{elements} = $new->new_elements;
2685 }
2686 0 CORE::return( $new );
2687 }
2688  
2689 4 1;
2690 # NOTE: POD
2691 __END__
« lib/DB/Object/Statement.pm ↑ Summary lib/DB/Object.pm »