lib/DB/Object/Query.pm

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