lib/DB/Object/SQLite/Query.pm

filter: Statementstmt 14.4% 26 / 180 Branchbran 0.0% 0 / 104 Conditioncond 0.0% 0 / 65 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 40.0% 8 / 20 Podpod 100% 10 / 10 totaltotal 10.6% 44 / 414 CC 81 SCAR 62.2
CC
81
Cov
7%
on_conflict
930.0
_query_components
756.0
limit
132.0
CRAP 503.0
« lib/DB/Object/Mysql/Tables.pm ↑ Summary lib/DB/Object/SQLite/Tables.pm »
1 # -*- perl -*-
2 ##----------------------------------------------------------------------------
3 ## Database Object Interface - ~/lib/DB/Object/SQLite/Query.pm
4 ## Version v0.4.1
5 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2019/06/16
8 ## Modified 2026/08/05
9 ## All rights reserved
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.##
13 ##----------------------------------------------------------------------------##
14 package DB::Object::SQLite::Query;
15 BEGIN
16 2 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 warnings::register_categories( 'DB::Object' );
20 2 ▶ use parent qw( DB::Object::Query );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use vars qw( $VERSION $DEBUG $EXCEPTION_CLASS );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 our $DEBUG = 0;
24 2 our $EXCEPTION_CLASS = $DB::Object::EXCEPTION_CLASS;
25 2 our $VERSION = 'v0.4.1';
26 };
27  
28 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 sub init
32 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
33 0 my $self = shift( @_ );
34 0 $self->{having} = '';
35 0 $self->{_init_strict_use_sub} = 1;
36 0 $self->{_exception_class} = $EXCEPTION_CLASS;
37 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
38 0 $self->{binded_having} = [];
39 0 $self->{query_reset_keys} = [qw( alias binded binded_values binded_where binded_limit binded_group binded_having binded_order from_unixtime group_by limit local _on_conflict on_conflict order_by reverse sorted unix_timestamp where )];
40 0 return( $self );
41 }
42  
43 0 ▶sub binded_having { return( shift->_set_get( 'binded_having', @_ ) ); }
Subroutine binded_having: not called CC=1 SCAR=6.9
Pod documented
44  
45 sub format_from_epoch
46 0 ▶{
Subroutine format_from_epoch: not called CC=4 SCAR=30.0
Pod documented
47 0 my $self = shift( @_ );
48 0 my $opts = {};
49 0 ▶ $opts = shift( @_ ) if( scalar( @_ ) == 1 && $self->_is_hash( $_[0] => 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and $self->_is_hash($_[0], "strict") 0 0 0
Condition0%0/3
scalar @_ == 1 and $self->_is_hash($_[0], "strict")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and $self->_is_hash($_[0], "strict")
scalar @_ == 1 $self->_is_hash($_[0], "strict")
Truth table0%0/3
A and B
A= scalar @_ == 1B= $self->_is_hash($_[0], "strict")
ABresult
0X0
100
111
50 0 ▶ if( $opts->{bind} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'bind'}) { } 0 0 0
51 {
52 0 return( "DATETIME(?, 'unixepoch', 'localtime')" );
53 }
54 else
55 {
56 0 return( sprintf( "DATETIME(%s, 'unixepoch', 'localtime')", $opts->{value} ) );
57 }
58 }
59  
60 sub format_to_epoch
61 0 ▶{
Subroutine format_to_epoch: not called CC=5 SCAR=34.0
Pod documented
62 0 my $self = shift( @_ );
63 0 my $opts = {};
64 0 ▶ $opts = shift( @_ ) if( scalar( @_ ) == 1 && $self->_is_hash( $_[0] => 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 and $self->_is_hash($_[0], "strict") 0 0 0
Condition0%0/3
scalar @_ == 1 and $self->_is_hash($_[0], "strict")
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @_ == 1 and $self->_is_hash($_[0], "strict")
scalar @_ == 1 $self->_is_hash($_[0], "strict")
Truth table0%0/3
A and B
A= scalar @_ == 1B= $self->_is_hash($_[0], "strict")
ABresult
0X0
100
111
65 0 ▶ if( $opts->{bind} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'bind'}) { } 0 0 0
66 {
67 0 return( "STRFTIME('%s',?)" );
68 }
69 else
70 {
71 0 ▶ return( sprintf( "STRFTIME('%%s','%s')", $opts->{quote} ? "'" . $opts->{value} . "'" : $opts->{value} ) );
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'quote'} ? : 0 0 0
72 }
73 }
74  
75 # _having is in DB::Object::Query
76 # sub having { return( shift->_having( @_ ) ); }
77 0 ▶sub having { return( shift->_where_having( 'having', 'having', @_ ) ); }
Subroutine having: not called CC=1 SCAR=6.9
Pod documented
78  
79 # <https://sqlite.org/lang_select.html#limitoffset>
80 # <https://sqlite.org/lang_delete.html>
81 # <https://sqlite.org/lang_update.html>
82 sub limit
83 0 ▶{
Subroutine limit: not called CC=11 SCAR=48.8
Pod documented
84 0 my $self = shift( @_ );
85 0 my $limit = $self->{limit};
86 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
87 {
88 # Returns a DB::Object::Query::Clause
89 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
90 return( $self->pass_error );
91  
92 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
93 {
94 0 ▶ $limit->generic( CORE::length( $limit->metadata->offset // '' ) ? 'LIMIT ? OFFSET ?' : '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
95 # %s works for integer, and also for numbered placeholders like $1 or ?1, or regular placeholder like ?
96 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
97 CORE::length( $limit->metadata->offset // '' )
98 ? CORE::sprintf( 'LIMIT %s OFFSET %s', $limit->metadata->limit, $limit->metadata->offset )
99 : CORE::sprintf( 'LIMIT %s', $limit->metadata->limit )
100 );
101 }
102 }
103  
104 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
105 {
106 0 return( $self->new_null( type => 'object' ) );
107 }
108 0 return( $limit );
109 }
110  
111 # This implementation in SQLite is essentially identical to PostgreSQL
112 # INSERT INTO vocabulary(word) VALUES('jovial')
113 # ON CONFLICT(word) DO UPDATE SET count=count+1;
114 #
115 # INSERT INTO phonebook(name,phonenumber) VALUES('Alice','704-555-1212')
116 # ON CONFLICT(name) DO UPDATE SET phonenumber=excluded.phonenumber;
117 #
118 #
119 # INSERT INTO phonebook2(name,phonenumber,validDate)
120 # VALUES('Alice','704-555-1212','2018-05-08')
121 # ON CONFLICT(name) DO UPDATE SET
122 # phonenumber=excluded.phonenumber,
123 # validDate=excluded.validDate
124 # WHERE excluded.validDate>phonebook2.validDate;
125 # https://www.sqlite.org/lang_upsert.html
126 # $q->on_conflict({
127 # target => 'id',
128 # action => 'nothing',
129 # action => 'update',
130 # fields => { a => 'some value', b => 'some other' },
131 # });
132 sub on_conflict
133 0 ▶{
Subroutine on_conflict: not called CC=30 SCAR=68.4
Pod documented
134 0 my $self = shift( @_ );
135 0 my $opts = {};
136 0 ▶ $self->{_on_conflict} = {} if( ref( $self->{_on_conflict} ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_on_conflict"} ne "HASH" 0 0 0
137 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
138 {
139 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
140 0 my $ver = $tbl_o->database_object->version;
141 0 ▶ if( version->parse( $ver ) < version->parse( '3.24.0' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse($ver) < "version"->parse("3.24.0")) 0 0 0
142 {
143 0 return( $self->error( "SQLite version is $ver, but version 3.24.0 of 2018-06-04 or higher is required to use this on conflict clause." ) );
144 }
145 0 $opts = $self->_get_args_as_hash( @_ );
146 0 my $hash = {};
147 0 my @comp = ( 'ON CONFLICT' );
148 0 ▶ if( $opts->{target} )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'target'}) { } 0 0 0
elsif ($opts->{'action'} ne 'nothing') { } 0 0 0
149 {
150 0 $hash->{target} = $opts->{target};
151 # Example: ON CONFLICT ON CONSTRAINT customers_name_key DO NOTHING;
152 0 ▶ if( $hash->{target} =~ /^(on[[:blank:]]+constraint)(.*?)$/i )
Branch: 3 branches
BranchTrueFalseTotal
if ($hash->{'target'} =~ /^(on[[:blank:]]+constraint)(.*?)$/i) { } 0 0 0
elsif (ref $hash->{'target'} eq 'SCALAR') { } 0 0 0
elsif ($self->_is_array($hash->{'target'})) { } 0 0 0
153 {
154 0 $hash->{target} = "\U$1\E$2";
155 0 push( @comp, $hash->{target} );
156 }
157 # a reference to a scalar was provided, so we set the value as is
158 elsif( ref( $hash->{target} ) eq 'SCALAR' )
159 {
160 0 push( @comp, $$hash->{target} );
161 }
162 elsif( $self->_is_array( $hash->{target} ) )
163 {
164 0 push( @comp, sprintf( '(%s)', join( ',', @{$hash->{target}} ) ) );
165 }
166 else
167 {
168 0 push( @comp, sprintf( '(%s)', $hash->{target} ) );
169 }
170 }
171 # https://www.postgresql.org/docs/10/sql-insert.html#SQL-ON-CONFLICT
172 elsif( $opts->{action} ne 'nothing' )
173 {
174 0 return( $self->error( "No target was specified for the on conflict clause." ) );
175 }
176  
177 0 ▶ if( $opts->{where} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"where"}) 0 0 0
178 {
179 0 $hash->{where} = $opts->{where};
180 0 push( @comp, 'WHERE ' . $opts->{where} );
181 }
182  
183 # action => update
184 0 ▶ if( $opts->{action} )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'action'}) { } 0 0 0
185 {
186 0 ▶ if( $opts->{action} eq 'update' )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'action'} eq 'update') { } 0 0 0
elsif ($opts->{'action'} eq 'nothing' or $opts->{'action'} eq 'ignore') { } 0 0 0
187 {
188 0 $hash->{action} = $opts->{action};
189 # return( $self->error( "No fields to update was provided for on conflict do update" ) ) if( !$opts->{fields} );
190 # No fields provided, so we take it from the initial insert and build the update list instead
191 0 ▶ if( !$opts->{fields} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"fields"}) 0 0 0
192 {
193 # The insert will have triggered a getdefault() which stores the parameters into a _args object fields
194 # my $f_ref = $self->{ '_args' };
195 # $opts->{inherited_fields} = $self->format_update( $f_ref );
196 $self->{_on_conflict_callback} = sub
197 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
198 0 my $f_ref = $self->{_args};
199 0 $self->is_upsert(1);
200 0 my $inherited_fields = $self->format_update( $f_ref );
201 0 push( @comp, 'DO UPDATE SET' );
202 0 push( @comp, $inherited_fields );
203 0 $hash->{query} = join( ' ', @comp );
204 0 $self->{_on_conflict} = $hash;
205 0 $self->{on_conflict} = join( ' ', @comp );
206 # Usable only once
207 0 CORE::delete( $self->{_on_conflict_callback} );
208 0 };
209 # Return empty, not undef; undef is error
210 0 return( '' );
211 }
212 0 ▶ return( $self->error( "Fields property to update for on conflict do update clause is not a hash reference nor an array of fields." ) ) if( !$self->_is_hash( $opts->{fields} => 'strict' ) && !$self->_is_array( $opts->{fields} ) && !$self->{_on_conflict_callback} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($opts->{"fields"}, "strict") or $self->_is_array($opts->{"fields"}) or $self->{"_on_conflict_callback"} 0 0 0
Condition0%0/6
$self->_is_hash($opts->{"fields"}, "strict") or $self->_is_array($opts->{"fields"}) or $self->{"_on_conflict_callback"}
l!l&&r!l&&!r
000
$self->_is_hash($opts->{"fields"}, "strict") or $self->_is_array($opts->{"fields"})
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->_is_hash($opts->{"fields"}, "strict") or $self->_is_array($opts->{"fields"}) or $self->{"_on_conflict_callback"}
$self->_is_hash($opts->{"fields"}, "strict") $self->_is_array($opts->{"fields"}) $self->{"_on_conflict_callback"}
Truth table0%0/4
A or B or C
A= $self->_is_hash($opts->{"fields"}, "strict")B= $self->_is_array($opts->{"fields"})C= $self->{"_on_conflict_callback"}
ABCresult
1XX1
01X1
0011
0000
213 0 ▶ if( $self->_is_hash( $opts->{fields} => 'strict' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_hash($opts->{'fields'}, 'strict')) { } 0 0 0
elsif ($self->_is_array($opts->{'fields'})) { } 0 0 0
214 {
215 0 ▶ return( $self->error( "Fields property to update for on conflict do update clause contains no fields!" ) ) if( !scalar( keys( %{$opts->{fields}} ) ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar keys %{$$opts{"fields"};} 0 0 0
216 }
217 elsif( $self->_is_array( $opts->{fields} ) )
218 {
219 0 ▶ return( $self->error( "Fields property to update for on conflict do update clause contains no fields!" ) ) if( !scalar( @{$opts->{fields}} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$opts->{"fields"};} 0 0 0
220 }
221  
222 0 ▶ if( $self->_is_array( $opts->{fields} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($opts->{"fields"})) 0 0 0
223 {
224 0 my $this = $opts->{fields};
225 0 my $new = {};
226 0 foreach my $f ( @$this )
227 {
228 0 $new->{ $f } = \( 'EXCLUDED.' . $f );
229 }
230 0 $opts->{fields} = $new;
231 }
232 # Here the user will use the special table 'excluded'
233 0 $hash->{fields} = $opts->{fields};
234  
235 0 my $q = [];
236  
237 0 foreach my $k ( sort( keys( %{$opts->{fields}} ) ) )
238 {
239 0 ▶ push( @$q, sprintf( '%s = %s', $k, ref( $opts->{fields}->{ $k } ) eq 'SCALAR' ? ${$opts->{fields}->{ $k }} : $tbl_o->database_object->quote( $opts->{fields}->{ $k } ) ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $opts->{'fields'}{$k} eq 'SCALAR' ? : 0 0 0
240 }
241 0 ▶ if( scalar( @$q ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$q) { } 0 0 0
242 {
243 0 push( @comp, 'DO UPDATE SET' );
244 0 push( @comp, join( ", ", @$q ) );
245 }
246 else
247 {
248 0 return( $self->error( "A on conflict do update clause was specified, but I could not get a list of fields to update." ) );
249 }
250 }
251 ▶ elsif( $opts->{action} eq 'nothing' || $opts->{action} eq 'ignore' )
Condition0%0/3
$opts->{"action"} eq "nothing" or $opts->{"action"} eq "ignore"
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"action"} eq "nothing" or $opts->{"action"} eq "ignore"
$opts->{"action"} eq "nothing" $opts->{"action"} eq "ignore"
Truth table0%0/3
A or B
A= $opts->{"action"} eq "nothing"B= $opts->{"action"} eq "ignore"
ABresult
1X1
011
000
252 {
253 0 $hash->{action} = $opts->{action};
254 0 push( @comp, 'DO NOTHING' );
255 }
256 else
257 {
258 0 return( $self->error( "Unknown action '$opts->{action}' for on conflict clause." ) );
259 }
260 }
261 else
262 {
263 0 return( $self->error( "No action was specified for the on conflict clause." ) );
264 }
265 0 $hash->{query} = join( ' ', @comp );
266 0 $self->{_on_conflict} = $hash;
267 0 $self->{on_conflict} = $self->new_clause({ value => join( ' ', @comp ) });
268 }
269 # We are being called possibly by _query_components
270 # If we have a callback, we execute it
271 0 ▶ if( $self->{_on_conflict_callback} && !scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_on_conflict_callback"} and not scalar @_) 0 0 0
Condition0%0/3
$self->{"_on_conflict_callback"} and not scalar @_
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_on_conflict_callback"} and not scalar @_
$self->{"_on_conflict_callback"} not scalar @_
Truth table0%0/3
A and not(B)
A= $self->{"_on_conflict_callback"}B= not scalar @_
ABresult
0X0
100
111
272 {
273 # This will use the insert components set up to format our on conflict clause properly
274 # The callback is needed, because the query formatting occurs after the calling of our method on_conflict()
275 0 $self->{_on_conflict_callback}->();
276 }
277 0 return( $self->{on_conflict} );
278 }
279  
280 sub reset
281 0 ▶{
Subroutine reset: not called CC=2 SCAR=17.9
Pod documented
282 0 my $self = shift( @_ );
283 0 ▶ if( !$self->{query_reset} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"query_reset"}) 0 0 0
284 {
285 0 my $keys = [qw( alias binded binded_values binded_where binded_limit binded_group binded_having binded_order from_unixtime group_by limit local _on_conflict on_conflict order_by reverse sorted unix_timestamp where )];
286 0 CORE::delete( @$self{ @$keys } );
287 0 $self->{query_reset}++;
288 # $self->{enhance} = 1;
289 }
290 0 return( $self );
291 }
292  
293 sub reset_bind
294 0 ▶{
Subroutine reset_bind: not called CC=2 SCAR=17.9
Pod documented
295 0 my $self = shift( @_ );
296 0 my @f = qw( binded binded_where binded_group binded_having binded_order binded_limit );
297 0 foreach my $field ( @f )
298 {
299 0 $self->{ $field } = [];
300 }
301 0 return( $self );
302 }
303  
304 # Supported by SQLite since 3.35.0 (2021-03-12)
305 # <https://www.sqlite.org/lang_returning.html>
306 sub returning
307 0 ▶{
Subroutine returning: not called CC=6 SCAR=37.4
Pod documented
308 0 my $self = shift( @_ );
309 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
310 return( $self->error( "No database handle could be found." ) );
311 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
312 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
313 {
314 0 my $pg_version = $dbo->version;
315 0 ▶ return( $self->error( "Cannot use returning for PostgreSQL version lower than 3.35.0 (released on 2021-03-12). This server version is: $pg_version" ) ) if( $pg_version < '3.35.0' );
Branch: 1 branch
BranchTrueFalseTotal
if $pg_version < "3.35.0" 0 0 0
316 # It could be a field name or a wildcard
317 0 ▶ return( $self->error( "A reference was provided (", ref( $_[0] ), "), but I was expecting a string, which could be a field name or even a star (*) indicating all fields." ) ) if( ref( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
318 0 $self->{returning} = $self->new_clause({ value => shift( @_ ) });
319 }
320 # return( wantarray() ? () : undef() ) if( !$self->{returning} );
321 # return( wantarray() ? ( $self->{returning} ) : "RETURNING $self->{returning}" );
322 0 return( $self->{returning} );
323 }
324  
325 # Inherited from DB::Object::Query
326 # sub update
327  
328 sub _query_components
329 0 ▶{
Subroutine _query_components: not called CC=27 SCAR=66.3
330 0 my $self = shift( @_ );
331 0 my $opts = $self->_get_args_as_hash( @_ );
332 0 ▶ my $type = ( @_ > 0 && lc( shift( @_ ) ) ) || $self->_query_type() || return( $self->error( "You must specify a query type: select, insert, update or delete" ) );
Condition0%0/8
@_ > 0 && lc shift @_ || $self->_query_type || (return $self->error('You must specify a query type: select, insert, update or delete'))
l!l
00
@_ > 0 and lc shift @_ or $self->_query_type
l!l&&r!l&&!r
000
@_ > 0 and lc shift @_
!ll&&!rl&&r
000
MC/DC0%0/3
@_ > 0 && lc shift @_ || $self->_query_type || (return $self->error('You must specify a query type: select, insert, update or delete'))
@_ > 0 lc shift @_ $self->_query_type
Truth table0%0/5
A and B or C
A= @_ > 0B= lc shift @_C= $self->_query_type
ABCresult
11X1
0X11
1011
0X00
1000
333 0 ▶ my $dbo = $self->database_object ||
Condition0%0/2
$self->database_object || (return $self->error('No database handle could be found.'))
l!l
00
MC/DC0%0/1
$self->database_object || (return $self->error('No database handle could be found.'))
$self->database_object
Truth table0%0/2
A
A= $self->database_object
Aresult
11
00
334 return( $self->error( "No database handle could be found." ) );
335 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
336 0 my( $where, $group, $having, $sort, $order, $limit, $returning, $on_conflict );
337 0 $where = $self->where();
338 0 $limit = $self->limit();
339 0 $returning = $self->returning;
340 0 $on_conflict = $self->on_conflict;
341 0 ▶ if( $type eq 'select' )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'select') { } 0 0 0
elsif ($type eq 'update' or $type eq 'delete') { } 0 0 0
342 {
343 0 $group = $self->group();
344 0 $having = $self->having();
345 0 ▶ $sort = $self->reverse() ? 'DESC' : $self->sort() ? 'ASC' : '';
Branch: 2 branches
BranchTrueFalseTotal
$self->reverse ? : 0 0 0
$self->sort ? : 0 0 0
346 0 $order = $self->order();
347 0 $limit = $self->limit();
348 }
349 ▶ elsif( $type eq 'update' || $type eq 'delete' )
Condition0%0/3
$type eq "update" or $type eq "delete"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "update" or $type eq "delete"
$type eq "update" $type eq "delete"
Truth table0%0/3
A or B
A= $type eq "update"B= $type eq "delete"
ABresult
1X1
011
000
350 {
351 0 ▶ if( $dbo->can_update_delete_limit )
Branch: 1 branch
BranchTrueFalseTotal
if ($dbo->can_update_delete_limit) 0 0 0
352 {
353 0 $limit = $self->limit();
354 }
355 }
356 0 my @query = ();
357 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
358 0 ▶ push( @query, "GROUP BY $group" ) if( $group );
Branch: 1 branch
BranchTrueFalseTotal
if $group 0 0 0
359 0 ▶ push( @query, "HAVING $having" ) if( $having );
Branch: 1 branch
BranchTrueFalseTotal
if $having 0 0 0
360 0 ▶ push( @query, "ORDER BY $order" ) if( $order );
Branch: 1 branch
BranchTrueFalseTotal
if $order 0 0 0
361 0 ▶ push( @query, $sort ) if( $sort && $order);
Branch: 1 branch
BranchTrueFalseTotal
if $sort and $order 0 0 0
Condition0%0/3
$sort and $order
!ll&&!rl&&r
000
MC/DC0%0/2
$sort and $order
$sort $order
Truth table0%0/3
A and B
A= $sortB= $order
ABresult
0X0
100
111
362 0 ▶ push( @query, $limit ) if( $limit );
Branch: 1 branch
BranchTrueFalseTotal
if $limit 0 0 0
363 0 ▶ if( $on_conflict )
Branch: 1 branch
BranchTrueFalseTotal
if ($on_conflict) 0 0 0
364 {
365 0 ▶ if( $type eq 'insert' )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'insert') { } 0 0 0
366 {
367 0 push( @query, $on_conflict );
368 }
369 else
370 {
371 0 ▶ warn( "The SQLite ON CONFLICT clause is only supported for INSERT queries. Your query was of type \"$type\"." ) if( $self->_is_warnings_enabled( 'DB::Object' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("DB::Object") 0 0 0
372 }
373 }
374 # Supported as of 3.35.0 (2021-03-12)
375 0 ▶ push( @query, "RETURNING $returning" ) if( $returning && ( $type eq 'insert' || $type eq 'update' || $type eq 'delete' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $returning and $type eq "insert" || $type eq "update" || $type eq "delete" 0 0 0
Condition0%0/9
$returning and $type eq "insert" || $type eq "update" || $type eq "delete"
!ll&&!rl&&r
000
$type eq "insert" or $type eq "update" or $type eq "delete"
l!l&&r!l&&!r
000
$type eq "insert" or $type eq "update"
l!l&&r!l&&!r
000
MC/DC0%0/4
$returning and $type eq "insert" || $type eq "update" || $type eq "delete"
$returning $type eq "insert" $type eq "update" $type eq "delete"
Truth table0%0/5
A and B or C or D
A= $returningB= $type eq "insert"C= $type eq "update"D= $type eq "delete"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
376 0 return( \@query );
377 }
378  
379 2 1;
380 # NOTE: POD
381 __END__
« lib/DB/Object/Mysql/Tables.pm ↑ Summary lib/DB/Object/SQLite/Tables.pm »