blib/lib/SQL/Yapp.pm

filter: Statementstmt 78.9% 2432 / 3081 Branchbran 62.7% 725 / 1156 Conditioncond 50.9% 157 / 308 MC/DCmcdc 22.7% 41 / 180 Subroutinesub 71.7% 585 / 815 Podpod 0.0% 0 / 298 totaltotal 67.4% 3940 / 5838 CC 715 SCAR 19.0
CC
715
Cov
73%
shift_or_reduce_pure
94.5
value
33.0
__ANON__
30.0
CRAP 6.7
↑ Summary
1 #! /usr/bin/perl -w
2  
3 package SQL::Yapp;
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use vars qw($VERSION @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Carp qw(longmess carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Hash::Util qw(lock_keys lock_hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Scalar::Util qw(looks_like_number blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Filter::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Text::Balanced;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 5 require v5.8;
17  
18 5 $VERSION= 2.002;
19  
20 5 @EXPORT_OK=qw(
21 dbh
22 get_dbh
23 quote
24 quote_identifier
25 check_identifier
26 runtime_check
27 xlat_catalog
28 xlat_schema
29 xlat_table
30 xlat_column
31 xlat_charset
32 xlat_collate
33 xlat_constraint
34 xlat_index
35 xlat_transliteration
36 xlat_transcoding
37 xlat_engine
38 parse
39 ASTERISK
40 QUESTION
41 NULL
42 TRUE
43 FALSE
44 UNKNOWN
45 DEFAULT
46 );
47  
48 5 ▶use constant SQL_MARK => "\0__SQL__";
Subroutine BEGIN: called CC=1 SCAR=0.0
49 5 ▶use constant COMMA_STR => ', ';
Subroutine BEGIN: called CC=1 SCAR=0.0
50 5 ▶use constant LARGE_LIMIT_CNT => '18446744073709551615';
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 5 ▶use constant NOT_IN_LIST => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 5 ▶use constant IN_LIST => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 5 ▶use constant NO_PARENS => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 5 ▶use constant PARENS => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 5 ▶use constant NO_SHIFT => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 5 ▶use constant SHIFT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 5 my $get_dbh= undef;
62 5 my $quote_id= undef;
63 5 my $quote_val= undef;
64 5 my $quote_id_default= undef;
65 5 my $quote_val_default= undef;
66 1 ▶my $xlat_catalog= sub($) { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
67 2 ▶my $xlat_schema= sub($) { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
68 0 ▶my $xlat_table= sub($) { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
69 171 ▶my $xlat_column= sub($) { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
70 2 ▶my $xlat_charset= sub($) { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
71 0 ▶my $xlat_collate= sub($) { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
72 0 ▶my $xlat_constraint= sub($) { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
73 0 ▶my $xlat_index= sub($) { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
74 0 ▶my $xlat_transliteration= sub($) { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
75 0 ▶my $xlat_transcoding= sub($) { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
76 1 ▶my $xlat_engine= sub($) { $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.0
77 5 ▶my $check_identifier= sub($$$$$) { };
Subroutine __ANON__: not called CC=1 SCAR=0.0
78 5 my $runtime_check= 0;
79 5 my $sql_marker= 'sql';
80 5 my $do_prec= 0;
81 5 my $debug= 0;
82  
83 5 my %dialect= ( # known dialects
84 generic => 1,
85 std => 1,
86 mysql => 1,
87 postgresql => 1,
88 oracle => 1,
89 );
90  
91 5 my $write_dialect= 'generic'; # not well-supported yet, only a few things are done
92 5 my %read_dialect= (
93 mysql => 1,
94 postgresql => 1,
95 oracle => 1,
96 );
97  
98 # SQL often has several tokens used as one keyword. In order to
99 # simplify the parser, we combine them in the scanner already. This
100 # also produces nicer error messages with more information for the
101 # user (e.g. 'Unexpected IS NOT NULL'...).
102 5 my %multi_token= (
103 IS => {
104 NULL => {},
105 TRUE => {},
106 FALSE => {},
107 UNKNOWN => {},
108 NORMALIZED => {},
109 NOT => {
110 NULL => {},
111 TRUE => {},
112 FALSE => {},
113 UNKNOWN => {},
114 NORMALIZED => {},
115 A => { SET => {} },
116 OF => {},
117 },
118 DISTINCT => { FROM => {} },
119 A => { SET => {} },
120 OF => {},
121 },
122 GROUP => { BY => {} },
123 ORDER => { BY => {} },
124 WITH => {
125 ROLLUP => {},
126 ORDINALITY => {},
127 LOCAL => { TIME => { ZONE => {} } },
128 TIME => { ZONE => {} },
129 },
130 WITHOUT => { TIME => { ZONE => {} } },
131 FOR => {
132 UPDATE => {},
133 SHARE => {},
134 },
135 LOCK => { IN => { SHARE => { MODE => {} } } },
136  
137 SIMILAR => { TO => {} },
138 BETWEEN => {
139 SYMMETRIC => {},
140 ASYMMETRIC => {},
141 },
142 MEMBER => { OF => {} },
143  
144 PRIMARY => { KEY => {} },
145 FOREIGN => { KEY => {} },
146  
147 CHARACTER => {
148 SET => {},
149 VARYING => {},
150 },
151 NATIONAL => { CHARACTER => {} },
152 NCHAR => {
153 VARYING => {}
154 },
155 DEFAULT => {
156 VALUES => {},
157 CHARACTER => {
158 SET => {}
159 },
160 },
161 ON => {
162 DUPLICATE => { KEY => { UPDATE => {} } },
163 DELETE => {},
164 UPDATE => {},
165 COMMIT => {},
166 },
167 OVERRIDING => {
168 USER => { VALUE => {} },
169 SYSTEM => { VALUE => {} }
170 },
171 CREATE => {
172 TABLE => {},
173 LOCAL => {
174 TABLE => {},
175 TEMPORARY => { TABLE => {} },
176 },
177 GLOBAL => {
178 TABLE => {},
179 TEMPORARY => { TABLE => {} },
180 },
181 INDEX => {},
182 },
183 ALTER => {
184 TABLE => {},
185 IGNORE => { TABLE => {} },
186 ONLINE => {
187 TABLE => {},
188 IGNORE => { TABLE => {} },
189 },
190 OFFLINE => {
191 TABLE => {},
192 IGNORE => { TABLE => {} },
193 },
194 COLUMN => {
195 },
196 },
197 DROP => {
198 TABLE => {},
199 TEMPORARY => { TABLE => {} },
200  
201 SIGN => {},
202 ZEROFILL => {},
203 COLLATE => {},
204 TIME => { ZONE => {} },
205 CHARACTER => { SET => {} },
206  
207 DEFAULT => {},
208 UNIQUE => {},
209 AUTO_INCREMENT => {},
210 UNIQUE => { KEY => {} },
211 PRIMARY => { KEY => {} },
212 FOREIGN => { KEY => {} },
213 KEY => {},
214 INDEX => {},
215  
216 NOT => { NULL => {} },
217  
218 COLUMN => {},
219 CONSTRAINT => {},
220 },
221 NOT => {
222 LIKE => {},
223 CLIKE => {},
224 SIMILAR => { TO => {}, },
225 BETWEEN => {
226 SYMMETRIC => {},
227 ASYMMETRIC => {},
228 },
229 MEMBER => { OF => {} },
230 NULL => {},
231 },
232  
233 NO => {
234 ACTION => {},
235 },
236  
237 BINARY => { VARYING => {} },
238 TEXT => { BINARY => {} },
239 TINYTEXT => { BINARY => {} },
240 MEDIUMTEXT => { BINARY => {} },
241 LONGTEXT => { BINARY => {} },
242 UNIQUE => { KEY => {} },
243 IF => {
244 NOT => { EXISTS => {} }, # Ouch! (should be :if-does-not-exist, of course)
245 EXISTS => {},
246 },
247 SET => {
248 NULL => {},
249 DEFAULT => {},
250 NOT => { NULL => {} },
251 SET => { DATA => { TYPE => {} } },
252 },
253 PRESERVE => { ROWS => {} },
254 DELETE => { ROWS => {} },
255 RENAME => {
256 TO => {},
257 COLUMN => {},
258 },
259 ADD => {
260 COLUMN => {},
261 },
262 MODIFY => {
263 COLUMN => {},
264 },
265 CHANGE => {
266 COLUMN => {},
267 },
268 );
269 5 my %synonym= (
270 'NORMALISED' => 'NORMALIZED',
271 'CHAR' => 'CHARACTER',
272 'CHAR_LENGTH' => 'CHARACTER_LENGTH',
273 'CHARACTER VARYING' => 'VARCHAR',
274 'NATIONAL CHARACTER' => 'NCHAR',
275 'CHAR LARGE OBJECT' => 'CLOB',
276 'NCHAR LARGE OBJECT' => 'NCLOB',
277 'BINARY LARGE OBJECT' => 'BLOB',
278 'NVARCHAR' => 'NCHAR VARYING',
279 'DEC' => 'DECIMAL',
280 'INTEGER' => 'INT',
281 'BINARY VARYING' => 'VARBINARY',
282 'CHARSET' => 'CHARACTER SET',
283 'TEMP' => 'TEMPORARY',
284 );
285  
286 5 my %type_spec= ();
287  
288 5 my @SELECT_INITIAL= (
289 'SELECT',
290 # 'WITH' # NOT YET
291 );
292  
293 5 my @CREATE_TABLE_INITIAL= (
294 'CREATE TABLE',
295 'CREATE TEMPORARY TABLE',
296 'CREATE LOCAL TABLE',
297 'CREATE GLOBAL TABLE',
298 'CREATE LOCAL TEMPORARY TABLE',
299 'CREATE GLOBAL TEMPORARY TABLE',
300 );
301  
302 5 my @DROP_TABLE_INITIAL= (
303 'DROP TABLE',
304 'DROP TEMPORARY TABLE',
305 );
306  
307 5 my @ALTER_TABLE_INITIAL= (
308 'ALTER TABLE',
309 'ALTER IGNORE TABLE',
310 'ALTER ONLINE TABLE',
311 'ALTER ONLINE IGNORE TABLE',
312 'ALTER OFFLINE TABLE',
313 'ALTER OFFLINE IGNORE TABLE',
314 );
315  
316 ######################################################################
317 # Use settings:
318  
319 sub get_set
320 20 ▶{
Subroutine get_set: called CC=2 SCAR=7.0
Pod undocumented
321 20 my $var= shift;
322 20 my $r= $$var;
323 20 ▶ ($$var)= @_ if scalar(@_);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ 20 0 20
324 20 return $;
325 }
326  
327 sub get_dbh()
328 0 ▶{
Subroutine get_dbh: not called CC=1 SCAR=6.9
Pod undocumented
329 0 return $get_dbh->();
330 }
331  
332 sub dbh(;&)
333 1 ▶{
Subroutine dbh: called CC=2 SCAR=9.2
Pod undocumented
334 1 get_set (\$get_dbh, @_);
335 1 ▶ if ($get_dbh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get_dbh) { } 1 0 1
336 0 ▶ $quote_id_default= sub(@) { $get_dbh->()->quote_identifier(@_); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
337 0 ▶ $quote_val_default= sub($) { $get_dbh->()->quote($_[0]); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
338 }
339 else {
340 0 $quote_id_default= undef;
341 0 $quote_val_default= undef;
342 }
343 }
344  
345 4 ▶sub quote_identifier(;&) { get_set (\$quote_id, @_); }
Subroutine quote_identifier: called CC=1 SCAR=0.0
Pod undocumented
346 4 ▶sub quote(;&) { get_set (\$quote_val, @_); }
Subroutine quote: called CC=1 SCAR=0.0
Pod undocumented
347 2 ▶sub xlat_catalog(;&) { get_set (\$xlat_catalog, @_); }
Subroutine xlat_catalog: called CC=1 SCAR=0.0
Pod undocumented
348 2 ▶sub xlat_schema(;&) { get_set (\$xlat_schema, @_); }
Subroutine xlat_schema: called CC=1 SCAR=0.0
Pod undocumented
349 4 ▶sub xlat_table(;&) { get_set (\$xlat_table, @_); }
Subroutine xlat_table: called CC=1 SCAR=0.0
Pod undocumented
350 2 ▶sub xlat_column(;&) { get_set (\$xlat_column, @_); }
Subroutine xlat_column: called CC=1 SCAR=0.0
Pod undocumented
351 0 ▶sub xlat_charset(;&) { get_set (\$xlat_charset, @_); }
Subroutine xlat_charset: not called CC=1 SCAR=6.9
Pod undocumented
352 0 ▶sub xlat_collate(;&) { get_set (\$xlat_collate, @_); }
Subroutine xlat_collate: not called CC=1 SCAR=6.9
Pod undocumented
353 0 ▶sub xlat_constraint(;&) { get_set (\$xlat_constraint, @_); }
Subroutine xlat_constraint: not called CC=1 SCAR=6.9
Pod undocumented
354 0 ▶sub xlat_index(;&) { get_set (\$xlat_index, @_); }
Subroutine xlat_index: not called CC=1 SCAR=6.9
Pod undocumented
355 0 ▶sub xlat_transcoding(;&) { get_set (\$xlat_transcoding, @_); }
Subroutine xlat_transcoding: not called CC=1 SCAR=6.9
Pod undocumented
356 0 ▶sub xlat_transliteration(;&) { get_set (\$xlat_transliteration, @_); }
Subroutine xlat_transliteration: not called CC=1 SCAR=6.9
Pod undocumented
357 0 ▶sub xlat_engine(;&) { get_set (\$xlat_engine, @_); }
Subroutine xlat_engine: not called CC=1 SCAR=6.9
Pod undocumented
358  
359 0 ▶sub check_identifier(;&) { get_set (\$check_identifier, @_); }
Subroutine check_identifier: not called CC=1 SCAR=6.9
Pod undocumented
360 0 ▶sub runtime_check(;$) { get_set (\$runtime_check, @_); }
Subroutine runtime_check: not called CC=1 SCAR=6.9
Pod undocumented
361  
362 1 ▶sub sql_marker(;$) { get_set (\$sql_marker, @_); } # used only internally
Subroutine sql_marker: called CC=1 SCAR=0.0
Pod undocumented
363  
364 2 ▶sub catalog_prefix($) { my ($p)= @_; xlat_catalog { $p.$_[0] }; }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine catalog_prefix: called CC=1 SCAR=0.0
Pod undocumented
365 2 ▶sub schema_prefix($) { my ($p)= @_; xlat_schema { $p.$_[0] }; }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine schema_prefix: called CC=1 SCAR=0.0
Pod undocumented
366 124 ▶sub table_prefix($) { my ($p)= @_; xlat_table { $p.$_[0] }; }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine table_prefix: called CC=1 SCAR=0.0
Pod undocumented
367 68 ▶sub column_prefix($) { my ($p)= @_; xlat_column { $p.$_[0] }; }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine column_prefix: called CC=1 SCAR=0.0
Pod undocumented
368 0 ▶sub constraint_prefix($) { my ($p)= @_; xlat_constraint { $p.$_[0] }; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine constraint_prefix: not called CC=1 SCAR=6.9
Pod undocumented
369  
370 0 ▶sub debug($) { ($debug)= @_; }
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
371  
372 sub read_dialect1($)
373 0 ▶{
Subroutine read_dialect1: not called CC=4 SCAR=30.0
Pod undocumented
374 0 my ($s)= @_;
375 0 ▶ if ($s eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq 'all') { } 0 0 0
376 0 for my $s1 (keys %dialect) {
377 0 $read_dialect{$s1}= 1;
378 }
379 }
380 else {
381 0 ▶ croak "Unknown dialect: read_dialect=$s" unless $dialect{$s};
Branch: 1 branch
BranchTrueFalseTotal
unless $dialect{$s} 0 0 0
382 0 $read_dialect{$s}= 1;
383 }
384 }
385  
386 sub read_dialect($)
387 0 ▶{
Subroutine read_dialect: not called CC=4 SCAR=30.0
Pod undocumented
388 0 my ($s)= @_;
389 0 %read_dialect=();
390 0 ▶ if (!ref($s)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $s) { } 0 0 0
elsif (ref $s eq 'ARRAY') { } 0 0 0
391 0 read_dialect1($s);
392 }
393 elsif (ref($s) eq 'ARRAY') {
394 0 for my $s1 (@$s) {
395 0 read_dialect1($s1);
396 }
397 }
398 else {
399 0 die "Illegal reference: ".ref($s);
400 }
401 }
402  
403 sub write_dialect($)
404 9 ▶{
Subroutine write_dialect: called CC=2 SCAR=7.1
Pod undocumented
405 9 my ($s)= @_;
406 9 ▶ croak "Unknown dialect: write_dialect=$s" unless $dialect{$s};
Branch: 1 branch
BranchTrueFalseTotal
unless $dialect{$s} 0 9 9
407 9 $write_dialect= $s;
408 }
409  
410 sub dialect($)
411 0 ▶{
Subroutine dialect: not called CC=1 SCAR=6.9
Pod undocumented
412 0 my ($s)= @_;
413 0 read_dialect($s);
414 0 write_dialect($s);
415 }
416  
417 ######################################################################
418 # Init
419  
420 5 my %import_handler_nonref= (
421 'marker' => \&sql_marker,
422 'catalog_prefix' => \&catalog_prefix,
423 'schema_prefix' => \&schema_prefix,
424 'table_prefix' => \&table_prefix,
425 'column_prefix' => \&column_prefix,
426 'constraint_prefix' => \&constraint_prefix,
427 'debug' => \&debug,
428 'read_dialect' => \&read_dialect,
429 'write_dialect' => \&write_dialect,
430 'dialect' => \&dialect,
431 );
432 5 my %import_handler_bool= (
433 'runtime_check' => \&runtime_check,
434 );
435 5 my %import_handler_ref= (
436 'dbh' => \&dbh,
437 'quote' => \&quote,
438 'quote_identifier' => \&quote_identifier,
439 'xlat_catalog' => \&xlat_catalog,
440 'xlat_schema' => \&xlat_schema,
441 'xlat_table' => \&xlat_table,
442 'xlat_column' => \&xlat_column,
443 'xlat_charset' => \&xlat_charset,
444 'xlat_collate' => \&xlat_collate,
445 'xlat_constraint' => \&xlat_constraint,
446 'xlat_index' => \&xlat_index,
447 'xlat_transliteration' => \&xlat_transliteration,
448 'xlat_transcoding' => \&xlat_transcoding,
449 'xlat_engine' => \&xlat_engine,
450 'check_identifier' => \&check_identifier,
451 );
452  
453 sub type_spec()
454 5 ▶{
Subroutine type_spec: called CC=4 SCAR=16.6
Pod undocumented
455 return (
456 'DOUBLE PRECISION' => 'INT',
457 'REAL' => 'INT',
458 'BIGINT' => 'INT',
459 'SMALLINT' => 'INT',
460 'INT' => {
461 },
462  
463 # numbers with 0 or 1 precision marker:
464 'FLOAT' => {
465 prec1 => 1,
466 },
467  
468 # numbers with 0, 1, or 2 precision numbers:
469 'NUMERIC' => 'DECIMAL',
470 'DECIMAL' => {
471 prec1 => 1,
472 prec2 => 1,
473 },
474  
475 # character strings:
476 'VARCHAR' => 'CHARACTER',
477 'CHARACTER' => {
478 prec1 => 1,
479 charset => 1,
480 collate => 1,
481 },
482  
483 # clobs:
484 'CLOB' => {
485 prec1 => 1,
486 prec_mul => 1,
487 prec_unit => 1,
488 charset => 1,
489 collate => 1,
490 },
491  
492 # nchar:
493 'NCHAR VARYING' => 'NCHAR',
494 'NCHAR' => {
495 prec1 => 1,
496 collate => 1,
497 },
498  
499 # nclobs:
500 'NCLOB' => {
501 prec1 => 1,
502 prec_mul => 1,
503 prec_unit => 1,
504 collate => 1,
505 },
506  
507 # binary strings:
508 'VARBINARY' => 'BINARY', # not standard
509 'BINARY' => {
510 prec1 => 1,
511 },
512  
513 # blobs:
514 'BLOB' => {
515 prec1 => 1,
516 prec_mul => 1,
517 prec_unit => 1,
518 },
519  
520 # simple types without further attributes or lengths:
521 'SERIAL' => 'BOOLEAN', # column spec, but handled as type for simplicity reasons
522 'BOOLEAN' => {
523 },
524  
525 # date/time:
526 'DATE' => 'TIME',
527 'TIMESTAMP' => 'TIME',
528 'TIME' => {
529 timezone => 1
530 },
531  
532 # Dialects come last because they may redefine above settings:
533 # If two dialects are contracting, you must find a common solution
534 # and put it at the end of this list:
535 ($read_dialect{mysql} ?
536 (
537 'SMALLINT' => 'INT',
538 'BIGINT' => 'INT',
539 'TINYINT' => 'INT',
540 'MEDIUMINT' => 'INT',
541 'BIT' => 'INT',
542 'BIT VARYING' => 'INT',
543 'FLOAT' => 'INT',
544 'INT' => {
545 prec1 => 1,
546 zerofill => 1,
547 sign => 1,
548 },
549  
550 'FLOAT' => 'NUMERIC',
551 'DECIMAL' => 'NUMERIC',
552 'REAL' => 'NUMERIC',
553 'DOUBLE' => 'NUMERIC',
554 'NUMERIC' => {
555 prec1 => 1,
556 prec2 => 1,
557 zerofill => 1,
558 sign => 1,
559 },
560  
561 'DATETIME' => 'TIME',
562 'YEAR' => 'TIME',
563  
564 'TINYBLOB' => 'BINARY',
565 'MEDIUMBLOB' => 'BINARY',
566 'LONGBLOB' => 'BINARY',
567  
568 'TINYTEXT' => 'CHARACTER',
569 'MEDIUMTEXT' => 'CHARACTER',
570 'LONGTEXT' => 'CHARACTER',
571 'TEXT' => 'CHARACTER',
572  
573 'TINYTEXT BINARY' => 'CHARACTER',
574 'MEDIUMTEXT BINARY' => 'CHARACTER',
575 'LONGTEXT BINARY' => 'CHARACTER',
576 'TEXT BINARY' => 'CHARACTER',
577  
578 'ENUM' => {
579 value_list => 1,
580 charset => 1,
581 collate => 1,
582 },
583  
584 'SET' => {
585 value_list => 1,
586 charset => 1,
587 collate => 1,
588 },
589 )
590 : ()
591 ),
592 ($read_dialect{postgresql} ?
593 (
594 'BYTEA' => 'BINARY',
595 'INT2' => 'INT',
596 'INT4' => 'INT',
597 'INT8' => 'INT',
598 'POINT' => 'BOOLEAN',
599 'LINE' => 'BOOLEAN',
600 'LSEG' => 'BOOLEAN',
601 'BOX' => 'BOOLEAN',
602 'PATH' => 'BOOLEAN',
603 'POLYGON' => 'BOOLEAN',
604 'CIRCLE' => 'BOOLEAN',
605 'MONEY' => 'BOOLEAN',
606 'IRDR' => 'BOOLEAN',
607 'INET' => 'BOOLEAN',
608 'MACADDR' => 'BOOLEAN',
609 'UUID' => 'BOOLEAN',
610 'TEXT' => 'CHARACTER',
611 'SERIAL4' => 'SERIAL',
612 'SERIAL8' => 'SERIAL',
613 'BIGSERIAL' => 'SERIAL',
614 )
615 : ()
616 ),
617 ($read_dialect{oracle} ?
618 (
619 5 ▶ 'NUMBER' => 'NUMERIC'
Branch: 3 branches
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 5 0 5
$read_dialect{'postgresql'} ? : 5 0 5
$read_dialect{'oracle'} ? : 5 0 5
620 )
621 : ()
622 ),
623 );
624 }
625  
626 sub import
627 5 ▶{
Subroutine import: called CC=9 SCAR=25.9
628 5 my ($pack, @opt)= @_;
629 5 my @super_param= ();
630 5 my $i=0;
631 5 ▶ while ($i < scalar(@opt)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @opt) 17 5 22
632 17 my $k= $opt[$i];
633 17 ▶ if ($i+1 < scalar(@opt)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < scalar @opt) { } 17 0 17
634 17 my $v= $opt[$i+1];
635 17 ▶ if (my $handler= $import_handler_nonref{$k}) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $handler = $import_handler_nonref{$k}) { } 8 9 17
elsif ($v eq '0' or $v eq '1') { } 0 9 9
elsif (ref $v) { } 9 0 9
636 8 $handler->($v);
637 8 $i++;
638 }
639 ▶ elsif ($v eq '0' || $v eq '1') {
Condition33%1/3
$v eq 0 or $v eq 1
l!l&&r!l&&!r
009
MC/DC0%0/2
$v eq 0 or $v eq 1
$v eq 0 $v eq 1
Truth table33%1/3
A or B
A= $v eq 0B= $v eq 1
ABresult
1X1
011
000
640 0 ▶ if (my $handler= $import_handler_bool{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $import_handler_bool{$k}) { } 0 0 0
641 0 $handler->($v);
642 0 $i++;
643 }
644 else {
645 0 croak "Error: Unrecognised package option for ".__PACKAGE__.": $k\n";
646 }
647 }
648 elsif (ref($v)) {
649 9 ▶ if (my $handler= $import_handler_ref{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $import_handler_ref{$k}) { } 9 0 9
650 9 $handler->($v);
651 9 $i++;
652 }
653 else {
654 0 croak "Error: Unrecognised package option for ".__PACKAGE__.": $k\n";
655 }
656 }
657 else {
658 0 push @super_param, $k;
659 }
660 }
661 else {
662 0 push @super_param, $k;
663 }
664 17 $i++;
665 }
666  
667 5 &Exporter::import($pack,@super_param);
668  
669 5 %type_spec= type_spec();
670 }
671  
672 ######################################################################
673 # Tools
674  
675 sub my_dumper($)
676 1 ▶{
Subroutine my_dumper: called CC=2 SCAR=7.1
Pod undocumented
677 1 my ($x)= @_;
678  
679 1 my $d= Data::Dumper->new([$x],['x']);
680 1 $d->Terse(1);
681 1 $d->Purity(1);
682 1 $d->Indent(1);
683  
684 1 my $s= $d->Dump;
685 1 ▶ return $s
Branch: 1 branch
BranchTrueFalseTotal
if length $s <= 400 1 0 1
686 if length($s) <= 400;
687  
688 0 return substr($s,0,400).'...';
689 }
690  
691 # longmess gives me: bizarre copy of hash. So confess does not work.
692 # Don't ask me why, I spent some time to debug this, but now I am
693 # sick of it. So here's my primitive version:
694 sub my_longmess()
695 3 ▶{
Subroutine my_longmess: called CC=2 SCAR=6.9
Pod undocumented
696 3 my $i= 2;
697 3 my @mess= ();
698 3 ▶ while (my ($pack, $file, $line, $function)= caller($i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = caller $i) 61 3 64
699 61 push @mess, "\t$file:$line: ${pack}::${function}\n";
700 61 $i++;
701 }
702 3 return "Call Stack:\n".join('', reverse @mess);
703 }
704  
705 sub my_confess(;$)
706 3 ▶{
Subroutine my_confess: called CC=2 SCAR=7.6
Pod undocumented
707 3 ▶ die my_longmess.'DIED: '.($_[0] || 'Error');
Condition50%1/2
$_[0] || 'Error'
l!l
30
MC/DC0%0/1
$_[0] || 'Error'
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
708 }
709  
710 ######################################################################
711 # Non-trivial access to module variables:
712  
713 sub get_quote_val()
714 205 ▶{
Subroutine get_quote_val: called CC=3 SCAR=16.5
Pod undocumented
715 return
716 $quote_val ||
717 $quote_val_default ||
718 205 ▶ do {
Condition33%2/6
$quote_val || $quote_val_default || do { croak("Error: No quote() function set.\n\tUse SQL::Yapp::quote() or SQL::Yapp::dbh().\n") }
l!l&&r!l&&!r
20500
$quote_val or $quote_val_default
l!l&&r!l&&!r
20500
MC/DC0%0/3
$quote_val || $quote_val_default || do { croak("Error: No quote() function set.\n\tUse SQL::Yapp::quote() or SQL::Yapp::dbh().\n") }
$quote_val $quote_val_default do { croak("Error: No quote() function set.\n\tUse SQL::Yapp::quote() or SQL::Yapp::dbh().\n") }
Truth table25%1/4
A or B || C
A= $quote_valB= $quote_val_defaultC= do { croak("Error: No quote() function set.\n\tUse SQL::Yapp::quote() or SQL::Yapp::dbh().\n") }
ABCresult
1XX1
01X1
0011
0000
719 0 croak "Error: No quote() function set.\n".
720 "\tUse ".__PACKAGE__."::quote() or ".__PACKAGE__."::dbh().\n";
721 };
722 }
723  
724 sub get_quote_id()
725 379 ▶{
Subroutine get_quote_id: called CC=3 SCAR=16.5
Pod undocumented
726 return
727 $quote_id ||
728 $quote_id_default ||
729 379 ▶ do {
Condition33%2/6
$quote_id || $quote_id_default || do { croak("Error: No quote_identifier() function set.\n\tUse SQL::Yapp::quote_identifier() or SQL::Yapp::dbh().\n") }
l!l&&r!l&&!r
37900
$quote_id or $quote_id_default
l!l&&r!l&&!r
37900
MC/DC0%0/3
$quote_id || $quote_id_default || do { croak("Error: No quote_identifier() function set.\n\tUse SQL::Yapp::quote_identifier() or SQL::Yapp::dbh().\n") }
$quote_id $quote_id_default do { croak("Error: No quote_identifier() function set.\n\tUse SQL::Yapp::quote_identifier() or SQL::Yapp::dbh().\n") }
Truth table25%1/4
A or B || C
A= $quote_idB= $quote_id_defaultC= do { croak("Error: No quote_identifier() function set.\n\tUse SQL::Yapp::quote_identifier() or SQL::Yapp::dbh().\n") }
ABCresult
1XX1
01X1
0011
0000
730 0 croak "Error: No quote_identifier() function set.\n".
731 "\tUse ".__PACKAGE__."::quote_identifier() or ".__PACKAGE__."::dbh().\n";
732 };
733 }
734  
735 ######################################################################
736 # Recursive Descent parser:
737  
738 # This is pure theory, because it will probably not occur, but:
739 #
740 # Assume:
741 # not b + c == not (b + c) ; just like in SQL
742 # a * b + c == (a * b) + c
743 #
744 # => a * not b + c == (a * not b) + c ; illegal in SQL for another reason, but
745 # ; still. Assume it was ok and numeric
746 # ; and boolean could be mixed at will.
747 #
748 # => parsing of the + sign is influenced not only by the immediate predecessor
749 # operator 'sin', but also by '*'.
750 #
751 # This is currently not so. Instead a * not b + c is parsed as a * not(b + c).
752 # I checked this with the Perl parser, which does the same:
753 #
754 # my $a= 1 && not 0 || 1; # ==> $a == 0
755 #
756 # Anyway, precedences are currently disabled, because of so much confusion, and
757 # particularly because of different precedences of the = operator in different
758 # positions.
759  
760 5 ▶use constant ASSOC_NON => undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
761 5 ▶use constant ASSOC_LEFT => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
762 5 ▶use constant ASSOC_RIGHT => +1;
Subroutine BEGIN: called CC=1 SCAR=0.0
763  
764 sub make_op($$;%)
765 461 ▶{
Subroutine make_op: called CC=6 SCAR=18.2
Pod undocumented
766 461 my ($value, $type, %opt)= @_;
767 461 ▶ my $read_value= $opt{read_value} || $value;
Condition66%2/3
$opt{'read_value'} || $value
l!l&&r!l&&!r
154460
MC/DC0%0/2
$opt{'read_value'} || $value
$opt{'read_value'} $value
Truth table66%2/3
A || B
A= $opt{'read_value'}B= $value
ABresult
1X1
011
000
768 461 ▶ my $read_type= $opt{read_type} || $type;
Condition66%2/3
$opt{'read_type'} || $type
l!l&&r!l&&!r
354260
MC/DC0%0/2
$opt{'read_type'} || $type
$opt{'read_type'} $type
Truth table66%2/3
A || B
A= $opt{'read_type'}B= $type
ABresult
1X1
011
000
769 my $result= {
770 read_value => $read_value,
771 value => $value,
772 value2 => $opt{value2}, # for infix3
773 read_type => $read_type, # how to parse?
774 type => $type, # how to print?
775 result0 => $opt{result0}, # for 'infix()' operators invoked with 0 arguments
776 # if undef => error to invoke with 0 arguments
777 prec => $opt{prec},
778 assoc => $opt{assoc},
779 rhs => $opt{rhs} || 'expr',
780 rhs_map => $opt{rhs_map} || {},
781 comparison => $opt{comparison}, # for checking ANY/SOME and ALL
782 dialect => $opt{dialect} || {},
783 accept => $opt{accept},
784 allow_when => $opt{allow_when},
785 461 ▶ };
Condition83%5/6
$opt{'rhs'} || 'expr'
l!l
70391
$opt{'rhs_map'} || {}
l!l
0461
$opt{'dialect'} || {}
l!l
60401
MC/DC100%1/1
$opt{'rhs'} || 'expr'
$opt{'rhs'}
MC/DC0%0/1
$opt{'rhs_map'} || {}
$opt{'rhs_map'}
MC/DC100%1/1
$opt{'dialect'} || {}
$opt{'dialect'}
Truth table100%2/2
A
A= $opt{'rhs'}
Aresult
11
00
Truth table50%1/2
A
A= $opt{'rhs_map'}
Aresult
11
00
Truth table100%2/2
A
A= $opt{'dialect'}
Aresult
11
00
786 461 lock_hash %$result;
787 461 return $result;
788 }
789  
790 sub declare_op($$;%)
791 385 ▶{
Subroutine declare_op: called CC=1 SCAR=0.0
Pod undocumented
792 385 my ($value, $type, %opt)= @_;
793 385 my $result= make_op($value, $type, %opt);
794 385 return ($result->{read_value} => $result);
795 }
796  
797 # There are two ways of normalising a functor:
798 # (a) Accepting a secondary form for an otherwise standard, and widely supported
799 # functor. Example: the power function. The std say it's called 'POWER',
800 # and this is how we want to always normalise it. To accept the MySQL form
801 # with infixed ^, use the read_value attribute:
802 #
803 # declare_op('POWER', 'funcall', ... read_value => '^');
804 #
805 # The 'dialect' hash keys should not defined were because there's a perfect
806 # normalisation for all dialects and accepting ^ is only a convenience.
807 #
808 # These normalisations will *always* be done.
809 #
810 # (b) Translating between non-standard or unavailable operators: here, we need
811 # to know which dialect we produce. It we don't, we keep what the user
812 # wrote and pass the syntax on as is. For translation, use the 'dialect'
813 # hash table to define how to write the operator in different output modes.
814 # if the output more is not found, the operator will not be touched:
815 #
816 # declare_op('||', 'infix()', ...
817 # dialect => {
818 # mysql => make_op('CONCAT', 'funcall')
819 # }
820 # ),
821 #
822 # If the current print dialect is not found, nothing is changed, otherwise
823 # the settings are taken from the corresponding hash entry. If a '-default'
824 # is given, then that one is used for default normalisation.
825 # If the value of a hash entry is 1 instead of a ref(), then the functor
826 # is not normalised for that dialect.
827 #
828 # For reducing input acception, use the 'accept' list: e.g. to accept the
829 # XOR operator only in MySQL and Postgres modes, use:
830 #
831 # declare_op('XOR', 'infix()', ... accept => [ 'mysql', 'postgresql' ]);
832 #
833 # ONLY restrict the input syntax if the input cannot be normalised in a
834 # standard way. Currently, we have no strict input mode: we only reject what
835 # cannot be rectified, regardless of %read_dialect, and that's the rule for now.
836 #
837 # Also note: you cannot freely switch type, but only if the number of
838 # parameters of the write type subsumes those of the read type:
839 #
840 # min max
841 # funcall 0 undef
842 # funcall1col 1 1 # one param which is a column name
843 # infix() 0/1 undef # min depends on whether result0 is set
844 # prefix 1 1
845 # prefixn 1 1 # never parens around param
846 # prefix1 1 1 # disallows point-wise application
847 # suffix 1 1
848 # infix2 2 2
849 # infix23 2 3
850 # infix3 3 3
851 #
852 # Note that all used symbolic operators must be known to token_scan_rec(),
853 # otherwise they are not correctly extracted from the input stream.
854  
855 #
856 # Missing:
857 #
858 # & | ~ (bit operations in MySQL)
859 #
860 # :: CAST (or TREAT?) in PostgreSQL
861 #
862  
863 # If the type is found in the following table, stringification will be
864 # handled by _prefix() and _suffix(). Otherwise, the compiled Perl
865 # code will already contain the logic of how to build the SQL command.
866 5 my %functor_kind= (
867 'infix()' => 'suffix',
868 'infix2' => 'suffix',
869 #'infix23' => 'suffix', # complex syntax, cannot be changed later, see funcsep
870 #'infix3' => 'suffix', # complex syntax, cannot be changed later, see funcsep
871  
872 'funcall' => 'prefix',
873 #'funcsep' => 'prefix', # complex syntax, currently not supported
874  
875 # Not built via _suffix() or _prefix():
876 #
877 # prefixn
878  
879 'suffix' => 'suffix', # applied point-wise, different from funcall
880 'prefix' => 'prefix', # applied point-wise, different from funcall
881 'funcall1' => 'prefix', # applied point-wise, different from funcall
882 'prefix()' => 'prefix', # not applied point-wise
883 );
884 5 my %functor_suffix= ( # for functors read in infix or suffix notation
885 # aliasses:
886 '==' => '=',
887 '!=' => '<>',
888  
889 # infix2 and infix():
890 declare_op('POWER', 'funcall', prec => 80, assoc => ASSOC_RIGHT,
891 read_value => '**', read_type => 'infix2'), # Oracle
892 #declare_op('POWER', 'funcall', prec => 80, assoc => ASSOC_RIGHT,
893 # read_value => '^', read_type => 'infix2'), # not MySQL
894 #declare_op('POWER', 'funcall', prec => 80, assoc => ASSOC_RIGHT
895 # read_value => ':', read_type => 'infix2'), # Postgres??
896  
897 # bitwise operators:
898 declare_op('^', 'infix()', result0 => 0,
899 assoc => ASSOC_LEFT,
900 dialect => {
901 oracle => make_op('BITXOR', 'funcall'),
902 }),
903  
904 declare_op('|', 'infix()', result0 => 0,
905 assoc => ASSOC_LEFT,
906 dialect => {
907 oracle => make_op('BITOR', 'funcall'),
908 }),
909  
910 declare_op('&', 'infix()', assoc => ASSOC_LEFT,
911 dialect => {
912 oracle => make_op('BITAND', 'funcall'),
913 }),
914  
915 # others:
916 declare_op('*', 'infix()', prec => 70, assoc => ASSOC_LEFT, result0 => 1),
917 declare_op('/', 'infix2', prec => 70, assoc => ASSOC_LEFT),
918  
919 declare_op('MOD', 'funcall', prec => 70, assoc => ASSOC_NON,
920 read_value => '%', read_type => 'infix2',), # MySQL, Postgres
921  
922 declare_op('+', 'infix()', prec => 60, assoc => ASSOC_LEFT, result0 => 0),
923 declare_op('-', 'infix2', prec => 60, assoc => ASSOC_LEFT),
924  
925 declare_op('=', 'infix2', prec => 50, assoc => ASSOC_NON, comparison => 1, allow_when => 1),
926 declare_op('<>', 'infix2', prec => 50, assoc => ASSOC_NON, comparison => 1, allow_when => 1),
927 declare_op('<', 'infix2', prec => 50, assoc => ASSOC_NON, comparison => 1, allow_when => 1),
928 declare_op('>', 'infix2', prec => 50, assoc => ASSOC_NON, comparison => 1, allow_when => 1),
929 declare_op('<=', 'infix2', prec => 50, assoc => ASSOC_NON, comparison => 1, allow_when => 1),
930 declare_op('>=', 'infix2', prec => 50, assoc => ASSOC_NON, comparison => 1, allow_when => 1),
931  
932 declare_op('AND', 'infix()', prec => 30, assoc => ASSOC_LEFT, result0 => 1),
933 declare_op('OR', 'infix()', prec => 30, assoc => ASSOC_LEFT, result0 => 0),
934  
935 declare_op('XOR', 'infix()', prec => 30, assoc => ASSOC_LEFT, result0 => 0,
936 accept => [ 'mysql', 'postgresql', 'oracle']),
937  
938 declare_op('||', 'infix()', assoc => ASSOC_LEFT, result0 => '',
939 dialect => {
940 mysql => make_op('CONCAT','funcall',result0 => ''),
941 }),
942  
943 declare_op('OVERLAPS', 'infix2', allow_when => 1),
944  
945 declare_op('IS DISTINCT FROM', 'infix2', allow_when => 1),
946  
947 declare_op('IS OF', 'infix2', rhs => 'type_list', allow_when => 1),
948 declare_op('IS NOT OF', 'infix2', rhs => 'type_list', allow_when => 1),
949  
950 declare_op('IN', 'infix2', rhs => 'expr_list', allow_when => 1),
951 declare_op('NOT IN', 'infix2', rhs => 'expr_list', allow_when => 1),
952  
953 # infix23
954 declare_op('NOT SIMILAR TO', 'infix23', value2 => 'ESCAPE', allow_when => 1),
955 declare_op('SIMILAR TO', 'infix23', value2 => 'ESCAPE', allow_when => 1),
956  
957 declare_op('LIKE', 'infix23', value2 => 'ESCAPE', allow_when => 1),
958 declare_op('NOT LIKE', 'infix23', value2 => 'ESCAPE', allow_when => 1),
959  
960 declare_op('CLIKE', 'infix23', value2 => 'ESCAPE', allow_when => 1),
961 declare_op('NOT CLIKE', 'infix23', value2 => 'ESCAPE', allow_when => 1),
962  
963 # infix3
964 declare_op('BETWEEN', 'infix3', value2 => 'AND', prec => 31, allow_when => 1),
965 declare_op('BETWEEN SYMMETRIC', 'infix3', value2 => 'AND', prec => 31, allow_when => 1),
966 declare_op('BETWEEN ASYMMETRIC', 'infix3', value2 => 'AND', prec => 31, allow_when => 1),
967 declare_op('NOT BETWEEN', 'infix3', value2 => 'AND', prec => 31, allow_when => 1),
968 declare_op('NOT BETWEEN SYMMETRIC', 'infix3', value2 => 'AND', prec => 31, allow_when => 1),
969 declare_op('NOT BETWEEN ASYMMETRIC', 'infix3', value2 => 'AND', prec => 31, allow_when => 1),
970  
971 # suffix
972 declare_op('IS NORMALIZED', 'suffix', prec => 45, allow_when => 1),
973 declare_op('IS NOT NORMALIZED', 'suffix', prec => 45, allow_when => 1),
974 declare_op('IS TRUE', 'suffix', prec => 45, allow_when => 1),
975 declare_op('IS NOT TRUE', 'suffix', prec => 45, allow_when => 1),
976 declare_op('IS FALSE', 'suffix', prec => 45, allow_when => 1),
977 declare_op('IS NOT FALSE', 'suffix', prec => 45, allow_when => 1),
978 declare_op('IS NULL', 'suffix', prec => 45, allow_when => 1),
979 declare_op('IS NOT NULL', 'suffix', prec => 45, allow_when => 1),
980 declare_op('IS UNKNOWN', 'suffix', prec => 45, allow_when => 1),
981 declare_op('IS NOT UNKNOWN', 'suffix', prec => 45, allow_when => 1),
982 declare_op('IS A SET', 'suffix', prec => 45, allow_when => 1),
983 declare_op('IS NOT A SET', 'suffix', prec => 45, allow_when => 1),
984 );
985  
986 5 my %functor_prefix= ( # functors read in prefix notation:
987 declare_op('+', 'prefix1', prec => 90, read_type => 'prefix'), # prefix1 disallows list context
988 declare_op('-', 'prefix', prec => 90),
989 declare_op('NOT', 'prefix', prec => 40),
990  
991 declare_op('~', 'prefix', dialect => { # MySQL
992 oracle => make_op('BITNOT', 'funcall'), # funcall1:
993 }),
994  
995 # Allow AND and OR as prefix operators.
996 # Because - and + are already defined, they are not translated this way.
997 declare_op('AND', 'prefix()',, read_type => 'prefix',
998 dialect => {
999 -default => make_op('AND', 'infix()', result0 => 1),
1000 }),
1001 declare_op('OR', 'prefix()', read_type => 'prefix',
1002 dialect => {
1003 -default => make_op('OR', 'infix()', result0 => 0),
1004 }),
1005  
1006 declare_op('BITXOR', 'funcall', assoc => ASSOC_LEFT,
1007 dialect => {
1008 mysql => make_op('^', 'infix()'),
1009 }),
1010 declare_op('BITOR', 'funcall', assoc => ASSOC_LEFT,
1011 dialect => {
1012 mysql => make_op('|', 'infix()'),
1013 }),
1014 declare_op('BITAND', 'funcall', assoc => ASSOC_LEFT,
1015 dialect => {
1016 mysql => make_op('&', 'infix()'),
1017 }),
1018  
1019 declare_op('POWER', 'funcall',
1020 read_value => 'POW'), # MySQL
1021  
1022 declare_op('CONCAT', 'funcall',
1023 dialect => {
1024 'mysql' => undef, # keep
1025 -default => make_op('||', 'infix()', result0 => ''),
1026 }),
1027  
1028 declare_op('CONCATENATE', 'funcall',
1029 dialect => {
1030 'mysql' => make_op('CONCAT', 'funcall'),
1031 -default => make_op('||', 'infix()', result0 => ''),
1032 }),
1033  
1034 declare_op('VALUES', 'funcall', accept => [ 'mysql' ], read_type => 'funcall1col'),
1035  
1036 # Funcalls with special separators instead of commas (who invented these??):
1037 # NOTE: These *must* start with (, otherwise they are even more special
1038 # than funcsep. Note that because of the hilarious syntax of UNNEST,
1039 # the closing paren is included in the rhs pattern.
1040 declare_op('CAST', 'funcsep',
1041 rhs => [ \q{expr}, 'AS', \q{type}, ')' ]),
1042  
1043 declare_op('TREAT', 'funcsep',
1044 rhs => [ \q{expr}, 'AS', \q{type}, ')' ]),
1045  
1046 declare_op('TRANSLATE', 'funcsep',
1047 rhs => [ \q{expr}, 'AS', \q{transliteration}, ')' ]),
1048  
1049 declare_op('POSITION','funcsep',
1050 rhs => [ \q{string_expr}, 'IN', \q{expr}, # hack for 'IN' infix op.
1051 [ 'USING', \q{char_unit} ], ')' ]),
1052  
1053 declare_op('SUBSTRING', 'funcsep',
1054 rhs => [ \q{expr}, 'FROM', \q{expr},
1055 [ 'FOR', \q{expr}], [ 'USING', \q{char_unit} ], ')' ]),
1056  
1057 declare_op('CHARACTER_LENGTH', 'funcsep',
1058 rhs => [ \q{expr}, [ 'USING', \q{char_unit} ], ')' ]),
1059  
1060 declare_op('CONVERT', 'funcsep',
1061 rhs => [ \q{expr}, 'USING', \q{transcoding}, ')' ]),
1062  
1063 declare_op('OVERLAY', 'funcsep',
1064 rhs => [ \q{expr}, 'PLACING', \q{expr}, 'FROM', \q{expr},
1065 [ 'FOR', \q{expr} ], [ 'USING', \q{char_unit} ], ')' ]),
1066  
1067 declare_op('EXTRACT', 'funcsep',
1068 rhs => [ \q{expr}, 'FROM', \q{expr}, ')']),
1069  
1070 declare_op('UNNEST', 'funcsep',
1071 rhs => [ \q{expr}, ')', [ 'WITH ORDINALITY' ] ]),
1072 );
1073  
1074 5 my %functor_special= ( # looked up manually, not generically.
1075 declare_op('ANY', 'prefixn'), # n=no paren. I know, it's lame.
1076 declare_op('SOME', 'prefixn'),
1077 declare_op('ALL', 'prefixn'),
1078 declare_op('DISTINCT', 'prefixn'),
1079 declare_op('DEFAULT', 'funcall', accept => [ 'mysql' ], read_type => 'funcall1col'),
1080 # Special functor because it collides with DEFAULT pseudo
1081 # constant, so it needs extra care during parsing.
1082 );
1083  
1084 # Reserved words from SQL-2003 spec:
1085 5 my @reserved= qw(
1086 ADD ALL ALLOCATE ALTER AND ANY ARE ARRAY AS ASENSITIVE ASYMMETRIC
1087 AT ATOMIC AUTHORIZATION BEGIN BETWEEN BIGINT BINARY BLOB BOOLEAN
1088 BOTH BY CALL CALLED CASCADED CASE CAST CHAR CHARACTER CHECK CLOB
1089 CLOSE COLLATE COLUMN COMMIT CONNECT CONSTRAINT CONTINUE
1090 CORRESPONDING CREATE CROSS CUBE CURRENT CURRENT_DATE
1091 CURRENT_DEFAULT_TRANSFORM_GROUP CURRENT_PATH CURRENT_ROLE
1092 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_TRANSFORM_GROUP_FOR_TYPE
1093 CURRENT_USER CURSOR CYCLE DATE DAY DEALLOCATE DEC DECIMAL DECLARE
1094 DEFAULT DELETE DEREF DESCRIBE DETERMINISTIC DISCONNECT DISTINCT
1095 DOUBLE DROP DYNAMIC EACH ELEMENT ELSE END END-EXEC ESCAPE EXCEPT
1096 EXEC EXECUTE EXISTS EXTERNAL FALSE FETCH FILTER FLOAT FOR FOREIGN
1097 FREE FROM FULL FUNCTION GET GLOBAL GRANT GROUP GROUPING HAVING
1098 HOLD HOUR IDENTITY IMMEDIATE IN INDICATOR INNER INOUT INPUT
1099 INSENSITIVE INSERT INT INTEGER INTERSECT INTERVAL INTO IS
1100 ISOLATION JOIN LANGUAGE LARGE LATERAL LEADING LEFT LIKE LOCAL
1101 LOCALTIME LOCALTIMESTAMP MATCH MEMBER MERGE METHOD MINUTE MODIFIES
1102 MODULE MONTH MULTISET NATIONAL NATURAL NCHAR NCLOB NEW NO NONE NOT
1103 NULL NUMERIC OF OLD ON ONLY OPEN OR ORDER OUT OUTER OUTPUT OVER
1104 OVERLAPS PARAMETER PARTITION PRECISION PREPARE PRIMARY PROCEDURE
1105 RANGE READS REAL RECURSIVE REF REFERENCES REFERENCING RELEASE
1106 RETURN RETURNS REVOKE RIGHT ROLLBACK ROLLUP ROW ROWS SAVEPOINT
1107 SCROLL SEARCH SECOND SELECT SENSITIVE SESSION_USER SET SIMILAR
1108 SMALLINT SOME SPECIFIC SPECIFICTYPE SQL SQLEXCEPTION SQLSTATE
1109 SQLWARNING START STATIC SUBMULTISET SYMMETRIC SYSTEM SYSTEM_USER
1110 TABLE THEN TIME TIMESTAMP TIMEZONE_HOUR TIMEZONE_MINUTE TO
1111 TRAILING TRANSLATION TREAT TRIGGER TRUE UNION UNIQUE UNKNOWN
1112 UNNEST UPDATE USER USING VALUE VALUES VARCHAR VARYING WHEN
1113 WHENEVER WHERE WINDOW WITH WITHIN WITHOUT YEAR
1114 );
1115 5 my %reserved= ( map { $_ => 1 } @reserved );
1116  
1117 sub double_quote_perl($)
1118 0 ▶{
Subroutine double_quote_perl: not called CC=1 SCAR=6.9
Pod undocumented
1119 0 my ($s)= @_;
1120 0 $s =~ s/([\\\"\$\@])/\\$1/g;
1121 0 $s =~ s/\t/\\t/g;
1122 0 $s =~ s/\n/\\n/g;
1123 0 $s =~ s/\r/\\r/g;
1124 0 $s =~ s/([\x00-\x1f\x7f])/sprintf("\\x%02x", ord($1))/gsex;
1125 0 return "\"$s\"";
1126 }
1127  
1128 sub single_quote_perl($)
1129 2884 ▶{
Subroutine single_quote_perl: called CC=1 SCAR=0.0
Pod undocumented
1130 2884 my ($s)= @_;
1131 2884 $s =~ s/([\\\'])/\\$1/g;
1132 2884 return "'$s'";
1133 }
1134  
1135 sub quote_perl($)
1136 3256 ▶{
Subroutine quote_perl: called CC=3 SCAR=11.1
Pod undocumented
1137 3256 my ($s)= @_;
1138 3256 ▶ return 'undef' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 372 2884 3256
1139 2884 ▶ return ($s =~ /[\x00-\x1f\x7f\']/) ? double_quote_perl($s) : single_quote_perl($s);
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /[\x00-\x1f\x7f\']/ ? : 0 2884 2884
1140 }
1141  
1142 sub skip_ws($)
1143 3558 ▶{
Subroutine skip_ws: called CC=4 SCAR=13.9
Pod undocumented
1144 3558 my ($lx)= @_;
1145 3558 my $s= $lx->{text_p};
1146  
1147 3558 for(;;) {
1148 6288 ▶ if ($$s =~ /\G\n/gc) { # count lines
Branch: 1 branch
BranchTrueFalseTotal
if ($$s =~ /\G\n/cg) 433 5855 6288
1149 433 $lx->{line}++;
1150 433 next;
1151 }
1152 5855 ▶ next if $$s =~ /\G[^\n\S]+/gc; # other space but newline
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G[^\n\S]+/cg 2278 3577 5855
1153 3577 ▶ next if $$s =~ /\G\#[^\n]*/gc; # comments
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G\#[^\n]*/cg 19 3558 3577
1154 3558 last;
1155 }
1156 }
1157  
1158 sub token_new($$;$%)
1159 3223 ▶{
Subroutine token_new: called CC=2 SCAR=7.0
Pod undocumented
1160 3223 my ($lx, $kind, $value, %opt)= @_;
1161 3223 ▶ my_confess unless $kind;
Branch: 1 branch
BranchTrueFalseTotal
unless $kind 0 3223 3223
1162 my $t= {
1163 lx => $lx,
1164 line => $lx->{line_before}, # start of token: rel. line num. in $lx->{text_p}
1165 line_after => $lx->{line},
1166 pos => $lx->{pos_before}, # start of token: string position in $lx->{text_p}
1167 3223 pos_after => pos(${ $lx->{text_p} }), # end of token: string position in $lx->{text_p}
1168 kind => $kind,
1169 value => $value,
1170 str => $opt{str},
1171 type => $opt{type}, # interproc: 'variable', 'block', 'num', etc.
1172 perltype => $opt{perltype}, # interproc: 'array', 'scalar', 'hash', 'list'
1173 prec => $opt{prec},
1174 error => $opt{error},
1175 3223 };
1176 3223 lock_keys %$t;
1177 3223 return $t;
1178 }
1179  
1180 sub token_describe($)
1181 1 ▶{
Subroutine token_describe: called CC=6 SCAR=18.0
Pod undocumented
1182 1 my ($t)= @_;
1183  
1184 1 my %opt= ();
1185 1 for my $key(qw(value str prec)) {
1186 3 ▶ if (defined $t->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t->{$key}) 1 2 3
1187 1 $opt{$key}= $t->{$key};
1188 }
1189 }
1190 1 for my $key(qw(perltype type)) {
1191 2 ▶ if ($t->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{$key}) 1 1 2
1192 1 $opt{$key}= $t->{$key};
1193 }
1194 }
1195  
1196 1 ▶ if (scalar(keys %opt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %opt) { } 1 0 1
1197 return "$t->{kind} (".
1198 join(", ",
1199 map {
1200 1 my $k= $_;
1201 2 "$k=".quote_perl($opt{$k})
1202 }
1203 sort keys %opt
1204 ).
1205 ")";
1206 }
1207 else {
1208 0 return quote_perl($t->{kind});
1209 }
1210 }
1211  
1212 sub error_new($$$)
1213 1 ▶{
Subroutine error_new: called CC=1 SCAR=0.0
Pod undocumented
1214 1 my ($lx, $value, $expl)= @_;
1215 1 return token_new ($lx, 'error', $value, str => $expl, error => 1);
1216 }
1217  
1218 sub syn_new($$$)
1219 2167 ▶{
Subroutine syn_new: called CC=1 SCAR=0.0
Pod undocumented
1220 2167 my ($lx, $type, $name)= @_;
1221 2167 return token_new ($lx, $name, undef, perltype => '', type => $type);
1222 # perltype and type are for * and ?, which can occur as
1223 # syntactic values in expressions.
1224 }
1225  
1226 sub interpol_new($$$$$)
1227 517 ▶{
Subroutine interpol_new: called CC=1 SCAR=0.0
Pod undocumented
1228 517 my ($lx, $interpol, $value, $type, $perltype)= @_;
1229 517 return token_new ($lx, "interpol$interpol", $value,
1230 type => $type,
1231 perltype => $perltype
1232 );
1233 }
1234  
1235 sub token_scan_codeblock($$)
1236 62 ▶{
Subroutine token_scan_codeblock: called CC=2 SCAR=7.0
Pod undocumented
1237 62 my ($lx, $interpol)= @_;
1238 62 my $s= $lx->{text_p};
1239  
1240 # Text::Balanced actually honours and updates pos($$s), so we can
1241 # interface directly:
1242 62 my ($ex)= Text::Balanced::extract_codeblock($$s, '{}()[]');
1243 return error_new($lx, 'codeblock', $@->{error})
1244 62 ▶ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 62 62
1245  
1246 62 $lx->{line}+= ($ex =~ tr/\n//);
1247 62 return interpol_new ($lx, $interpol, "do$ex", 'block', 'list');
1248 # $ex contains {}, so do$ex is sound.
1249 }
1250  
1251 sub token_scan_variable($$$)
1252 170 ▶{
Subroutine token_scan_variable: called CC=2 SCAR=7.0
Pod undocumented
1253 170 my ($lx, $interpol, $perltype)= @_;
1254 170 my $s= $lx->{text_p};
1255  
1256 170 my ($ex)= Text::Balanced::extract_variable($$s);
1257 return error_new($lx, 'variable', $@->{error})
1258 170 ▶ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 170 170
1259  
1260 170 $lx->{line}+= ($ex =~ tr/\n//);
1261 170 return interpol_new ($lx, $interpol, $ex, 'variable', $perltype);
1262 }
1263  
1264 sub token_scan_delimited($$$)
1265 50 ▶{
Subroutine token_scan_delimited: called CC=2 SCAR=7.0
Pod undocumented
1266 50 my ($lx, $interpol, $delim)= @_;
1267 50 my $s= $lx->{text_p};
1268  
1269 50 my ($ex)= Text::Balanced::extract_delimited($$s, $delim);
1270 return error_new($lx, 'delimited', $@->{error})
1271 50 ▶ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 50 50
1272  
1273 50 $lx->{line}+= ($ex =~ tr/\n//);
1274 50 return interpol_new ($lx, $interpol, $ex, 'string', 'scalar');
1275 }
1276  
1277 sub token_num_new($$$)
1278 235 ▶{
Subroutine token_num_new: called CC=2 SCAR=7.2
Pod undocumented
1279 235 my ($lx, $interpol, $value)= @_;
1280 235 ▶ return interpol_new ($lx, $interpol || 'Expr', $value, 'num', 'scalar');
Condition50%1/2
$interpol || 'Expr'
l!l
0235
MC/DC0%0/1
$interpol || 'Expr'
$interpol
Truth table50%1/2
A
A= $interpol
Aresult
11
00
1281 }
1282  
1283 sub ident_new($$)
1284 538 ▶{
Subroutine ident_new: called CC=1 SCAR=0.0
Pod undocumented
1285 538 my ($lx, $value)= @_;
1286 538 return token_new ($lx, 'ident', $value, perltype => 'scalar');
1287 }
1288  
1289 sub keyword_new($$) # either syn or function
1290 754 ▶{
Subroutine keyword_new: called CC=2 SCAR=6.9
Pod undocumented
1291 754 my ($lx, $name)= @_;
1292 754 ▶ if ($reserved{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reserved{$name}) { } 681 73 754
1293 681 return syn_new($lx, 'reserved', $name);
1294 }
1295 else {
1296 73 return syn_new($lx, 'keyword', $name);
1297 }
1298 }
1299  
1300 sub replace_synonym($)
1301 1268 ▶{
Subroutine replace_synonym: called CC=2 SCAR=6.9
Pod undocumented
1302 1268 my ($name)= @_;
1303 1268 ▶ while (my $syn= $synonym{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $syn = $synonym{$name}) 7 1268 1275
1304 7 $name= $syn;
1305 }
1306 1268 return $name;
1307 }
1308  
1309 sub multi_token_new($$)
1310 926 ▶{
Subroutine multi_token_new: called CC=4 SCAR=13.9
Pod undocumented
1311 926 my ($lx, $name)= @_;
1312 926 my $s= $lx->{text_p};
1313  
1314 926 $name= replace_synonym($name);
1315 926 ▶ if (my $tree= $multi_token{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tree = $multi_token{$name}) { } 172 754 926
1316 172 SUB_TOKEN: for (;;) {
1317 327 skip_ws($lx);
1318  
1319 327 my $p= pos($$s);
1320 327 ▶ last SUB_TOKEN unless $$s =~ /\G ([A-Z][A-Z_0-9]*)\b /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
unless $$s =~ /\G ([A-Z][A-Z_0-9]*)\b /cgsx 140 187 327
1321 187 my $sub_name= $1;
1322  
1323 187 $sub_name= replace_synonym($sub_name);
1324 187 $tree= $tree->{$sub_name};
1325 187 ▶ unless ($tree) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree) 32 155 187
1326 32 pos($$s)= $p; # unscan rejected keyword
1327 32 last SUB_TOKEN;
1328 }
1329  
1330 155 $name.= " $sub_name";
1331 155 $name= replace_synonym($name);
1332 }
1333 172 return syn_new ($lx, 'keyword', $name); # never a function, always a keyword
1334 }
1335 else {
1336 754 return keyword_new ($lx, $name);
1337 }
1338 }
1339  
1340 sub good_interpol_type($);
1341  
1342 sub token_scan_rec($$);
1343 sub token_scan_rec($$)
1344 3231 ▶{
Subroutine token_scan_rec: called CC=24 SCAR=32.1
Pod undocumented
1345 3231 my ($lx, $interpol)= @_;
1346 3231 my $s= $lx->{text_p};
1347  
1348 3231 skip_ws($lx);
1349  
1350 3231 $lx->{pos_before}= pos($$s);
1351 3231 $lx->{line_before}= $lx->{line}; # strings may contain \n, so this may change.
1352  
1353 # idents: distinguished by case:
1354 3231 ▶ return multi_token_new ($lx, $1) if $$s =~ /\G ([A-Z][A-Z_0-9]*)\b /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([A-Z][A-Z_0-9]*)\b /cgsx 926 2305 3231
1355 2305 ▶ return ident_new ($lx, $1) if $$s =~ /\G ([a-z][a-z_0-9]*)\b /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([a-z][a-z_0-9]*)\b /cgsx 538 1767 2305
1356 1767 ▶ return ident_new ($lx, $1) if $$s =~ /\G \`([^\n\\\`]+)\` /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G \`([^\n\\\`]+)\` /cgsx 0 1767 1767
1357  
1358 1767 ▶ if ($$s =~ /\G ([A-Z][a-z][A-Za-z0-9]*)\b /gcsx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$s =~ /\G ([A-Z][a-z][A-Za-z0-9]*)\b /cgsx) 8 1759 1767
1359 # type specifiers change the token context itself, so we recurse here.
1360 8 my $interpol_new= $1;
1361 8 ▶ return error_new ($lx, $interpol_new, 'unknown type cast')
Branch: 1 branch
BranchTrueFalseTotal
unless &good_interpol_type($interpol_new) 0 8 8
1362 unless good_interpol_type($interpol_new);
1363  
1364 8 ▶ return error_new ($lx, $interpol_new, 'duplicate type case')
Branch: 1 branch
BranchTrueFalseTotal
if $interpol 0 8 8
1365 if $interpol;
1366  
1367 8 my $tok= token_scan_rec ($lx, $interpol_new);
1368 8 ▶ return $tok if $tok->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"error"} 0 8 8
1369  
1370 return error_new ($lx, $tok->{kind},
1371 "Expected Perl interpolation after type cast to '$interpol_new'")
1372 8 ▶ unless $tok->{kind} =~ /^interpol/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->{"kind"} =~ /^interpol/ 0 8 8
1373  
1374 8 return $tok;
1375 }
1376  
1377 1759 ▶ return error_new ($lx, $1, 'illegal identifier: neither keyword nor name')
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([A-Za-z_][A-Za-z_0-9]*) /cgsx 0 1759 1759
1378 if $$s =~ /\G ([A-Za-z_][A-Za-z_0-9]*) /gcsx;
1379  
1380 # Numbers, strings, and embedded Perl code are handled alike: they will be
1381 # extracted as is and evaluated as is. This way, much of the embedded SQL
1382 # syntax is just like in Perl, and you don't face surprises. The uniform
1383 # kind of this token is 'interpol'. The precise type is stored in the
1384 # str attribute, in case anyone wants to know later.
1385  
1386 # numbers:
1387 ## ints:
1388 1759 ▶ return token_num_new ($lx, $interpol, hex($1)) if $$s =~ /\G 0x([0-9a-f_]+)\b /gcsix;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G 0x([0-9a-f_]+)\b /cgisx 1 1758 1759
1389 1758 ▶ return token_num_new ($lx, $interpol, oct($1)) if $$s =~ /\G (0b[0-1_]+)\b /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (0b[0-1_]+)\b /cgsx 1 1757 1758
1390 1757 ▶ return token_num_new ($lx, $interpol, $1) if $$s =~ /\G ([1-9][0-9_]*)\b /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([1-9][0-9_]*)\b /cgsx 216 1541 1757
1391 1541 ▶ return token_num_new ($lx, $interpol, oct($1)) if $$s =~ /\G ([0][0-7_]*)\b /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([0][0-7_]*)\b /cgsx 17 1524 1541
1392 # Note: oct() interprets 0b as binary, and there's not bin().
1393  
1394 1524 ▶ return token_num_new ($lx, $interpol, $1) if $$s =~ /\G ([1-9][0-9_]*)(?=[KMG]\b) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([1-9][0-9_]*)(?=[KMG]\b) /cgsx 0 1524 1524
1395 # special case for <large object length token>, which we split in two.
1396  
1397 ## floats:
1398 1524 ▶ return token_num_new ($lx, $interpol, $1)
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G( (?= [1-9] # not empty, but numeric | [.][0-9] ) (?: [1-9] [0-9_]* )? (?: [.] [0-9_]+ )? (?: e[-+] [0-9_]+ )?\b )/cgisx 0 1524 1524
1399 if $$s =~ /\G( (?= [1-9] # not empty, but numeric
1400 | [.][0-9]
1401 )
1402 (?: [1-9] [0-9_]* )?
1403 (?: [.] [0-9_]+ )?
1404 (?: e[-+] [0-9_]+ )?\b )/gcsix;
1405  
1406 1524 ▶ return error_new ($lx, $1, 'not a number')
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([0-9][a-z_0-9]*) /cgisx 0 1524 1524
1407 if $$s =~ /\G ([0-9][a-z_0-9]*) /gcsix;
1408  
1409 # embedded Perl:
1410 1524 ▶ return token_scan_variable ($lx, $interpol, 'scalar') if $$s =~ /\G (?= \$\S ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \$\S ) /cgsx 71 1453 1524
1411 1453 ▶ return token_scan_variable ($lx, $interpol, 'array') if $$s =~ /\G (?= \@\S ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \@\S ) /cgsx 71 1382 1453
1412 1382 ▶ return token_scan_variable ($lx, $interpol, 'hash') if $$s =~ /\G (?= \%[^\s\d] ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \%[^\s\d] ) /cgsx 28 1354 1382
1413 1354 ▶ return token_scan_codeblock ($lx, $interpol) if $$s =~ /\G (?= \{ ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \{ ) /cgsx 62 1292 1354
1414 1292 ▶ return token_scan_delimited ($lx, $interpol, $1) if $$s =~ /\G (?= [\'\"] ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= [\'\"] ) /cgsx 50 1242 1292
1415  
1416 # symbols:
1417 1242 ▶ return syn_new ($lx, 'symbol', $1)
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ m(\G( == | != | <= | >= | \&\& | \|\| | \! | \^\^ | \*\* | \^ | [-+*/;:,.()\[\]{}<=>?\%\&\|] ))cgsx 1201 41 1242
1418 if $$s =~ /\G(
1419 == | != | <= | >=
1420 | \&\& | \|\| | \! | \^\^
1421 | \*\* | \^
1422 | [-+*\/;:,.()\[\]{}<=>?\%\&\|]
1423 )/gcsx;
1424  
1425 # specials:
1426 41 ▶ return error_new ($lx, $1, 'Unexpected character') if $$s =~ /\G(.)/gcs;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G(.)/cgs 1 40 41
1427 40 return syn_new ($lx, 'special', '<EOF>');
1428 }
1429  
1430 sub token_scan($)
1431 3223 ▶{
Subroutine token_scan: called CC=1 SCAR=0.0
Pod undocumented
1432 3223 my ($lx)= @_;
1433 3223 my $t= token_scan_rec($lx, '');
1434 #print STDERR "DEBUG: scanned: ".token_describe($t)."\n";
1435 3223 return $t;
1436 }
1437  
1438 sub lexer_shift($)
1439 # returns the old token kind
1440 3223 ▶{
Subroutine lexer_shift: called CC=1 SCAR=0.0
Pod undocumented
1441 3223 my ($lx)= @_;
1442 3223 my $r= $lx->{token}{kind};
1443 3223 $lx->{token}= token_scan($lx);
1444 3223 return $r;
1445 }
1446  
1447 sub lexer_new($$$)
1448 280 ▶{
Subroutine lexer_new: called CC=1 SCAR=0.0
Pod undocumented
1449 280 my ($s, $file, $line_start)= \(@_);
1450 280 my $lx= {
1451 text_p => $s,
1452 token => undef,
1453 file => $$file,
1454 line_start => $$line_start, # relative start line of text in file
1455 line => 1, # current line (after current token)
1456 prev_line => 1, # end line of previous token (before white space)
1457 line_before => 1, # start line of current token (after white space)
1458 pos_before => 0, # pos($$s) at start of current token
1459 error => undef,
1460 };
1461 280 lock_keys %$lx;
1462 280 lexer_shift($lx);
1463 280 return $lx;
1464 }
1465  
1466 sub flatten($);
1467 sub flatten($)
1468 12156 ▶{
Subroutine flatten: called CC=4 SCAR=16.4
Pod undocumented
1469 12156 my ($x)= @_;
1470 12156 ▶ return $x
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 11264 892 12156
1471 unless ref($x);
1472  
1473 892 ▶ return map { flatten($_) } @$x
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "ARRAY" 892 0 892
1474 if ref($x) eq 'ARRAY';
1475  
1476 0 ▶ return flatten([ sort keys %$x ])
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "HASH" 0 0 0
1477 if ref($x) eq 'HASH';
1478  
1479 0 my_confess "No idea how to flatten $x";
1480 }
1481  
1482 sub flatten_hash($);
1483 sub flatten_hash($)
1484 8407 ▶{
Subroutine flatten_hash: called CC=1 SCAR=0.0
Pod undocumented
1485 8407 my ($x)= @_;
1486 8407 return map {$_ => 1} flatten $x;
1487 }
1488  
1489 sub looking_at_raw($$)
1490 9536 ▶{
Subroutine looking_at_raw: called CC=3 SCAR=11.0
Pod undocumented
1491 9536 my ($lx, $kind)= @_;
1492 9536 ▶ return unless $kind;
Branch: 1 branch
BranchTrueFalseTotal
unless $kind 1129 8407 9536
1493  
1494 8407 my %kind= flatten_hash $kind;
1495 return $lx->{token}{kind}
1496 8407 ▶ if $kind{$lx->{token}{kind}};
Branch: 1 branch
BranchTrueFalseTotal
if $kind{$lx->{"token"}{"kind"}} 1442 6965 8407
1497  
1498 6965 return; # Don't return undef, but an empty list, so in array context, we get 0 results
1499 # This principle is used everywhere in this file. In scalar context, we still
1500 # get undef from am empty list.
1501 }
1502  
1503 sub looking_at($$;$)
1504 9536 ▶{
Subroutine looking_at: called CC=3 SCAR=11.0
Pod undocumented
1505 9536 my ($lx, $kind, $do_shift)= @_;
1506 9536 ▶ if (my $x= looking_at_raw($lx,$kind)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = &looking_at_raw($lx, $kind)) 1442 8094 9536
1507 1442 ▶ lexer_shift($lx) if $do_shift;
Branch: 1 branch
BranchTrueFalseTotal
if $do_shift 1349 93 1442
1508 1442 return $x;
1509 }
1510 8094 return;
1511 }
1512  
1513 sub english_or(@)
1514 1 ▶{
Subroutine english_or: called CC=6 SCAR=21.6
Pod undocumented
1515 1 my $map= undef;
1516 1 ▶ $map= shift
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "CODE" 1 0 1
1517 if ref($_[0]) eq 'CODE';
1518  
1519 1 my @l= sort map flatten($_), @_;
1520  
1521 1 ▶ @l= map { $map->($_) } @l
Branch: 1 branch
BranchTrueFalseTotal
if $map 1 0 1
1522 if $map;
1523  
1524 1 ▶ return 'nothing' if scalar(@l) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @l == 0 0 1 1
1525 1 ▶ return $l[0] if scalar(@l) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @l == 1 1 0 1
1526 0 ▶ return "$l[0] or $l[1]" if scalar(@l) == 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @l == 2 0 0 0
1527  
1528 0 return join(", ", @l[0..$#l-1], "or $l[-1]");
1529 }
1530  
1531 sub expect($$;$)
1532 790 ▶{
Subroutine expect: called CC=3 SCAR=11.2
Pod undocumented
1533 790 my ($lx, $kind, $do_shift)= @_;
1534 790 ▶ if (my $x= looking_at($lx, $kind, $do_shift)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $x = &looking_at($lx, $kind, $do_shift)) { } 789 1 790
elsif (my $err = &lx_token_error($lx)) { } 0 1 1
1535 789 return $x;
1536 }
1537 elsif (my $err= lx_token_error($lx)) {
1538 0 $lx->{error}= $err;
1539 }
1540 else {
1541 $lx->{error}= 'Expected '.(english_or \&quote_perl, $kind).
1542 1 ', but found '.token_describe($lx->{token});
1543 }
1544 1 return;
1545 }
1546  
1547 # Parse Functions
1548 # ---------------
1549 # These functions return either:
1550 #
1551 # undef - in case of a syntax error
1552 # $lx->{error} will contain more information
1553 #
1554 # [...] - In case of a sequence of things (parse_list)
1555 #
1556 # {...} - In case of a successfully parsed item.
1557 # The hash contains a 'type' plus additional
1558 # slots depending on what was parsed.
1559 #
1560 # These things can be created with create().
1561 #
1562 # Note that tokens may be used here, too.
1563 #
1564 # Note: you cannot *try* to parse something and in case of a
1565 # failure, do something else, because pos() and the $lx->{token}
1566 # will have changed. E.g. when calling parse_list, you *must*
1567 # pass all things that might end a list instead of reading up
1568 # to an error. That's what the look-ahead token is for!
1569  
1570 sub create($$@)
1571 2622 ▶{
Subroutine create: called CC=2 SCAR=6.9
Pod undocumented
1572 2622 my ($lx, $kind, @more)= @_;
1573 my $r= {
1574 (ref($kind) ?
1575 (
1576 kind => $kind->[0],
1577 type => $kind->[1]
1578 )
1579 : (
1580 kind => $kind,
1581 type => ''
1582 )
1583 ),
1584 line => $lx->{token}{line},
1585 2622 ▶ map { $_ => undef } @more,
Branch: 1 branch
BranchTrueFalseTotal
ref $kind ? : 249 2373 2622
1586 };
1587 2622 lock_keys %$r;
1588 2622 return $r;
1589 }
1590  
1591 # special creates that occur frequently:
1592 sub create_Expr($)
1593 1034 ▶{
Subroutine create_Expr: called CC=1 SCAR=0.0
Pod undocumented
1594 1034 my ($lx)= @_;
1595 1034 return create ($lx, 'Expr', qw(maybe_check token functor arg switchval otherwise));
1596 }
1597  
1598 sub parse_list($$$$;$)
1599 # We allow multiple separators and also lists beginning with
1600 # separators, but we do not allow them to end with the same separator.
1601 # If a separator is encountered, we assume that the list continues.
1602  
1603 # There is one exception: if you specify an $end, then before the
1604 # $end, there may be too many separators. This is handy for
1605 # statements that often end in ; just before the closing }.
1606  
1607 # <EOF> is implicit treated as an $end in all invocations.
1608  
1609 # A token matching $end is not shifted.
1610 #
1611 # If $end is given, lists may be empty. Otherwise, they may
1612 # not be.
1613  
1614 # The result is either a list reference or undef in case
1615 # of an error. $lx->{error} will then be set accordingly.
1616 1233 ▶{
Subroutine parse_list: called CC=7 SCAR=19.5
Pod undocumented
1617 1233 my ($result, $lx, $parse_elem, $list_sep, $end)= @_;
1618  
1619 1233 my %pos= ();
1620 1233 ▶ ELEMENT: {do {
Branch: 1 branch
BranchTrueFalseTotal
&looking_at($lx, $list_sep, 1) and do { do { do { my $p = pos ${$$lx{"text_p"};}; die "BUG: pos() not shifted in list" if $pos{$p}++; last ELEMENT if &looking_at($lx, $end); last ELEMENT if &looking_at($lx, "<EOF>") } while &looking_at($lx, $list_sep, 1); return unless my(@result1) = &$parse_elem($lx); push @$result, @result1 } } 269 1221 1490
1621 1502 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
&looking_at($lx, $list_sep, 1) and do { do { my $p = pos ${$$lx{"text_p"};}; die "BUG: pos() not shifted in list" if $pos{$p}++; last ELEMENT if &looking_at($lx, $end); last ELEMENT if &looking_at($lx, "<EOF>") } } 9 1492 1501
1622 # check that we have no infinite loop:
1623 1511 my $p= pos(${ $lx->{text_p} });
1624 1511 ▶ die "BUG: pos() not shifted in list" if $pos{$p}++;
Branch: 1 branch
BranchTrueFalseTotal
if $pos{$p}++ 0 1511 1511
1625  
1626 # check for end:
1627 1511 ▶ last ELEMENT if looking_at($lx, $end);
Branch: 1 branch
BranchTrueFalseTotal
if &looking_at($lx, $end) 9 1502 1511
1628 1502 ▶ last ELEMENT if looking_at($lx, '<EOF>');
Branch: 1 branch
BranchTrueFalseTotal
if &looking_at($lx, "<EOF>") 1 1501 1502
1629  
1630 # allow too many separators:
1631 } while (looking_at($lx, $list_sep, SHIFT));
1632  
1633 # parse one element:
1634 return unless
1635 1492 ▶ my @result1= $parse_elem->($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my(@result1) = &$parse_elem($lx) 2 1490 1492
1636  
1637 # append that element to result:
1638 1490 push @$result, @result1;
1639  
1640 # check whether the list continues:
1641 } while (looking_at($lx, $list_sep, SHIFT))};
1642  
1643 1231 return $result;
1644 }
1645  
1646 sub parse_try_list($$$)
1647 # List without delimiter, but sequenced prefix-marked elements.
1648 # For example: a list of JOIN clauses.
1649 #
1650 # The parsers for such elements must handle try-parsing, i.e.,
1651 # returning undef while not setting $lx->{error} to indicate
1652 # that they are not looking at a prefix-marked element.
1653 159 ▶{
Subroutine parse_try_list: called CC=3 SCAR=11.0
Pod undocumented
1654 159 my ($result, $lx, $parse_elem)= @_;
1655  
1656 159 ▶ while (my @result1= $parse_elem->($lx)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@result1) = &$parse_elem($lx)) 55 159 214
1657 55 push @$result, @result1;
1658 }
1659  
1660 159 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 159 159
1661 159 return $result;
1662 }
1663  
1664 sub find_ref(\%$)
1665 # Finds a ref-valued value in a hash table, allowing redirections.
1666 # If nothing is found, '' is returned (which would never be returned
1667 # otherwise, because it is neither a ref(), nor undef).
1668 9673 ▶{
Subroutine find_ref: called CC=6 SCAR=17.9
Pod undocumented
1669 9673 my ($hash, $key)= @_;
1670 9673 my $result= undef;
1671 9673 local $SIG{__DIE__}= \&my_confess;
1672 9673 ▶ if (exists $hash->{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $hash->{$key}) { } 7601 2072 9673
elsif (exists $hash->{'-default'}) { } 1099 973 2072
1673 7601 $result= $hash->{$key}
1674 }
1675 elsif (exists $hash->{-default}) {
1676 $result= $hash->{-default}
1677 1099 }
1678 else {
1679 973 return '';
1680 }
1681  
1682 8700 ▶ until (ref($result) || !defined $result) { # No infinite loop protection!
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $result or not defined $result) 405 8700 9105
Condition100%3/3
ref $result or not defined $result
l!l&&r!l&&!r
86982405
MC/DC100%2/2
ref $result or not defined $result
ref $result not defined $result
Truth table100%3/3
A or not(B)
A= ref $resultB= not defined $result
ABresult
1X1
011
000
1683 die "'$result' key not in hash table"
1684 405 ▶ unless exists $hash->{$result};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$result} 0 405 405
1685 405 $result= $hash->{$result};
1686 }
1687  
1688 8700 return $result;
1689 }
1690  
1691 sub switch($%) # waiting for Perl 5.10: given/when/default
1692 8369 ▶{
Subroutine switch: called CC=2 SCAR=7.6
Pod undocumented
1693 8369 my ($value, %case)= @_;
1694 8369 ▶ if (my $code= find_ref(%case, $value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = &find_ref(\%case, $value)) 8369 0 8369
1695 8369 return $code->();
1696 }
1697  
1698 0 my_confess "Expected ".(english_or \&quote_perl, \%case).", but found '$value'";
1699 }
1700  
1701 sub lx_token_error($)
1702 2 ▶{
Subroutine lx_token_error: called CC=2 SCAR=6.9
Pod undocumented
1703 2 my ($lx)= @_;
1704 2 ▶ if ($lx->{token}{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{"token"}{"error"}) 1 1 2
1705 return 'Found '.
1706 quote_perl($lx->{token}{value}).': '.
1707 1 $lx->{token}{str};
1708 }
1709 1 return;
1710 }
1711  
1712 sub parse_choice($%)
1713 2304 ▶{
Subroutine parse_choice: called CC=1 SCAR=4.4
Pod undocumented
1714 2304 my ($lx, %opt)= @_;
1715 return switch ($lx->{token}{kind},
1716 0 ▶ -default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1717 0 ▶ if (my $err= lx_token_error($lx)) { # already have an error message.
Branch: 2 branches
BranchTrueFalseTotal
if (my $err = &lx_token_error($lx)) { } 0 0 0
elsif (scalar keys %opt > 10) { } 0 0 0
1718 0 $lx->{error}= 'In '.(caller(3))[3].": $err";
1719 }
1720 elsif (scalar(keys %opt) > 10) {
1721 $lx->{error}= 'In '.(caller(3))[3].': '.
1722 0 ' Unexpected '.token_describe($lx->{token});
1723 }
1724 else {
1725 $lx->{error}= 'In '.(caller(3))[3].': Expected '.
1726 (english_or \&quote_perl, \%opt).
1727 ', but found '.
1728 0 token_describe($lx->{token});
1729 }
1730 0 return;
1731 },
1732 2304 %opt, # may override -default
1733 );
1734 }
1735  
1736 sub parse_plain_ident($)
1737 553 ▶{
Subroutine parse_plain_ident: called CC=1 SCAR=0.1
Pod undocumented
1738 553 my ($lx)= @_;
1739 return parse_choice($lx,
1740 49 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.9
1741 49 my $r= $lx->{token};
1742  
1743 # If it is unambiguous, even "..." interpolation is intepreted as
1744 # a column name.
1745 #if (FORCE_STRING && $r->{type} eq 'string') {
1746 # $lx->{error}=
1747 # 'Expected identifier, but found string: '.token_describe($r).
1748 # "\n\t".
1749 # "If you want to construct an identifier name, use {$r->{value}}.";
1750 # return;
1751 #}
1752 #els
1753 49 ▶ if ($r->{type} eq 'num') {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"type"} eq "num") 0 49 49
1754 $lx->{error}=
1755 0 'Expected identifier, but found number: '.token_describe($r).
1756 "\n\t".
1757 "If you want to construct an identifier name, use {$r->{value}}.";
1758 0 return;
1759 }
1760  
1761 49 lexer_shift($lx);
1762 49 return $r;
1763 },
1764  
1765 'interpolColumn' => 'ident',
1766 'interpolTable' => 'ident',
1767 'interpolCharSet' => 'ident',
1768 'interpolEngine' => 'ident',
1769 'interpolCollate' => 'ident',
1770 'interpolConstraint' => 'ident',
1771 'interpolIndex' => 'ident',
1772 'interpolTranscoding' => 'ident',
1773 'interpolTransliteration' => 'ident',
1774 '*' => 'ident',
1775 504 ▶ 'ident' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1776 504 my $r= $lx->{token};
1777 504 lexer_shift($lx);
1778 504 return $r;
1779 },
1780 553 );
1781 }
1782  
1783 sub parse_ident_chain($$)
1784 520 ▶{
Subroutine parse_ident_chain: called CC=1 SCAR=0.0
Pod undocumented
1785 520 my ($lx, $arr)= @_;
1786 520 return parse_list($arr, $lx, \&parse_plain_ident, '.');
1787 }
1788  
1789 sub check_column(@)
1790 330 ▶{
Subroutine check_column: called CC=2 SCAR=6.9
Pod undocumented
1791 330 ▶ while (scalar(@_) < 4) { unshift @_, undef; }
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ < 4) 960 330 1290
1792 330 my ($cat,$sch,$tab,$col)= @_;
1793  
1794 #return unless !defined $cat || my $cat= $cat->{
1795 #check_ident ('Column', $cat, $sch, $tab, $col);
1796 }
1797  
1798 sub parse_column($;$)
1799 # The interpretation of the identifier chain is left to the column{1,2,3,4}
1800 # family of functions. It is as follows:
1801 #
1802 # Depending on the number of elements in the chain, the following types
1803 # are allowed:
1804 #
1805 # 1 Element:
1806 # - Column: a fully qualified column object, maybe including
1807 # a table specification
1808 # - ColumnName: a single identifier object with a column name
1809 # - string: a single identifier, too, will be quoted accordingly.
1810 #
1811 # 2 Elements:
1812 # - First element: Table or string
1813 # Last element: ColumnName or string
1814 #
1815 # more Elements:
1816 # - All but last element: string only
1817 # - Last element: ColumnName or string
1818 330 ▶{
Subroutine parse_column: called CC=5 SCAR=16.8
Pod undocumented
1819 330 my ($lx, $arr)= @_;
1820 330 my $r= create ($lx, 'Column', qw(ident_chain));
1821 330 ▶ $arr||= [];
Condition100%2/2
$arr ||= []
l!l
9321
MC/DC100%1/1
$arr ||= []
$arr
Truth table100%2/2
A
A= $arr
Aresult
11
00
1822 return
1823 330 ▶ unless parse_ident_chain($lx, $arr);
Branch: 1 branch
BranchTrueFalseTotal
unless &parse_ident_chain($lx, $arr) 0 330 330
1824  
1825 330 ▶ my_confess if scalar(@$arr) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$arr < 1 0 330 330
1826 330 ▶ if (scalar(@$arr) > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arr > 4) 0 330 330
1827 0 $lx->{error}= 'Too many parts of column identifier chain. '.
1828 'Maximum is 4, found '.scalar(@$arr);
1829 0 return;
1830 }
1831  
1832 330 check_column(@$arr);
1833  
1834 330 $r->{ident_chain}= $arr;
1835  
1836 330 lock_keys %$r;
1837 330 return $r;
1838 }
1839  
1840 sub parse_schema_qualified($$)
1841 190 ▶{
Subroutine parse_schema_qualified: called CC=4 SCAR=14.8
Pod undocumented
1842 190 my ($lx, $kind)= @_;
1843  
1844 190 my $r= create ($lx, $kind, qw(ident_chain));
1845 190 my $arr= [];
1846 return
1847 190 ▶ unless parse_ident_chain($lx, $arr);
Branch: 1 branch
BranchTrueFalseTotal
unless &parse_ident_chain($lx, $arr) 0 190 190
1848  
1849 190 ▶ my_confess if scalar(@$arr) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$arr < 1 0 190 190
1850 190 ▶ if (scalar(@$arr) > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arr > 3) 0 190 190
1851 0 $lx->{error}= 'Too many identifiers in $kind. '.
1852 'Maximum is 3, found '.scalar(@$arr);
1853 0 return;
1854 }
1855  
1856 190 $r->{ident_chain}= $arr;
1857  
1858 190 lock_keys %$r;
1859 190 return $r;
1860 }
1861  
1862 sub parse_table($)
1863 # The interpretation of the identifier chain is left to the table{1,2,3}
1864 # family of functions. It is as follows:
1865 #
1866 # Depending on the number of elements in the chain, the following types
1867 # are allowed:
1868 #
1869 # 1 Element:
1870 # - Table: a fully qualified table object
1871 # - string: a single identifier, too, will be quoted accordingly.
1872 #
1873 # more Elements:
1874 # - all elements: string
1875 172 ▶{
Subroutine parse_table: called CC=1 SCAR=0.0
Pod undocumented
1876 172 my ($lx)= @_;
1877 172 return parse_schema_qualified($lx, 'Table');
1878 }
1879  
1880 sub parse_charset($)
1881 7 ▶{
Subroutine parse_charset: called CC=1 SCAR=0.0
Pod undocumented
1882 7 my ($lx)= @_;
1883 7 return parse_schema_qualified($lx, 'CharSet');
1884 }
1885  
1886 sub parse_constraint($)
1887 7 ▶{
Subroutine parse_constraint: called CC=1 SCAR=0.0
Pod undocumented
1888 7 my ($lx)= @_;
1889 7 return parse_schema_qualified($lx, 'Constraint');
1890 }
1891  
1892 sub parse_index($)
1893 1 ▶{
Subroutine parse_index: called CC=1 SCAR=0.0
Pod undocumented
1894 1 my ($lx)= @_;
1895 1 return parse_schema_qualified($lx, 'Index');
1896 }
1897  
1898 sub parse_collate($)
1899 1 ▶{
Subroutine parse_collate: called CC=1 SCAR=0.0
Pod undocumented
1900 1 my ($lx)= @_;
1901 1 return parse_schema_qualified($lx, 'Collate');
1902 }
1903  
1904 sub parse_transliteration($)
1905 0 ▶{
Subroutine parse_transliteration: not called CC=1 SCAR=6.9
Pod undocumented
1906 0 my ($lx)= @_;
1907 0 return parse_schema_qualified($lx, 'Transliteration');
1908 }
1909  
1910 sub parse_transcoding($)
1911 0 ▶{
Subroutine parse_transcoding: not called CC=1 SCAR=6.9
Pod undocumented
1912 0 my ($lx)= @_;
1913 0 return parse_schema_qualified($lx, 'Transcoding');
1914 }
1915  
1916 sub parse_engine($)
1917 2 ▶{
Subroutine parse_engine: called CC=1 SCAR=0.0
Pod undocumented
1918 2 my ($lx)= @_;
1919 2 return parse_schema_qualified($lx, 'Engine');
1920 }
1921  
1922  
1923 sub parse_column_name($)
1924 49 ▶{
Subroutine parse_column_name: called CC=2 SCAR=6.9
Pod undocumented
1925 49 my ($lx)= @_;
1926 49 my $r= create ($lx, 'ColumnName', qw(token));
1927  
1928 parse_choice($lx,
1929 44 ▶ 'ident' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1930 44 $r->{type}= 'ident';
1931 44 $r->{token}= $lx->{token};
1932 44 lexer_shift($lx);
1933 },
1934  
1935 'interpolColumn' => 'interpol',
1936 5 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1937 5 $r->{type}= 'interpol';
1938 5 $r->{token}= $lx->{token};
1939 5 lexer_shift($lx);
1940 },
1941 49 );
1942 49 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 49 49
1943  
1944 49 lock_keys %$r;
1945 49 return $r;
1946 }
1947  
1948 sub parse_column_index($)
1949 2 ▶{
Subroutine parse_column_index: called CC=7 SCAR=20.2
Pod undocumented
1950 2 my ($lx)= @_;
1951 2 my $r= create ($lx, 'ColumnIndex', qw(name length desc));
1952  
1953 return unless
1954 2 ▶ $r->{name}= parse_column_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"name"} = &parse_column_name($lx) 0 2 2
1955  
1956 2 ▶ if (looking_at($lx, '(', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "(", 1)) 1 1 2
1957 return unless
1958 1 ▶ $r->{length}= parse_limit_expr($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"length"} = &parse_limit_expr($lx) and &expect($lx, ")", 1) 0 1 1
Condition33%1/3
$r->{"length"} = &parse_limit_expr($lx) and &expect($lx, ")", 1)
!ll&&!rl&&r
001
MC/DC0%0/2
$r->{"length"} = &parse_limit_expr($lx) and &expect($lx, ")", 1)
$r->{"length"} = &parse_limit_expr($lx) &expect($lx, ")", 1)
Truth table33%1/3
A and B
A= $r->{"length"} = &parse_limit_expr($lx)B= &expect($lx, ")", 1)
ABresult
0X0
100
111
1959 and expect ($lx, ')', SHIFT);
1960 }
1961  
1962 2 ▶ if (looking_at($lx, 'DESC', SHIFT)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looking_at($lx, 'DESC', 1)) { } 1 1 2
elsif (&looking_at($lx, 'ASC', 1)) { } 0 1 1
1963 1 $r->{desc}= 1;
1964 }
1965 elsif (looking_at($lx, 'ASC', SHIFT)) {
1966 #ignore
1967 }
1968  
1969 2 lock_hash %$r;
1970 2 return $r;
1971 }
1972  
1973 sub parse_table_name($)
1974 5 ▶{
Subroutine parse_table_name: called CC=2 SCAR=7.4
Pod undocumented
1975 5 my ($lx)= @_;
1976 5 my $r= create ($lx, 'TableName', qw(token));
1977  
1978 parse_choice($lx,
1979 5 ▶ 'ident' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1980 5 $r->{type}= 'ident';
1981 5 $r->{token}= $lx->{token};
1982 5 lexer_shift($lx);
1983 },
1984  
1985 'interpolTable' => 'interpol',
1986 0 ▶ 'interpol' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1987 0 $r->{type}= 'interpol';
1988 0 $r->{token}= $lx->{token};
1989 0 lexer_shift($lx);
1990 },
1991 5 );
1992 5 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 5 5
1993  
1994 5 lock_keys %$r;
1995 5 return $r;
1996 }
1997  
1998 sub parse_table_as($)
1999 128 ▶{
Subroutine parse_table_as: called CC=7 SCAR=19.9
Pod undocumented
2000 128 my ($lx)= @_;
2001 128 my $r= create ($lx, 'TableAs', qw(table as));
2002  
2003 128 ▶ if (looking_at($lx, '(', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '(', 1)) { } 2 126 128
2004 2 my $stmt;
2005 return unless
2006 2 ▶ $stmt= parse_select_stmt($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless $stmt = &parse_select_stmt($lx) and &expect($lx, ")", 1) 0 2 2
Condition33%1/3
$stmt = &parse_select_stmt($lx) and &expect($lx, ")", 1)
!ll&&!rl&&r
002
MC/DC0%0/2
$stmt = &parse_select_stmt($lx) and &expect($lx, ")", 1)
$stmt = &parse_select_stmt($lx) &expect($lx, ")", 1)
Truth table33%1/3
A and B
A= $stmt = &parse_select_stmt($lx)B= &expect($lx, ")", 1)
ABresult
0X0
100
111
2007 and expect ($lx, ')', SHIFT);
2008  
2009 2 my $s= create_Expr ($lx);
2010 2 $s->{type}= 'subquery';
2011 2 $s->{arg}= $stmt;
2012  
2013 2 $r->{table} = $s;
2014 }
2015 else {
2016 return unless
2017 126 ▶ $r->{table}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_table($lx) 0 126 126
2018 }
2019  
2020 128 ▶ if (looking_at($lx, 'AS', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "AS", 1)) 5 123 128
2021 return unless
2022 5 ▶ $r->{as}= parse_table_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"as"} = &parse_table_name($lx) 0 5 5
2023 }
2024  
2025 128 lock_hash %$r;
2026 128 return $r;
2027 }
2028  
2029 sub parse_value_or_column_into($$$)
2030 173 ▶{
Subroutine parse_value_or_column_into: called CC=2 SCAR=6.9
Pod undocumented
2031 173 my ($lx, $r, $type)= @_;
2032  
2033 173 my $token= $lx->{token};
2034 173 lexer_shift($lx);
2035  
2036 173 ▶ if (looking_at($lx, '.')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '.')) { } 9 164 173
2037 9 $r->{type}= 'column';
2038 9 $r->{arg}= parse_column($lx, [ $token ]);
2039 }
2040 else {
2041 164 $r->{type}= $type;
2042 164 $r->{token}= $token;
2043 }
2044 }
2045  
2046 sub parse_expr($;$$);
2047 sub parse_select_stmt($);
2048 sub parse_funcsep($$$);
2049 sub parse_expr_post($$$$);
2050  
2051 5 ▶use constant ACTION_AMBIGUOUS => undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
2052 5 ▶use constant ACTION_REDUCE => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2053 5 ▶use constant ACTION_SHIFT => +1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2054  
2055 sub plural($;$$)
2056 0 ▶{
Subroutine plural: not called CC=4 SCAR=30.0
Pod undocumented
2057 0 my ($cnt, $sg, $pl)= @_;
2058 0 ▶ return $cnt == 1 ? (defined $sg ? $sg : '') : (defined $pl ? $pl : 's');
Branch: 3 branches
BranchTrueFalseTotal
$cnt == 1 ? : 0 0 0
defined $sg ? : 0 0 0
defined $pl ? : 0 0 0
2059 }
2060  
2061 sub parse_limit_expr($)
2062 24 ▶{
Subroutine parse_limit_expr: called CC=2 SCAR=7.0
Pod undocumented
2063 24 my ($lx)= @_;
2064 return unless
2065 24 ▶ my $limit= parse_limit_num($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $limit = &parse_limit_num($lx) 0 24 24
2066 24 my $r= create_Expr ($lx);
2067 24 $r->{type}= 'limit';
2068 24 $r->{arg}= $limit;
2069 24 lock_hash %$r;
2070 24 return $r;
2071 }
2072  
2073 sub parse_char_unit($)
2074 1 ▶{
Subroutine parse_char_unit: called CC=1 SCAR=0.0
Pod undocumented
2075 1 my ($lx)= @_;
2076 1 my $r= create($lx, 'CharUnit', qw(name));
2077 1 $r->{name}= expect($lx, ['CHARACTERS', 'CODE_UNITS', 'OCTETS'], SHIFT);
2078 1 lock_hash %$r;
2079 1 return $r;
2080 }
2081  
2082 sub parse_list_delim($$)
2083 59 ▶{
Subroutine parse_list_delim: called CC=4 SCAR=17.1
Pod undocumented
2084 59 my ($lx, $func)= @_;
2085 return unless
2086 59 ▶ expect($lx, '(', SHIFT)
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "(", 1) and my $list = &parse_list(scalar [], $lx, $func, ",", ")") and &expect($lx, ")", 1) 0 59 59
Condition33%2/6
&expect($lx, "(", 1) and my $list = &parse_list(scalar [], $lx, $func, ",", ")") and &expect($lx, ")", 1)
!ll&&!rl&&r
0059
&expect($lx, "(", 1) and my $list = &parse_list(scalar [], $lx, $func, ",", ")")
!ll&&!rl&&r
0059
MC/DC0%0/3
&expect($lx, "(", 1) and my $list = &parse_list(scalar [], $lx, $func, ",", ")") and &expect($lx, ")", 1)
&expect($lx, "(", 1) my $list = &parse_list(scalar [], $lx, $func, ",", ")") &expect($lx, ")", 1)
Truth table25%1/4
A and B and C
A= &expect($lx, "(", 1)B= my $list = &parse_list(scalar [], $lx, $func, ",", ")")C= &expect($lx, ")", 1)
ABCresult
0XX0
10X0
1100
1111
2087 and my $list= parse_list([], $lx, $func, ',', ')')
2088 and expect($lx, ')', SHIFT);
2089 59 return $list;
2090 }
2091  
2092 sub parse_type_post_inner($)
2093 106 ▶{
Subroutine parse_type_post_inner: called CC=1 SCAR=0.9
Pod undocumented
2094 106 my ($lx)= @_;
2095  
2096 106 my $functor= undef;
2097 106 my @arg= ();
2098 parse_choice ($lx,
2099 73 ▶ -default => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
2100 73 ▶ if (my $spec= find_ref(%type_spec, $lx->{token}{kind})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = &find_ref(\%type_spec, $lx->{"token"}{"kind"})) 27 46 73
2101 27 ▶ if ($spec->{value_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'value_list'}) { } 1 26 27
2102 1 $functor= 'basewlist',
2103 push @arg, lexer_shift($lx);
2104 return unless
2105 1 ▶ my $value_list= parse_list_delim($lx, \&parse_expr);
Branch: 1 branch
BranchTrueFalseTotal
unless my $value_list = &parse_list_delim($lx, \&SQL::Yapp::parse_expr) 0 1 1
2106 1 push @arg, @$value_list;
2107 }
2108 else {
2109 26 $functor= 'base';
2110 26 push @arg, lexer_shift($lx);
2111 }
2112 }
2113 },
2114  
2115 'UNSIGNED' => 'SIGNED',
2116 1 ▶ 'SIGNED' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2117 1 $functor= 'property';
2118 1 push @arg, 'sign', lexer_shift($lx);
2119 },
2120 0 ▶ 'DROP SIGN' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2121 0 $functor= 'property';
2122 0 push @arg, 'sign', '';
2123 0 lexer_shift($lx);
2124 },
2125  
2126 1 ▶ 'ZEROFILL' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2127 1 $functor= 'property';
2128 1 push @arg, 'zerofill', lexer_shift($lx);
2129 },
2130  
2131 0 ▶ 'DROP ZEROFILL' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2132 0 $functor= 'property';
2133 0 push @arg, 'zerofill', '';
2134 0 lexer_shift($lx);
2135 },
2136  
2137 0 ▶ 'ASCII' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2138 0 my $cs= create($lx, 'CharSet', qw(token));
2139 0 $cs->{token}= ident_new($lx, 'latin1');
2140 0 $functor= 'property';
2141 0 push @arg, 'charset', $cs;
2142 0 lexer_shift($lx);
2143 },
2144 0 ▶ 'UNICODE' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2145 0 my $cs= create($lx, 'CharSet', qw(token));
2146 0 $cs->{token}= ident_new($lx, 'ucs2');
2147 0 $functor= 'property';
2148 0 push @arg, 'charset', $cs;
2149 0 lexer_shift($lx);
2150 },
2151 4 ▶ 'CHARACTER SET' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
2152 4 lexer_shift($lx);
2153 return unless
2154 4 ▶ my $arg= parse_charset($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_charset($lx) 0 4 4
2155 4 $functor= 'property';
2156 4 push @arg, 'charset', $arg;
2157 },
2158 3 ▶ 'DROP CHARACTER SET' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2159 3 $functor= 'property';
2160 3 push @arg, 'charset', '';
2161 3 lexer_shift($lx);
2162 },
2163  
2164 1 ▶ 'COLLATE' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
2165 1 lexer_shift($lx);
2166 return unless
2167 1 ▶ my $arg= parse_collate($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_collate($lx) 0 1 1
2168 1 $functor= 'property';
2169 1 push @arg, 'collate', $arg;
2170 },
2171 0 ▶ 'DROP COLLATE' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2172 0 $functor= 'property';
2173 0 push @arg, 'collate', '';
2174 0 lexer_shift($lx);
2175 },
2176  
2177 'WITH LOCAL TIME ZONE' => 'WITH TIME ZONE',
2178 'WITHOUT TIME ZONE' => 'WITH TIME ZONE',
2179 0 ▶ 'WITH TIME ZONE' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2180 0 $functor= 'property';
2181 0 push @arg, 'timezone', lexer_shift($lx);
2182 },
2183  
2184 0 ▶ 'DROP TIME ZONE' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2185 0 $functor= 'property';
2186 0 push @arg, 'timezone', '';
2187 0 lexer_shift($lx);
2188 },
2189  
2190 23 ▶ '(' => sub {
Subroutine __ANON__: called CC=4 SCAR=17.2
2191 23 lexer_shift($lx);
2192 return unless
2193 23 ▶ my $list= parse_list ([], $lx, \&parse_limit_expr, ',', ')');
Branch: 1 branch
BranchTrueFalseTotal
unless my $list = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_limit_expr, ",", ")") 0 23 23
2194  
2195 parse_choice($lx,
2196 'K' => 'G',
2197 'M' => 'G',
2198 1 ▶ 'G' => sub {
Subroutine __ANON__: called CC=4 SCAR=15.8
2199 1 ▶ if (scalar(@$list) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 1) 0 1 1
2200 0 $lx->{error}= "At most one value in () expected, but found ".scalar($list);
2201 0 return;
2202 }
2203  
2204 1 $functor= 'largelength';
2205 1 push @arg, $list->[0];
2206  
2207 1 push @arg, lexer_shift($lx);
2208  
2209 1 ▶ if (looking_at($lx, ')')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ')')) { } 0 1 1
2210 0 push @arg, '';
2211 }
2212 else {
2213 return unless
2214 1 ▶ my $unit= parse_char_unit($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $unit = &parse_char_unit($lx) 0 1 1
2215  
2216 1 push @arg, $unit;
2217 }
2218 },
2219  
2220 0 ▶ 'ident' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2221 0 ▶ if (scalar(@$list) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 1) 0 0 0
2222 0 $lx->{error}= "At most one value in () expected, but found ".scalar($list);
2223 0 return;
2224 }
2225  
2226 0 $functor= 'largelength';
2227 0 push @arg, '';
2228  
2229 },
2230  
2231 22 ▶ -default => sub {
Subroutine __ANON__: called CC=2 SCAR=8.4
2232 22 ▶ if (scalar(@$list) > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 2) 0 22 22
2233 0 $lx->{error}= "At most two values in () expected, but found ".scalar($list);
2234 0 return;
2235 }
2236  
2237 22 $functor= 'length';
2238 22 push @arg, @$list;
2239 }
2240 23 );
2241 23 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 23 23
2242 23 ▶ return unless expect($lx, ')', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, ")", 1) 0 23 23
2243 },
2244 106 );
2245  
2246 106 return ($functor, \@arg);
2247 }
2248  
2249 sub parse_type_post($$);
2250 sub parse_type_post($$)
2251 86 ▶{
Subroutine parse_type_post: called CC=3 SCAR=11.0
Pod undocumented
2252 86 my ($lx, $base)= @_;
2253 86 my $r= create($lx, 'TypePost', qw(base functor arg));
2254 86 $r->{base}= $base;
2255  
2256 86 ($r->{functor}, $r->{arg})= parse_type_post_inner($lx);
2257 return
2258 86 ▶ if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 86 86
2259  
2260 return $base
2261 86 ▶ unless defined $r->{functor};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"functor"} 30 56 86
2262  
2263 56 return parse_type_post ($lx, $r);
2264 }
2265  
2266 sub parse_type($)
2267 30 ▶{
Subroutine parse_type: called CC=3 SCAR=11.1
Pod undocumented
2268 30 my ($lx)= @_;
2269 30 my $r= create($lx, 'Type', qw(base token));
2270  
2271 30 ▶ if (looking_at($lx, ['interpol', 'interpolType'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ['interpol', 'interpolType'])) { } 8 22 30
2272 8 $r->{type}= 'interpol';
2273 8 $r->{token}= $lx->{token};
2274 8 lexer_shift($lx);
2275 }
2276 else {
2277 22 ▶ unless ($type_spec{$lx->{token}{kind}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type_spec{$lx->{"token"}{"kind"}}) 0 22 22
2278 0 $lx->{error}= 'Expected type name, but found '.token_describe($lx->{token});
2279 0 return;
2280 }
2281 22 $r->{type}= 'base';
2282 22 $r->{base}= $lx->{token}{kind};
2283 }
2284  
2285 30 lock_hash %$r;
2286 30 return parse_type_post ($lx, $r);
2287 }
2288  
2289 sub parse_type_list($) # without enclosing (...)
2290 1 ▶{
Subroutine parse_type_list: called CC=2 SCAR=7.0
Pod undocumented
2291 1 my ($lx)= @_;
2292 return unless
2293 1 ▶ my $arg= parse_list ([], $lx, \&parse_type, ',', ')');
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_type, ",", ")") 0 1 1
2294  
2295 1 my $r= create ($lx, ['TypeList','explicit'], qw(arg));
2296 1 $r->{arg}= $arg;
2297 1 lock_hash %$r;
2298 1 return $r;
2299 }
2300  
2301 sub parse_type_list_delim($) # with enclosing (...)
2302 1 ▶{
Subroutine parse_type_list_delim: called CC=1 SCAR=1.4
Pod undocumented
2303 1 my ($lx)= @_;
2304  
2305 return parse_choice($lx,
2306 1 ▶ '(' => sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
2307 1 lexer_shift($lx);
2308 return unless
2309 1 ▶ my $r= parse_type_list ($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless my $r = &parse_type_list($lx) and &expect($lx, ")", 1) 0 1 1
Condition33%1/3
my $r = &parse_type_list($lx) and &expect($lx, ")", 1)
!ll&&!rl&&r
001
MC/DC0%0/2
my $r = &parse_type_list($lx) and &expect($lx, ")", 1)
my $r = &parse_type_list($lx) &expect($lx, ")", 1)
Truth table33%1/3
A and B
A= my $r = &parse_type_list($lx)B= &expect($lx, ")", 1)
ABresult
0X0
100
111
2310 and expect ($lx, ')', SHIFT);
2311 1 return $r;
2312 },
2313  
2314 0 ▶ 'interpol' => sub { # Perl array reference:
Subroutine __ANON__: not called CC=1 SCAR=6.9
2315 0 my $r= create ($lx, ['TypeList','interpol'], qw(token));
2316 0 $r->{token}= $lx->{token};
2317 0 lexer_shift($lx);
2318 0 lock_hash %$r;
2319 0 return $r;
2320 },
2321 1 );
2322 }
2323  
2324 sub parse_on_action($)
2325 1 ▶{
Subroutine parse_on_action: called CC=1 SCAR=0.0
Pod undocumented
2326 1 my ($lx)= @_;
2327 1 return looking_at($lx, ['RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT', 'NO ACTION'], SHIFT);
2328 }
2329  
2330 sub parse_references($)
2331 3 ▶{
Subroutine parse_references: called CC=5 SCAR=17.6
Pod undocumented
2332 3 my ($lx)= @_;
2333 3 my $r= create($lx, 'References', qw(table column match on_delete on_update));
2334  
2335 3 lexer_shift($lx);
2336  
2337 return unless
2338 $r->{table}= parse_table($lx)
2339 3 ▶ and $r->{column}= parse_list_delim($lx, \&parse_column_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_table($lx) and $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name) 0 3 3
Condition33%1/3
$r->{"table"} = &parse_table($lx) and $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name)
!ll&&!rl&&r
003
MC/DC0%0/2
$r->{"table"} = &parse_table($lx) and $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name)
$r->{"table"} = &parse_table($lx) $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name)
Truth table33%1/3
A and B
A= $r->{"table"} = &parse_table($lx)B= $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name)
ABresult
0X0
100
111
2340  
2341 3 ▶ if (looking_at($lx, 'MATCH', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "MATCH", 1)) 1 2 3
2342 1 $r->{match}= expect ($lx, ['FULL','PARTIAL','SINGLE'], SHIFT);
2343 }
2344  
2345 4 ▶ parse_try_list([], $lx, sub {
Subroutine __ANON__: called CC=1 SCAR=1.6
2346 parse_choice($lx,
2347 1 ▶ 'ON DELETE' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
2348 1 lexer_shift($lx);
2349 return unless
2350 1 ▶ $r->{on_delete}= parse_on_action($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"on_delete"} = &parse_on_action($lx) 0 1 1
2351 },
2352 0 ▶ 'ON UPDATE' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2353 0 lexer_shift($lx);
2354 return unless
2355 0 ▶ $r->{on_update}= parse_on_action($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"on_update"} = &parse_on_action($lx) 0 0 0
2356 },
2357 3 ▶ -default => sub {}
Subroutine __ANON__: called CC=1 SCAR=0.0
2358 4 );
2359 3 });
2360 3 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 3 3
2361  
2362 3 lock_hash %$r;
2363 3 return $r;
2364 }
2365  
2366 sub parse_column_spec_post_inner($)
2367 38 ▶{
Subroutine parse_column_spec_post_inner: called CC=4 SCAR=20.9
Pod undocumented
2368 38 my ($lx)= @_;
2369 38 my $functor= undef;
2370 38 my @arg= ();
2371  
2372 38 my $constraint= undef;
2373 38 ▶ if (looking_at($lx, 'CONSTRAINT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "CONSTRAINT", 1)) 2 36 38
2374 return unless
2375 2 ▶ $constraint= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $constraint = &parse_constraint($lx) 0 2 2
2376 }
2377  
2378 parse_choice($lx,
2379 20 ▶ -default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
2380 20 ▶ if ($constraint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constraint) { } 0 20 20
2381 0 $lx->{error}= 'Constraint expected';
2382 }
2383 else {
2384 20 my ($func, $arg)= parse_type_post_inner($lx); # inherit column type post
2385 20 ▶ if ($func) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func) 4 16 20
2386 4 $functor= "type_$func";
2387 4 @arg= @$arg;
2388 }
2389 }
2390 },
2391 10 ▶ 'NOT NULL' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2392 10 $functor= 'property';
2393 10 push @arg, $constraint, 'notnull', lexer_shift($lx);
2394 },
2395 0 ▶ 'NULL' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2396 0 $functor= 'property';
2397 0 push @arg, $constraint, 'notnull', '';
2398 0 lexer_shift($lx);
2399 },
2400  
2401 0 ▶ 'AUTO_INCREMENT' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2402 0 $functor= 'property';
2403 0 push @arg, $constraint, 'autoinc', lexer_shift($lx);
2404 },
2405 0 ▶ 'DROP AUTO_INCREMENT' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2406 0 $functor= 'property';
2407 0 push @arg, $constraint, 'autoinc', '';
2408 0 lexer_shift($lx);
2409 },
2410  
2411 1 ▶ 'UNIQUE' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2412 1 $functor= 'property';
2413 1 push @arg, $constraint, 'unique', lexer_shift($lx);
2414 },
2415 0 ▶ 'DROP UNIQUE' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2416 0 $functor= 'property';
2417 0 push @arg, $constraint, 'unique', '';
2418 0 lexer_shift($lx);
2419 },
2420  
2421 0 ▶ 'PRIMARY KEY' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2422 0 $functor= 'property';
2423 0 push @arg, $constraint, 'primary', lexer_shift($lx);
2424 },
2425 0 ▶ 'DROP PRIMARY KEY' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2426 0 $functor= 'property';
2427 0 push @arg, $constraint, 'primary', '';
2428 0 lexer_shift($lx);
2429 },
2430  
2431 0 ▶ 'KEY' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2432 0 $functor= 'property';
2433 0 push @arg, $constraint, 'key', lexer_shift($lx);
2434 },
2435 0 ▶ 'DROP KEY' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2436 0 $functor= 'property';
2437 0 push @arg, $constraint, 'key', '';
2438 0 lexer_shift($lx);
2439 },
2440  
2441 6 ▶ 'DEFAULT' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
2442 6 lexer_shift($lx);
2443 return unless
2444 6 ▶ my $val= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $val = &parse_expr($lx) 0 6 6
2445 6 $functor= 'property';
2446 6 push @arg, $constraint, 'default', $val;
2447 },
2448 0 ▶ 'DROP DEFAULT' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2449 0 lexer_shift($lx);
2450 0 $functor= 'property';
2451 0 push @arg, $constraint, 'default', '';
2452 },
2453  
2454 0 ▶ 'CHECK' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2455 0 lexer_shift($lx);
2456 return unless
2457 0 ▶ my $val= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $val = &parse_expr($lx) 0 0 0
2458 0 $functor= 'property';
2459 0 push @arg, $constraint, 'check', $val;
2460 },
2461 0 ▶ 'DROP CHECK' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2462 0 lexer_shift($lx);
2463 0 $functor= 'property';
2464 0 push @arg, $constraint, 'check', '';
2465 },
2466  
2467 ($read_dialect{mysql} ?
2468 (
2469 0 ▶ 'COMMENT' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2470 0 lexer_shift($lx);
2471 return unless
2472 0 ▶ my $val= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $val = &parse_expr($lx) 0 0 0
2473 0 $functor= 'property';
2474 0 push @arg, $constraint, 'comment', $val;
2475 },
2476 0 ▶ 'DROP COMMENT' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2477 0 lexer_shift($lx);
2478 0 $functor= 'property';
2479 0 push @arg, $constraint, 'comment', '';
2480 },
2481 0 ▶ 'COLUMN_FORMAT' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2482 0 lexer_shift($lx);
2483 0 $functor= 'property';
2484 0 push @arg, $constraint, 'column_format',
2485 expect($lx, ['FIXED','DYNAMIC','DEFAULT'], SHIFT);
2486 },
2487 0 ▶ 'STORAGE' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2488 0 lexer_shift($lx);
2489 0 $functor= 'property';
2490 0 push @arg, $constraint, 'storage',
2491 expect($lx, ['DISK','MEMORY','DEFAULT'], SHIFT);
2492 }
2493 )
2494 : ()
2495 ),
2496  
2497 1 ▶ 'REFERENCES' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
2498 return unless
2499 1 ▶ my $ref= parse_references($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $ref = &parse_references($lx) 0 1 1
2500 1 $functor= 'property';
2501 1 push @arg, $constraint, 'references', $ref;
2502 },
2503 0 ▶ 'DROP REFERENCES' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2504 0 lexer_shift($lx);
2505 0 $functor= 'property';
2506 0 push @arg, $constraint, 'references', '';
2507 },
2508 38 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 38 0 38
2509  
2510 38 return ($functor, \@arg);
2511 }
2512  
2513 sub parse_column_spec_post($$);
2514 sub parse_column_spec_post($$)
2515 38 ▶{
Subroutine parse_column_spec_post: called CC=3 SCAR=11.0
Pod undocumented
2516 38 my ($lx, $base)= @_;
2517  
2518 38 my $r= create($lx, 'ColumnSpecPost', qw(base functor arg));
2519 38 $r->{base}= $base;
2520 38 $r->{arg}= [];
2521  
2522 38 ($r->{functor}, $r->{arg})= parse_column_spec_post_inner($lx);
2523 return
2524 38 ▶ if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 38 38
2525  
2526 return $base
2527 38 ▶ unless defined $r->{functor};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"functor"} 16 22 38
2528  
2529 22 return parse_column_spec_post ($lx, $r);
2530 }
2531  
2532 sub parse_column_spec($)
2533 16 ▶{
Subroutine parse_column_spec: called CC=2 SCAR=7.0
Pod undocumented
2534 16 my ($lx)= @_;
2535  
2536 16 my $r= create($lx, 'ColumnSpec', qw(datatype name token));
2537  
2538 parse_choice($lx,
2539 'interpolColumnSpec' => 'interpol',
2540 7 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2541 7 $r->{type}= 'interpol';
2542 7 $r->{token}= $lx->{token};
2543 7 lexer_shift($lx);
2544 },
2545  
2546 9 ▶ -default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
2547 9 $r->{type}= 'base';
2548 return unless
2549 9 ▶ $r->{datatype}= parse_type($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"datatype"} = &parse_type($lx) 0 9 9
2550 }
2551 16 );
2552 16 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 16 16
2553  
2554 16 lock_hash %$r;
2555 16 return parse_column_spec_post($lx, $r);
2556  
2557 }
2558  
2559 sub parse_expr_list($) # without enclosing (...)
2560 9 ▶{
Subroutine parse_expr_list: called CC=4 SCAR=13.9
Pod undocumented
2561 9 my ($lx)= @_;
2562 9 ▶ if (looking_at($lx, [@SELECT_INITIAL,'interpolStmt'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, [@SELECT_INITIAL, 'interpolStmt'])) { } 3 6 9
2563 return unless
2564 3 ▶ my $q= parse_select_stmt($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $q = &parse_select_stmt($lx) 0 3 3
2565  
2566 3 my $r= create_Expr ($lx);
2567 3 $r->{type}= 'subquery';
2568 3 $r->{arg}= $q;
2569 3 return $r;
2570 }
2571 else {
2572 6 my $r= create ($lx, ['ExprList','explicit'], qw(arg));
2573  
2574 return unless
2575 6 ▶ my $arg= parse_list ([], $lx, \&parse_expr, ',', ')');
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr, ",", ")") 0 6 6
2576  
2577 6 $r->{arg}= $arg;
2578 6 lock_hash %$r;
2579 6 return $r;
2580 }
2581 }
2582  
2583 sub parse_expr_list_delim($) # with enclosing (...)
2584 15 ▶{
Subroutine parse_expr_list_delim: called CC=1 SCAR=0.1
Pod undocumented
2585 15 my ($lx)= @_;
2586  
2587 return parse_choice($lx,
2588 9 ▶ '(' => sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
2589 9 lexer_shift($lx);
2590 return unless
2591 9 ▶ my $r= parse_expr_list ($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless my $r = &parse_expr_list($lx) and &expect($lx, ")", 1) 0 9 9
Condition33%1/3
my $r = &parse_expr_list($lx) and &expect($lx, ")", 1)
!ll&&!rl&&r
009
MC/DC0%0/2
my $r = &parse_expr_list($lx) and &expect($lx, ")", 1)
my $r = &parse_expr_list($lx) &expect($lx, ")", 1)
Truth table33%1/3
A and B
A= my $r = &parse_expr_list($lx)B= &expect($lx, ")", 1)
ABresult
0X0
100
111
2592 and expect ($lx, ')', SHIFT);
2593 9 return $r;
2594 },
2595  
2596 5 ▶ 'interpol' => sub { # Perl array reference:
Subroutine __ANON__: called CC=1 SCAR=0.0
2597 5 my $r= create ($lx, ['ExprList','interpol'], qw(token));
2598 5 $r->{token}= $lx->{token};
2599 5 lexer_shift($lx);
2600 5 lock_hash %$r;
2601 5 return $r;
2602 },
2603 15 );
2604 }
2605  
2606 sub get_rhs($$)
2607 190 ▶{
Subroutine get_rhs: called CC=2 SCAR=8.1
Pod undocumented
2608 190 my ($left, $arg_i)= @_;
2609 190 ▶ return $left->{rhs_map}{$arg_i} || $left->{rhs};
Condition33%1/3
$left->{'rhs_map'}{$arg_i} || $left->{'rhs'}
l!l&&r!l&&!r
01900
MC/DC0%0/2
$left->{'rhs_map'}{$arg_i} || $left->{'rhs'}
$left->{'rhs_map'}{$arg_i} $left->{'rhs'}
Truth table33%1/3
A || B
A= $left->{'rhs_map'}{$arg_i}B= $left->{'rhs'}
ABresult
1X1
011
000
2610 }
2611  
2612 sub parse_thing($$;$$)
2613 203 ▶{
Subroutine parse_thing: called CC=1 SCAR=0.0
Pod undocumented
2614 203 my ($lx, $thing_name, $left, $right_mark)= @_;
2615 return switch ($thing_name,
2616 191 ▶ 'expr' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2617 191 return parse_expr ($lx, $left, $right_mark)
2618 },
2619 1 ▶ 'type' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2620 1 return parse_type ($lx);
2621 },
2622 1 ▶ 'string_expr' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2623 1 return parse_expr ($lx, $left, 'string')
2624 },
2625 9 ▶ 'expr_list' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2626 9 return parse_expr_list_delim($lx);
2627 },
2628 1 ▶ 'type_list' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2629 1 return parse_type_list_delim($lx);
2630 },
2631 203 );
2632 }
2633  
2634 sub parse_funcsep($$$)
2635 8 ▶{
Subroutine parse_funcsep: called CC=9 SCAR=22.5
Pod undocumented
2636 8 my ($lx, $r, $pattern)= @_;
2637 8 for my $e (@$pattern) {
2638 34 ▶ if (!ref($e)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not ref $e) { } 14 20 34
elsif (ref $e eq 'SCALAR') { } 13 7 20
elsif (ref $e eq 'ARRAY') { } 7 0 7
2639 return unless
2640 14 ▶ expect($lx, $e, SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, $e, 1) 0 14 14
2641 14 push @{ $r->{arg} }, $e; # no ref()
2642 }
2643 elsif (ref($e) eq 'SCALAR') {
2644 return unless
2645 13 ▶ my $arg= parse_thing($lx, $$e); # will return a ref()
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_thing($lx, $$e) 0 13 13
2646 13 push @{ $r->{arg} }, $arg;
2647 }
2648 elsif (ref($e) eq 'ARRAY') {
2649 7 ▶ if (looking_at($lx, $e->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, $e->[0])) 2 5 7
2650 return unless
2651 2 ▶ parse_funcsep($lx, $r, $e);
Branch: 1 branch
BranchTrueFalseTotal
unless &parse_funcsep($lx, $r, $e) 0 2 2
2652 }
2653 }
2654 else {
2655 0 die "Unrecognised pattern piece, ref()=".ref($e);
2656 }
2657 }
2658 8 return $r;
2659 }
2660  
2661 sub parse_check($)
2662 9 ▶{
Subroutine parse_check: called CC=2 SCAR=7.0
Pod undocumented
2663 9 my ($lx)= @_;
2664 9 my $r= create ($lx, 'Check', qw(expr));
2665  
2666 9 my $cond= parse_expr_post($lx, undef, undef, create($lx, 'ExprEmpty'));
2667 9 ▶ return unless $cond;
Branch: 1 branch
BranchTrueFalseTotal
unless $cond 0 9 9
2668  
2669 9 $r->{expr}= $cond;
2670 9 return $r;
2671 }
2672  
2673 sub parse_when_post($)
2674 42 ▶{
Subroutine parse_when_post: called CC=7 SCAR=20.4
Pod undocumented
2675 42 my ($lx)= @_;
2676  
2677 return unless
2678 42 ▶ looking_at($lx, 'WHEN', SHIFT); # no error if false (-> parse_try_list)
Branch: 1 branch
BranchTrueFalseTotal
unless &looking_at($lx, "WHEN", 1) 22 20 42
2679  
2680 20 my $cond;
2681  
2682 20 my $functor= find_functor(\%functor_suffix, $lx->{token}{kind});
2683 20 ▶ if ($functor && $functor->{allow_when}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($functor and $functor->{'allow_when'}) { } 9 11 20
Condition66%2/3
$functor and $functor->{"allow_when"}
!ll&&!rl&&r
1109
MC/DC50%1/2
$functor and $functor->{"allow_when"}
$functor $functor->{"allow_when"}
Truth table66%2/3
A and B
A= $functorB= $functor->{"allow_when"}
ABresult
0X0
100
111
2684 9 $cond= parse_expr_post($lx, undef, undef, create($lx, 'ExprEmpty'));
2685 }
2686 else {
2687 11 $cond= parse_expr($lx);
2688 }
2689  
2690 return unless
2691 20 ▶ $cond
Branch: 1 branch
BranchTrueFalseTotal
unless $cond and &expect($lx, "THEN", 1) and my $expr = &parse_expr($lx) 0 20 20
Condition33%2/6
$cond and &expect($lx, "THEN", 1) and my $expr = &parse_expr($lx)
!ll&&!rl&&r
0020
$cond and &expect($lx, "THEN", 1)
!ll&&!rl&&r
0020
MC/DC0%0/3
$cond and &expect($lx, "THEN", 1) and my $expr = &parse_expr($lx)
$cond &expect($lx, "THEN", 1) my $expr = &parse_expr($lx)
Truth table25%1/4
A and B and C
A= $condB= &expect($lx, "THEN", 1)C= my $expr = &parse_expr($lx)
ABCresult
0XX0
10X0
1100
1111
2692 and expect($lx, 'THEN', SHIFT)
2693 and my $expr= parse_expr($lx);
2694  
2695 20 $cond->{maybe_check}= 1; # allow Check interpolation if this is an Expr
2696  
2697 20 return [ $cond, $expr ];
2698 }
2699  
2700 sub parse_when($)
2701 22 ▶{
Subroutine parse_when: called CC=5 SCAR=16.6
Pod undocumented
2702 22 my ($lx)= @_;
2703  
2704 return unless
2705 22 ▶ looking_at($lx, 'WHEN', SHIFT) # no error if false (-> parse_try_list)
Branch: 1 branch
BranchTrueFalseTotal
unless &looking_at($lx, "WHEN", 1) and my $cond = &parse_expr($lx) and &expect($lx, "THEN", 1) and my $expr = &parse_expr($lx) 12 10 22
Condition66%6/9
&looking_at($lx, "WHEN", 1) and my $cond = &parse_expr($lx) and &expect($lx, "THEN", 1) and my $expr = &parse_expr($lx)
!ll&&!rl&&r
12010
&looking_at($lx, "WHEN", 1) and my $cond = &parse_expr($lx) and &expect($lx, "THEN", 1)
!ll&&!rl&&r
12010
&looking_at($lx, "WHEN", 1) and my $cond = &parse_expr($lx)
!ll&&!rl&&r
12010
MC/DC25%1/4
&looking_at($lx, "WHEN", 1) and my $cond = &parse_expr($lx) and &expect($lx, "THEN", 1) and my $expr = &parse_expr($lx)
&looking_at($lx, "WHEN", 1) my $cond = &parse_expr($lx) &expect($lx, "THEN", 1) my $expr = &parse_expr($lx)
Truth table40%2/5
A and B and C and D
A= &looking_at($lx, "WHEN", 1)B= my $cond = &parse_expr($lx)C= &expect($lx, "THEN", 1)D= my $expr = &parse_expr($lx)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2706 and my $cond= parse_expr($lx)
2707 and expect($lx, 'THEN', SHIFT)
2708 and my $expr= parse_expr($lx);
2709  
2710 10 return [ $cond, $expr ];
2711 }
2712  
2713 sub shift_or_reduce_pure($$$)
2714 # $right_mark is either 0/undef, 1, or 'string', see parse_expr().
2715 183 ▶{
Subroutine shift_or_reduce_pure: called CC=18 SCAR=45.5
Pod undocumented
2716 183 my ($left, $right, $right_mark)= @_;
2717  
2718 # hack for 'IN':
2719 return ACTION_REDUCE
2720 if ($right_mark || '') eq 'string' &&
2721 183 ▶ $right->{value} eq 'IN';
Branch: 1 branch
BranchTrueFalseTotal
if ($right_mark || "") eq "string" and $right->{"value"} eq "IN" 1 182 183
Condition80%4/5
($right_mark || "") eq "string" and $right->{"value"} eq "IN"
!ll&&!rl&&r
18201
$right_mark || ''
l!l
5178
MC/DC50%1/2
($right_mark || "") eq "string" and $right->{"value"} eq "IN"
$right_mark $right->{"value"} eq "IN"
Truth table66%2/3
A and B
A= $right_markB= $right->{"value"} eq "IN"
ABresult
0X0
100
111
2722  
2723 # currently, this is very simple, because we don't use precedences:
2724 182 ▶ return ACTION_SHIFT
Branch: 1 branch
BranchTrueFalseTotal
unless $left 178 4 182
2725 unless $left;
2726  
2727 # special rule to allow sequencing even for operators without precedence:
2728 return ACTION_REDUCE
2729 if $left->{value} eq $right->{value} &&
2730 4 ▶ $left->{read_type} eq 'infix()';
Branch: 1 branch
BranchTrueFalseTotal
if $left->{"value"} eq $right->{"value"} and $left->{"read_type"} eq "infix()" 1 3 4
Condition66%2/3
$left->{"value"} eq $right->{"value"} and $left->{"read_type"} eq "infix()"
!ll&&!rl&&r
301
MC/DC50%1/2
$left->{"value"} eq $right->{"value"} and $left->{"read_type"} eq "infix()"
$left->{"value"} eq $right->{"value"} $left->{"read_type"} eq "infix()"
Truth table66%2/3
A and B
A= $left->{"value"} eq $right->{"value"}B= $left->{"read_type"} eq "infix()"
ABresult
0X0
100
111
2731  
2732 # parse with precedences?
2733 3 ▶ if ($do_prec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_prec) { } 0 3 3
2734 # if both have a precedence:
2735 0 ▶ if ($left->{prec} && $right->{prec}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left->{"prec"} and $right->{"prec"}) 0 0 0
Condition0%0/3
$left->{"prec"} and $right->{"prec"}
!ll&&!rl&&r
000
MC/DC0%0/2
$left->{"prec"} and $right->{"prec"}
$left->{"prec"} $right->{"prec"}
Truth table0%0/3
A and B
A= $left->{"prec"}B= $right->{"prec"}
ABresult
0X0
100
111
2736 return ACTION_REDUCE
2737 0 ▶ if $left->{prec} > $right->{prec};
Branch: 1 branch
BranchTrueFalseTotal
if $left->{"prec"} > $right->{"prec"} 0 0 0
2738  
2739 return ACTION_SHIFT
2740 0 ▶ if $left->{prec} < $right->{prec};
Branch: 1 branch
BranchTrueFalseTotal
if $left->{"prec"} < $right->{"prec"} 0 0 0
2741  
2742 # if both have an associativity and the associativity is the same:
2743 0 ▶ if ($left->{assoc} && $right->{assoc} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($left->{"assoc"} and $right->{"assoc"} and $left->{"assoc"} == $right->{"assoc"}) 0 0 0
Condition0%0/6
$left->{"assoc"} and $right->{"assoc"} and $left->{"assoc"} == $right->{"assoc"}
!ll&&!rl&&r
000
$left->{"assoc"} and $right->{"assoc"}
!ll&&!rl&&r
000
MC/DC0%0/3
$left->{"assoc"} and $right->{"assoc"} and $left->{"assoc"} == $right->{"assoc"}
$left->{"assoc"} $right->{"assoc"} $left->{"assoc"} == $right->{"assoc"}
Truth table0%0/4
A and B and C
A= $left->{"assoc"}B= $right->{"assoc"}C= $left->{"assoc"} == $right->{"assoc"}
ABCresult
0XX0
10X0
1100
1111
2744 $left->{assoc} == $right->{assoc})
2745 {
2746 0 ▶ if ($left->{assoc} == ASSOC_LEFT && $right_mark) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left->{'assoc'} == -1 and $right_mark) { } 0 0 0
Condition0%0/3
$left->{"assoc"} == -1 and $right_mark
!ll&&!rl&&r
000
MC/DC0%0/2
$left->{"assoc"} == -1 and $right_mark
$left->{"assoc"} == -1 $right_mark
Truth table0%0/3
A and B
A= $left->{"assoc"} == -1B= $right_mark
ABresult
0X0
100
111
2747 0 return ACTION_REDUCE;
2748 }
2749 else {
2750 0 return ACTION_SHIFT;
2751 }
2752 }
2753 }
2754 }
2755 else {
2756 # no precedences at all:
2757 # For infix23 and infix3, we need to reduce, instead of failing:
2758 3 ▶ if (defined $left->{value2}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $left->{"value2"}) 3 0 3
2759 3 return ACTION_REDUCE;
2760 }
2761 }
2762  
2763 # otherwise: ambiguous
2764 0 return ACTION_AMBIGUOUS;
2765 }
2766  
2767 sub shift_or_reduce($$$$)
2768 183 ▶{
Subroutine shift_or_reduce: called CC=2 SCAR=7.4
Pod undocumented
2769 183 my ($lx, $left, $right, $right_mark)= @_;
2770 183 my $result= shift_or_reduce_pure ($left, $right, $right_mark);
2771 183 ▶ unless ($result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 183 183
2772 0 $lx->{error}= "Use of operators '$left->{value}' vs. '$right->{value}' ".
2773 "requires parentheses.";
2774 }
2775 183 return $result;
2776 }
2777  
2778 sub find_functor($$)
2779 1123 ▶{
Subroutine find_functor: called CC=5 SCAR=16.2
Pod undocumented
2780 1123 my ($map, $kind)= @_;
2781  
2782 return unless
2783 1123 ▶ my $functor= find_ref(%$map, $kind);
Branch: 1 branch
BranchTrueFalseTotal
unless my $functor = &find_ref(\%$map, $kind) 860 263 1123
2784  
2785 263 ▶ if (my $accept= $functor->{accept}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $accept = $functor->{"accept"}) 3 260 263
2786 3 for my $a (@$accept) {
2787 3 ▶ if ($read_dialect{$a}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read_dialect{$a}) 3 0 3
2788 3 return $functor;
2789 }
2790 }
2791 0 return;
2792 }
2793  
2794 260 return $functor;
2795 }
2796  
2797 sub set_expr_functor($$@)
2798 260 ▶{
Subroutine set_expr_functor: called CC=2 SCAR=7.0
Pod undocumented
2799 260 my ($r, $functor, @arg)= @_;
2800 260 ▶ my_confess if $r->{arg};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"arg"} 0 260 260
2801  
2802 260 $r->{type}= $functor->{type};
2803 260 $r->{functor}= $functor;
2804 260 $r->{arg}= [ @arg ];
2805 }
2806  
2807 sub parse_expr_post($$$$)
2808 # $right_mark is either 0/undef, 1, or 'string', see parse_expr().
2809 1021 ▶{
Subroutine parse_expr_post: called CC=5 SCAR=16.7
Pod undocumented
2810 1021 my ($lx, $left, $right_mark, $arg1)= @_;
2811  
2812 # infix:
2813 1021 my $kind= $lx->{token}{kind};
2814  
2815 1021 ▶ if (my $right= find_functor(\%functor_suffix, $kind)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $right = &find_functor(\%functor_suffix, $kind)) 183 838 1021
2816 return unless
2817 183 ▶ my $action= shift_or_reduce($lx, $left, $right, $right_mark);
Branch: 1 branch
BranchTrueFalseTotal
unless my $action = &shift_or_reduce($lx, $left, $right, $right_mark) 0 183 183
2818  
2819 183 ▶ if ($action == ACTION_SHIFT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action == 1) 178 5 183
2820 178 lexer_shift ($lx);
2821  
2822 178 my $r= create_Expr ($lx);
2823 178 set_expr_functor ($r, $right, $arg1);
2824  
2825 switch ($right->{read_type},
2826 91 ▶ 'infix2' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
2827 # parse second arg:
2828 return unless
2829 91 ▶ my $arg2= parse_thing ($lx, get_rhs($right,0), $right, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) 1 90 91
2830 90 push @{ $r->{arg} }, $arg2;
2831 },
2832 63 ▶ 'infix()' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
2833 # parse sequence:
2834 63 my $i=0;
2835 63 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
&looking_at($lx, $kind, 1) and do { do { return unless my $argi = &parse_thing($lx, scalar &get_rhs($right, $i++), $right, 1); push @{$$r{"arg"};}, $argi } } 1 63 64
2836 return unless
2837 64 ▶ my $argi= parse_thing ($lx, get_rhs($right,$i++), $right, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless my $argi = &parse_thing($lx, scalar &get_rhs($right, $i++), $right, 1) 0 64 64
2838 64 push @{ $r->{arg} }, $argi;
2839 } while (looking_at($lx, $kind, SHIFT)); # same operator?
2840 },
2841 2 ▶ 'infix23' => sub {
Subroutine __ANON__: called CC=4 SCAR=18.7
2842 # parse second arg:
2843 return unless
2844 2 ▶ my $arg2= parse_thing ($lx, get_rhs($right,0), $right, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) 0 2 2
2845 2 push @{ $r->{arg} }, $arg2;
2846  
2847 # maybe parse third arg:
2848 2 ▶ if (looking_at ($lx, $right->{value2}, SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, $right->{"value2"}, 1)) 0 2 2
2849 return unless
2850 0 ▶ my $arg3= parse_thing ($lx, get_rhs($right,1), $right, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg3 = &parse_thing($lx, scalar &get_rhs($right, 1), $right, 1) 0 0 0
2851 0 push @{ $r->{arg} }, $arg3;
2852 }
2853 },
2854 2 ▶ 'infix3' => sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
2855 # parse second arg:
2856 return unless
2857 my $arg2= parse_thing ($lx, get_rhs($right,0), $right, 1)
2858 2 ▶ and expect ($lx, $right->{value2}, SHIFT)
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) and &expect($lx, $right->{"value2"}, 1) and my $arg3 = &parse_thing($lx, scalar &get_rhs($right, 1), $right, 1) 0 2 2
Condition33%2/6
my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) and &expect($lx, $right->{"value2"}, 1) and my $arg3 = &parse_thing($lx, scalar &get_rhs($right, 1), $right, 1)
!ll&&!rl&&r
002
my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) and &expect($lx, $right->{"value2"}, 1)
!ll&&!rl&&r
002
MC/DC0%0/3
my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) and &expect($lx, $right->{"value2"}, 1) and my $arg3 = &parse_thing($lx, scalar &get_rhs($right, 1), $right, 1)
my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) &expect($lx, $right->{"value2"}, 1) my $arg3 = &parse_thing($lx, scalar &get_rhs($right, 1), $right, 1)
Truth table25%1/4
A and B and C
A= my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1)B= &expect($lx, $right->{"value2"}, 1)C= my $arg3 = &parse_thing($lx, scalar &get_rhs($right, 1), $right, 1)
ABCresult
0XX0
10X0
1100
1111
2859 and my $arg3= parse_thing ($lx, get_rhs($right,1), $right, 1); # descend
2860  
2861 2 push @{ $r->{arg} }, $arg2, $arg3;
2862 },
2863 20 ▶ 'suffix' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2864 # nothing more to do
2865 }
2866 178 );
2867 178 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 1 177 178
2868  
2869 177 lock_keys %$r; # {maybe_check} may be modified if we parse WHEN clauses.
2870  
2871 177 return parse_expr_post ($lx, $left, $right_mark, $r); # descend
2872 }
2873 }
2874  
2875 843 return $arg1;
2876 }
2877  
2878 sub parse_expr($;$$)
2879 # $right_mark is either 0/undef, 1, or 'string'.
2880 # 'string' is a hack for POSITION(a IN b) and keeps parse_expr
2881 # from shifting IN. It's one of these typical design complications
2882 # in SQL grammar that prevents you from writing a straight-forward
2883 # recursive parser. If $right_mark eq 'string', then $functor
2884 # is undef. Otherwise $functor is defined if $right_mark is true.
2885 826 ▶{
Subroutine parse_expr: called CC=3 SCAR=11.5
Pod undocumented
2886 826 my ($lx, $functor, $right_mark)= @_;
2887 826 my $r= create_Expr ($lx);
2888  
2889 parse_choice($lx,
2890 23 ▶ '.' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2891 23 lexer_shift($lx);
2892 23 $r->{type}= 'column';
2893 23 $r->{arg}= parse_column ($lx);
2894 },
2895  
2896 'interpolColumn' => 'ident',
2897 'interpolTable' => 'ident',
2898 '*' => 'ident',
2899 289 ▶ 'ident' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2900 289 $r->{type}= 'column';
2901 289 $r->{arg}= parse_column ($lx);
2902 },
2903  
2904 206 ▶ 'interpolExpr' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2905 206 $r->{type}= 'interpol';
2906 206 $r->{token}= $lx->{token};
2907 206 lexer_shift($lx);
2908 },
2909  
2910 173 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2911 173 parse_value_or_column_into ($lx, $r, 'interpol');
2912 },
2913  
2914 'TRUE' => '?',
2915 'FALSE' => '?',
2916 'NULL' => '?',
2917 'UNKNOWN' => '?',
2918 'DEFAULT' => '?',
2919 7 ▶ '?' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
2920 7 $r->{type}= 'interpol';
2921 7 $r->{token}= $lx->{token};
2922 7 lexer_shift($lx);
2923  
2924 # special care for functors like MySQL's DEFAULT(...). Since
2925 # there's both DEFAULT and DEFAULT(...), we need to check. We
2926 # use find_functor() in order to support read_dialect properly.
2927 7 ▶ if (looking_at($lx, '(', SHIFT) and
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "(", 1) and my $functor = &find_functor(\%functor_special, $r->{"token"}{"kind"})) 1 6 7
Condition66%2/3
&looking_at($lx, "(", 1) and my $functor = &find_functor(\%functor_special, $r->{"token"}{"kind"})
!ll&&!rl&&r
601
MC/DC50%1/2
&looking_at($lx, "(", 1) and my $functor = &find_functor(\%functor_special, $r->{"token"}{"kind"})
&looking_at($lx, "(", 1) my $functor = &find_functor(\%functor_special, $r->{"token"}{"kind"})
Truth table66%2/3
A and B
A= &looking_at($lx, "(", 1)B= my $functor = &find_functor(\%functor_special, $r->{"token"}{"kind"})
ABresult
0X0
100
111
2928 my $functor= find_functor(\%functor_special, $r->{token}{kind}))
2929 {
2930 switch ($functor->{read_type},
2931 1 ▶ 'funcall1col' => sub {
Subroutine __ANON__: called CC=3 SCAR=13.1
2932 return unless
2933 1 ▶ my $arg= parse_column_name($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_column_name($lx) and &expect($lx, ")", 1) 0 1 1
Condition33%1/3
my $arg = &parse_column_name($lx) and &expect($lx, ")", 1)
!ll&&!rl&&r
001
MC/DC0%0/2
my $arg = &parse_column_name($lx) and &expect($lx, ")", 1)
my $arg = &parse_column_name($lx) &expect($lx, ")", 1)
Truth table33%1/3
A and B
A= my $arg = &parse_column_name($lx)B= &expect($lx, ")", 1)
ABresult
0X0
100
111
2934 and expect ($lx, ')', SHIFT);
2935 1 set_expr_functor ($r, $functor, $arg);
2936 }
2937 1 );
2938 }
2939 },
2940  
2941 34 ▶ 'CASE' => sub {
Subroutine __ANON__: called CC=8 SCAR=22.1
2942 34 lexer_shift($lx);
2943 34 $r->{type}= 'case';
2944 34 ▶ if (looking_at($lx, ['WHEN','ELSE','END'])) { # without 'switchval'
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ['WHEN', 'ELSE', 'END'])) { } 12 22 34
2945 return unless
2946 12 ▶ $r->{arg}= parse_try_list([], $lx, \&parse_when);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"arg"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_when) 0 12 12
2947 }
2948 else { # with switchval
2949 return unless
2950 $r->{switchval}= parse_expr($lx)
2951 22 ▶ and $r->{arg}= parse_try_list([], $lx, \&parse_when_post);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"switchval"} = &parse_expr($lx) and $r->{"arg"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_when_post) 0 22 22
Condition33%1/3
$r->{"switchval"} = &parse_expr($lx) and $r->{"arg"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_when_post)
!ll&&!rl&&r
0022
MC/DC0%0/2
$r->{"switchval"} = &parse_expr($lx) and $r->{"arg"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_when_post)
$r->{"switchval"} = &parse_expr($lx) $r->{"arg"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_when_post)
Truth table33%1/3
A and B
A= $r->{"switchval"} = &parse_expr($lx)B= $r->{"arg"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_when_post)
ABresult
0X0
100
111
2952 }
2953  
2954 34 ▶ if (looking_at($lx, 'ELSE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ELSE", 1)) 24 10 34
2955 return unless
2956 24 ▶ $r->{otherwise}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"otherwise"} = &parse_expr($lx) 0 24 24
2957 }
2958  
2959 return unless
2960 34 ▶ expect($lx, 'END', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "END", 1) 0 34 34
2961 },
2962  
2963 'DISTINCT' => 'SOME',
2964 'ALL' => 'SOME',
2965 'ANY' => 'SOME',
2966 2 ▶ 'SOME' => sub {
Subroutine __ANON__: called CC=6 SCAR=19.7
2967 #if (!$functor || !$functor->{comparison} || !$right_mark) {
2968 # $lx->{error}= "$lx->{token}{kind} can only be used directly after a comparison.";
2969 # return;
2970 #}
2971 2 my $functor2= find_functor(\%functor_special, $lx->{token}{kind});
2972 2 ▶ unless ($functor2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($functor2) 0 2 2
2973 0 $lx->{error}= "Unexpected $lx->{token}{kind} in expression.";
2974 0 return;
2975 }
2976 2 lexer_shift($lx);
2977  
2978 2 my $r2;
2979 2 ▶ if (looking_at($lx, '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '(')) { } 1 1 2
2980 return unless
2981 1 ▶ expect($lx, '(', SHIFT)
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "(", 1) and my $q = &parse_select_stmt($lx) and &expect($lx, ")", 1) 0 1 1
Condition33%2/6
&expect($lx, "(", 1) and my $q = &parse_select_stmt($lx) and &expect($lx, ")", 1)
!ll&&!rl&&r
001
&expect($lx, "(", 1) and my $q = &parse_select_stmt($lx)
!ll&&!rl&&r
001
MC/DC0%0/3
&expect($lx, "(", 1) and my $q = &parse_select_stmt($lx) and &expect($lx, ")", 1)
&expect($lx, "(", 1) my $q = &parse_select_stmt($lx) &expect($lx, ")", 1)
Truth table25%1/4
A and B and C
A= &expect($lx, "(", 1)B= my $q = &parse_select_stmt($lx)C= &expect($lx, ")", 1)
ABCresult
0XX0
10X0
1100
1111
2982 and my $q= parse_select_stmt ($lx)
2983 and expect($lx, ')', SHIFT);
2984  
2985 1 $r2= create_Expr($lx);
2986 1 $r2->{type}= 'subquery';
2987 1 $r2->{arg}= $q;
2988  
2989 }
2990 else {
2991 1 $r2 = parse_expr($lx, $functor, $right_mark);
2992 }
2993  
2994 2 set_expr_functor ($r, $functor2, $r2);
2995 },
2996  
2997 13 ▶ '(' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.4
2998 13 lexer_shift($lx);
2999 13 ▶ if (looking_at($lx, [@SELECT_INITIAL,'interpolStmt'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, [@SELECT_INITIAL, 'interpolStmt'])) { } 2 11 13
3000 return unless
3001 2 ▶ my $q= parse_select_stmt ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $q = &parse_select_stmt($lx) 0 2 2
3002 2 $r->{type}= 'subquery';
3003 2 $r->{arg}= $q;
3004 }
3005 else {
3006 return unless
3007 11 ▶ my $arg= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_expr($lx) 0 11 11
3008 11 $r->{type}= '()';
3009 11 $r->{arg}= $arg;
3010 }
3011 return unless
3012 13 ▶ expect($lx, ')', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, ")", 1) 0 13 13
3013 },
3014  
3015 79 ▶ -default => sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
3016 79 my $functor2= find_functor(\%functor_prefix, $lx->{token}{kind});
3017 79 ▶ if (!$functor2 && $lx->{token}{type} eq 'keyword') { # generic funcall
Branch: 1 branch
BranchTrueFalseTotal
if (not $functor2 and $lx->{"token"}{"type"} eq "keyword") 11 68 79
Condition66%2/3
not $functor2 and $lx->{"token"}{"type"} eq "keyword"
!ll&&!rl&&r
68011
MC/DC50%1/2
not $functor2 and $lx->{"token"}{"type"} eq "keyword"
not $functor2 $lx->{"token"}{"type"} eq "keyword"
Truth table66%2/3
not(A) and B
A= not $functor2B= $lx->{"token"}{"type"} eq "keyword"
ABresult
0X0
100
111
3018 11 $functor2= make_op($lx->{token}{kind}, 'funcall');
3019 }
3020  
3021 # prefix / funcall:
3022 79 ▶ if ($functor2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($functor2) { } 79 0 79
elsif (not $lx->{'error'}) { } 0 0 0
3023 79 set_expr_functor ($r, $functor2);
3024 79 lexer_shift($lx);
3025  
3026 switch ($functor2->{read_type},
3027 45 ▶ 'prefix' => sub {
Subroutine __ANON__: called CC=4 SCAR=14.1
3028 45 my $arg;
3029 45 ▶ if (looking_at($lx, '(', NO_SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '(', 0)) { } 16 29 45
3030 return unless
3031 16 ▶ $r->{arg}= parse_list_delim ($lx, \&parse_expr);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"arg"} = &parse_list_delim($lx, \&SQL::Yapp::parse_expr) 0 16 16
3032 }
3033 else {
3034 return unless
3035 29 ▶ my $arg= parse_thing ($lx, get_rhs($functor2,0), $functor2, 0);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_thing($lx, scalar &get_rhs($functor2, 0), $functor2, 0) 0 29 29
3036 29 $r->{arg}= [ $arg ];
3037 }
3038 },
3039 27 ▶ 'funcall' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
3040 return unless
3041 27 ▶ $r->{arg}= parse_list_delim ($lx, \&parse_expr);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"arg"} = &parse_list_delim($lx, \&SQL::Yapp::parse_expr) 0 27 27
3042 },
3043 1 ▶ 'funcall1col' => sub {
Subroutine __ANON__: called CC=4 SCAR=17.9
3044 return unless
3045 1 ▶ expect ($lx, '(', SHIFT)
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "(", 1) and my $arg1 = &parse_column_name($lx) and &expect($lx, ")", 1) 0 1 1
Condition33%2/6
&expect($lx, "(", 1) and my $arg1 = &parse_column_name($lx) and &expect($lx, ")", 1)
!ll&&!rl&&r
001
&expect($lx, "(", 1) and my $arg1 = &parse_column_name($lx)
!ll&&!rl&&r
001
MC/DC0%0/3
&expect($lx, "(", 1) and my $arg1 = &parse_column_name($lx) and &expect($lx, ")", 1)
&expect($lx, "(", 1) my $arg1 = &parse_column_name($lx) &expect($lx, ")", 1)
Truth table25%1/4
A and B and C
A= &expect($lx, "(", 1)B= my $arg1 = &parse_column_name($lx)C= &expect($lx, ")", 1)
ABCresult
0XX0
10X0
1100
1111
3046 and my $arg1= parse_column_name($lx)
3047 and expect ($lx, ')', SHIFT);
3048 1 $r->{arg}= [ $arg1 ];
3049 },
3050 6 ▶ 'funcsep' => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
3051 return unless
3052 expect ($lx, '(', SHIFT)
3053 6 ▶ and parse_funcsep ($lx, $r, $functor2->{rhs});
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "(", 1) and &parse_funcsep($lx, $r, $functor2->{"rhs"}) 0 6 6
Condition33%1/3
&expect($lx, "(", 1) and &parse_funcsep($lx, $r, $functor2->{"rhs"})
!ll&&!rl&&r
006
MC/DC0%0/2
&expect($lx, "(", 1) and &parse_funcsep($lx, $r, $functor2->{"rhs"})
&expect($lx, "(", 1) &parse_funcsep($lx, $r, $functor2->{"rhs"})
Truth table33%1/3
A and B
A= &expect($lx, "(", 1)B= &parse_funcsep($lx, $r, $functor2->{"rhs"})
ABresult
0X0
100
111
3054 },
3055 79 );
3056 79 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 79 79
3057 }
3058 # error:
3059 elsif (! $lx->{error}) {
3060 0 $lx->{error}= "Unexpected ".token_describe($lx->{token})." in expression";
3061 }
3062  
3063 79 return;
3064 },
3065 826 );
3066 826 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 826 826
3067  
3068 826 ▶ die unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 826 826
3069 826 lock_keys %$r; # {arg} may be modified when parsing sequenced infix operators
3070 # and {maybe_check} may be modified when parsing WHEN clauses
3071  
3072 # And now parse the suffix:
3073 826 return parse_expr_post ($lx, $functor, $right_mark, $r);
3074 }
3075  
3076 sub parse_limit_num($) # Simply returns the single token if it is appropriate.
3077 32 ▶{
Subroutine parse_limit_num: called CC=1 SCAR=0.0
Pod undocumented
3078 32 my ($lx)= @_;
3079 return parse_choice($lx,
3080 'interpolExpr' => 'interpol',
3081 '?' => 'interpol',
3082 32 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3083 32 my $r= $lx->{token};
3084 32 lexer_shift($lx);
3085 32 return $r;
3086 },
3087 32 );
3088 }
3089  
3090 sub parse_expr_as($)
3091 231 ▶{
Subroutine parse_expr_as: called CC=4 SCAR=13.9
Pod undocumented
3092 231 my ($lx)= @_;
3093 231 my $r= create ($lx, 'ExprAs', qw(expr as));
3094  
3095 return unless
3096 231 ▶ $r->{expr}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"expr"} = &parse_expr($lx) 1 230 231
3097  
3098 230 ▶ if (looking_at($lx, 'AS', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "AS", 1)) 4 226 230
3099 return unless
3100 4 ▶ $r->{as}= parse_column_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"as"} = &parse_column_name($lx) 0 4 4
3101 }
3102  
3103 230 lock_hash %$r;
3104 230 return $r;
3105 }
3106  
3107 sub parse_order($)
3108 35 ▶{
Subroutine parse_order: called CC=2 SCAR=7.0
Pod undocumented
3109 35 my ($lx)= @_;
3110 35 my $r= create ($lx, 'Order', qw(type expr token desc));
3111 35 $r->{desc}= 0;
3112  
3113 parse_choice($lx,
3114 14 ▶ -default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
3115 14 $r->{type}= 'expr';
3116 return unless
3117 14 ▶ $r->{expr}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"expr"} = &parse_expr($lx) 0 14 14
3118 },
3119  
3120 'interpolOrder' => 'interpol',
3121 21 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
3122 21 ▶ if ($lx->{token}{type} eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{'token'}{'type'} eq 'string') { } 3 18 21
3123 # Strings are still expressions, not column names. There is no
3124 # other way of forcing Perl interpolation to String type, so
3125 # we assume a string here.
3126 3 $r->{type}= 'expr';
3127 return unless
3128 3 ▶ $r->{expr}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"expr"} = &parse_expr($lx) 0 3 3
3129 }
3130 else {
3131 18 $r->{type}= 'interpol';
3132 18 $r->{token}= $lx->{token};
3133 18 lexer_shift($lx);
3134 }
3135 },
3136 35 );
3137 35 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 35 35
3138  
3139 parse_choice($lx,
3140 23 ▶ -default => sub {}, # no error
Subroutine __ANON__: called CC=1 SCAR=0.0
3141 2 ▶ 'ASC' => sub { lexer_shift($lx); $r->{desc}= 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
3142 10 ▶ 'DESC' => sub { lexer_shift($lx); $r->{desc}= 1; },
Subroutine __ANON__: called CC=1 SCAR=0.0
3143 35 );
3144  
3145 35 lock_hash %$r;
3146 35 return $r;
3147 }
3148  
3149 sub parse_join($)
3150 133 ▶{
Subroutine parse_join: called CC=3 SCAR=11.1
Pod undocumented
3151 133 my ($lx)= @_;
3152 133 my $r= create ($lx, 'Join', qw(token table qual on using natural));
3153  
3154 #print STDERR "parse join: ".token_describe($lx->{token})."\n";
3155 parse_choice($lx,
3156 'interpolJoin' => 'interpol',
3157 5 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3158 $r->{type}= 'interpol',
3159 5 $r->{token}= $lx->{token};
3160 5 lexer_shift($lx);
3161 },
3162  
3163 128 ▶ -default => sub {
Subroutine __ANON__: called CC=7 SCAR=19.8
3164 128 my $shifted= 0;
3165  
3166 128 my $want_condition= 1;
3167 128 ▶ if (looking_at($lx, 'NATURAL', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "NATURAL", 1)) 3 125 128
3168 3 $r->{natural}= 1;
3169 3 $shifted= 1;
3170 3 $want_condition= 0;
3171 }
3172  
3173 parse_choice($lx,
3174 118 ▶ -default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3175 118 $r->{type}= 'INNER';
3176 },
3177  
3178 4 ▶ 'INNER' => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
3179 4 $r->{type}= 'INNER';
3180 4 lexer_shift($lx);
3181 4 $shifted= 1;
3182 },
3183  
3184 'UNION' => 'CROSS',
3185 3 ▶ 'CROSS' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.9
3186 3 ▶ if ($r->{natural}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"natural"}) 0 3 3
3187 0 $lx->{error}= "NATURAL cannot be used with CROSS or UNION JOIN";
3188 0 return;
3189 }
3190  
3191 3 $r->{type}= lexer_shift($lx);
3192 3 $want_condition= 0;
3193 3 $shifted= 1;
3194 },
3195  
3196 'LEFT' => 'FULL',
3197 'RIGHT' => 'FULL',
3198 3 ▶ 'FULL' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3199 3 $r->{type}= lexer_shift($lx);
3200 3 looking_at($lx, 'OUTER', SHIFT);
3201 3 $shifted= 1;
3202 },
3203 128 );
3204 128 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 128 128
3205  
3206 128 ▶ unless (looking_at ($lx, 'JOIN', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looking_at($lx, "JOIN", 1)) 117 11 128
3207 117 ▶ if ($shifted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shifted) 0 117 117
3208 0 $lx->{error}= "Expected JOIN, but found ".token_describe($lx->{token});
3209 }
3210 117 $r= undef;
3211 117 return;
3212 }
3213  
3214 return unless
3215 11 ▶ $r->{table}= parse_list([], $lx, \&parse_table_as, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") 0 11 11
3216  
3217 11 ▶ if ($want_condition) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_condition) 5 6 11
3218 parse_choice($lx,
3219 3 ▶ 'ON' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3220 3 lexer_shift($lx);
3221 3 $r->{on}= parse_expr($lx);
3222 },
3223 2 ▶ 'USING' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
3224 2 lexer_shift($lx);
3225 return unless
3226 2 ▶ $r->{using}= parse_list_delim ($lx, \&parse_column_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"using"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name) 0 2 2
3227 },
3228 5 );
3229 }
3230 }
3231 133 );
3232 133 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 133 133
3233 133 ▶ return unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 117 16 133
3234  
3235 16 lock_hash %$r;
3236 16 return $r;
3237 }
3238  
3239 sub push_option($$$)
3240 503 ▶{
Subroutine push_option: called CC=2 SCAR=6.9
Pod undocumented
3241 503 my ($lx, $list, $words)= @_;
3242 503 ▶ if (my $x= looking_at($lx, $words, SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = &looking_at($lx, $words, 1)) 5 498 503
3243 5 push @$list, $x;
3244 5 return $x;
3245 }
3246 498 return 0;
3247 }
3248  
3249 sub push_option_list($$$)
3250 310 ▶{
Subroutine push_option_list: called CC=2 SCAR=6.9
Pod undocumented
3251 310 my ($lx, $list, $words)= @_;
3252 310 ▶ while (push_option($lx, $list, $words)) {}
Branch: 1 branch
BranchTrueFalseTotal
if (&push_option($lx, $list, $words)) 4 310 314
3253 }
3254  
3255 sub parse_where($) # WHERE is supposed to haveing been parsed already here
3256 56 ▶{
Subroutine parse_where: called CC=1 SCAR=0.0
Pod undocumented
3257 56 my ($lx)= @_;
3258 # FIXME: MISSING:
3259 # - WHERE CURRENT OF (i.e., cursor support)
3260 56 return parse_expr($lx);
3261 }
3262  
3263 sub parse_select($)
3264 185 ▶{
Subroutine parse_select: called CC=25 SCAR=33.9
Pod undocumented
3265 185 my ($lx)= @_;
3266 185 my $r= create ($lx, ['Stmt','Select'],
3267 qw(
3268 opt_front
3269 opt_back
3270 expr_list
3271 from
3272 join
3273 where
3274 group_by
3275 group_by_with_rollup
3276 having
3277 order_by
3278 limit_cnt
3279 limit_offset
3280 )
3281 );
3282  
3283 185 ▶ return unless expect($lx, 'SELECT', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "SELECT", 1) 0 185 185
3284  
3285 # Missing:
3286 # PostgresQL:
3287 # - DISTINCT **ON** <expr>
3288 # - WITH
3289 # - WINDOW
3290 # - FETCH
3291 # - FOR UPDATE|SHARE **OF** ( <Table> , ... )
3292 #
3293 # All:
3294 # - UNION
3295 # - INTERSECT
3296 # - EXCEPT
3297 # - FETCH [ FIRST | NEXT ] count [ ROW | ROWS ] ONLY (same as LIMIT in SQL:2008)
3298  
3299 185 $r->{opt_front}= [];
3300 push_option ($lx, $r->{opt_front}, [
3301 'DISTINCT', 'ALL',
3302 ($read_dialect{mysql} ?
3303 185 ▶ ('DISTINCTROW')
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 185 0 185
3304 : ()
3305 )
3306 ]);
3307  
3308 push_option_list ($lx, $r->{opt_front}, [
3309 ($read_dialect{mysql} ?
3310 (
3311 185 ▶ 'HIGH_PRIORITY', 'STRAIGHT_JOIN',
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 185 0 185
3312 'SQL_SMALL_RESULT', 'SQL_BIG_RESULT', 'SQL_BUFFER_RESULT',
3313 'SQL_CACHE', 'SQL_NO_CACHE', 'SQL_CALC_FOUND_ROWS'
3314 )
3315 : ()
3316 )
3317 ]);
3318  
3319 return unless
3320 185 ▶ $r->{expr_list}= parse_list([], $lx, \&parse_expr_as, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"expr_list"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr_as, ",") 1 184 185
3321  
3322 184 ▶ if (looking_at($lx, 'FROM', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "FROM", 1)) 99 85 184
3323 return unless
3324 $r->{from}= parse_list([], $lx, \&parse_table_as, ',')
3325 99 ▶ and $r->{join}= parse_try_list([], $lx, \&parse_join);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"from"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") and $r->{"join"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_join) 0 99 99
Condition33%1/3
$r->{"from"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") and $r->{"join"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_join)
!ll&&!rl&&r
0099
MC/DC0%0/2
$r->{"from"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") and $r->{"join"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_join)
$r->{"from"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") $r->{"join"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_join)
Truth table33%1/3
A and B
A= $r->{"from"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",")B= $r->{"join"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_join)
ABresult
0X0
100
111
3326  
3327 99 ▶ if (looking_at($lx, 'WHERE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "WHERE", 1)) 44 55 99
3328 return unless
3329 44 ▶ $r->{where}= parse_where ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"where"} = &parse_where($lx) 0 44 44
3330 }
3331 99 ▶ if (looking_at($lx, 'GROUP BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "GROUP BY", 1)) 6 93 99
3332 return unless
3333 6 ▶ $r->{group_by}= parse_list([], $lx, \&parse_order, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"group_by"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_order, ",") 0 6 6
3334  
3335 6 $r->{group_by_with_rollup}= looking_at($lx, 'WITH ROLLUP', SHIFT);
3336 }
3337 99 ▶ if (looking_at($lx, 'HAVING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "HAVING", 1)) 1 98 99
3338 return unless
3339 1 ▶ $r->{having}= parse_expr ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"having"} = &parse_expr($lx) 0 1 1
3340 }
3341 99 ▶ if (looking_at($lx, 'ORDER BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ORDER BY", 1)) 8 91 99
3342 return unless
3343 8 ▶ $r->{order_by}= parse_list([], $lx, \&parse_order, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"order_by"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_order, ",") 0 8 8
3344 }
3345  
3346 99 ▶ if (looking_at($lx, 'LIMIT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "LIMIT", 1)) 4 95 99
3347 4 ▶ unless (looking_at($lx, 'ALL', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looking_at($lx, "ALL", 1)) 4 0 4
3348 4 my $first_num= parse_limit_num ($lx);
3349 4 ▶ if (looking_at($lx, ',', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ',', 1)) { } 2 2 4
3350 2 $r->{limit_offset}= $first_num;
3351 2 $r->{limit_cnt}= parse_limit_num($lx);
3352 }
3353 else {
3354 2 $r->{limit_cnt}= $first_num;
3355 }
3356 }
3357 }
3358 99 ▶ if (!$r->{limit_offset} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $r->{"limit_offset"} and &looking_at($lx, "OFFSET", 1)) 1 98 99
Condition100%3/3
not $r->{"limit_offset"} and &looking_at($lx, "OFFSET", 1)
!ll&&!rl&&r
2961
MC/DC100%2/2
not $r->{"limit_offset"} and &looking_at($lx, "OFFSET", 1)
not $r->{"limit_offset"} &looking_at($lx, "OFFSET", 1)
Truth table100%3/3
not(A) and B
A= not $r->{"limit_offset"}B= &looking_at($lx, "OFFSET", 1)
ABresult
0X0
100
111
3359 looking_at ($lx, 'OFFSET', SHIFT))
3360 {
3361 1 $r->{limit_offset}= parse_limit_num ($lx);
3362 }
3363  
3364 99 $r->{opt_back}= [];
3365 push_option_list ($lx, $r->{opt_back}, [
3366 ($read_dialect{mysql} || $read_dialect{postgresql} ?
3367 ('FOR UPDATE')
3368 : ()
3369 ),
3370 ($read_dialect{mysql} ?
3371 (
3372 'LOCK IN SHARE MODE' # FIXME: normalise: PostgreSQL: FOR SHARE
3373 )
3374 : ()
3375 ),
3376 ($read_dialect{postgresql} ?
3377 (
3378 99 ▶ 'FOR SHARE', # FIXME: normalise: MySQL: LOCK IN SHARE MODE
Branch: 3 branches
BranchTrueFalseTotal
$read_dialect{'mysql'} || $read_dialect{'postgresql'} ? : 99 0 99
$read_dialect{'mysql'} ? : 99 0 99
$read_dialect{'postgresql'} ? : 99 0 99
Condition33%1/3
$read_dialect{"mysql"} or $read_dialect{"postgresql"}
l!l&&r!l&&!r
9900
MC/DC0%0/2
$read_dialect{"mysql"} or $read_dialect{"postgresql"}
$read_dialect{"mysql"} $read_dialect{"postgresql"}
Truth table33%1/3
A or B
A= $read_dialect{"mysql"}B= $read_dialect{"postgresql"}
ABresult
1X1
011
000
3379 'NOWAIT'
3380 )
3381 : ()
3382 ),
3383 ]);
3384 }
3385  
3386 184 lock_hash %$r;
3387 184 return $r;
3388 }
3389  
3390 sub parse_insert($)
3391 13 ▶{
Subroutine parse_insert: called CC=10 SCAR=24.9
Pod undocumented
3392 13 my ($lx)= @_;
3393 13 my $r= create ($lx, ['Stmt','Insert'],
3394 qw(
3395 opt_front
3396 into
3397 column
3398 default_values
3399 value
3400 value_interpol
3401 set
3402 select
3403 duplicate_update
3404 )
3405 );
3406  
3407 13 ▶ return unless expect($lx, 'INSERT', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "INSERT", 1) 0 13 13
3408  
3409 # PostgreSQL:
3410 # - RETURNING ...
3411  
3412 13 $r->{opt_front}= [];
3413 push_option_list ($lx, $r->{opt_front}, [
3414 ($read_dialect{mysql} ?
3415 (
3416 13 ▶ 'IGNORE',
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 13 0 13
3417 'LOW_PRIORITY',
3418 'HIGH_PRIORITY',
3419 'DELAYED',
3420 )
3421 : ()
3422 )
3423 ]);
3424  
3425 13 looking_at($lx, 'INTO', SHIFT); # optional in MySQL
3426  
3427 return unless
3428 13 ▶ $r->{into}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"into"} = &parse_table($lx) 0 13 13
3429  
3430 13 ▶ if (looking_at($lx, '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "(")) 5 8 13
3431 return unless
3432 5 ▶ $r->{column}= parse_list_delim($lx, \&parse_column_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name) 0 5 5
3433 }
3434  
3435 parse_choice($lx,
3436 0 ▶ 'DEFAULT VALUES' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3437 0 lexer_shift($lx);
3438 0 $r->{default_values}= 1;
3439 },
3440  
3441 'VALUE' => 'VALUES',
3442 5 ▶ 'VALUES' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3443 5 lexer_shift($lx);
3444 5 $r->{value}= parse_list([], $lx, \&parse_expr_list_delim, ',');
3445 },
3446  
3447 8 ▶ 'SET' => sub {
Subroutine __ANON__: called CC=2 SCAR=8.4
3448 # MySQL extension, but will be normalised to VALUES clause, so we
3449 # always accept this even with !$read_dialect{mysql}.
3450 8 ▶ if ($r->{column}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"column"}) 0 8 8
3451 0 $lx->{error}= "Either column list or 'SET' expected, but found both.";
3452 0 return;
3453 }
3454 8 lexer_shift($lx);
3455 8 $r->{set}= parse_list([], $lx, \&parse_expr, ',');
3456 },
3457  
3458 13 (map { $_ => 'interpolStmt' } @SELECT_INITIAL),
3459 'interpol' => 'interpolStmt',
3460 0 ▶ 'interpolStmt' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3461 0 $r->{select}= parse_select_stmt($lx);
3462 },
3463 13 );
3464 13 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 13 13
3465  
3466 13 ▶ if ($read_dialect{mysql} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($read_dialect{"mysql"} and &looking_at($lx, "ON DUPLICATE KEY UPDATE", 1)) 1 12 13
Condition66%2/3
$read_dialect{"mysql"} and &looking_at($lx, "ON DUPLICATE KEY UPDATE", 1)
!ll&&!rl&&r
0121
MC/DC50%1/2
$read_dialect{"mysql"} and &looking_at($lx, "ON DUPLICATE KEY UPDATE", 1)
$read_dialect{"mysql"} &looking_at($lx, "ON DUPLICATE KEY UPDATE", 1)
Truth table66%2/3
A and B
A= $read_dialect{"mysql"}B= &looking_at($lx, "ON DUPLICATE KEY UPDATE", 1)
ABresult
0X0
100
111
3467 looking_at ($lx, 'ON DUPLICATE KEY UPDATE', SHIFT))
3468 {
3469 return unless
3470 1 ▶ $r->{duplicate_update}= parse_list([], $lx, \&parse_expr, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"duplicate_update"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr, ",") 0 1 1
3471 }
3472  
3473 13 lock_hash %$r;
3474 13 return $r;
3475 }
3476  
3477 sub parse_update($)
3478 9 ▶{
Subroutine parse_update: called CC=15 SCAR=29.8
Pod undocumented
3479 9 my ($lx)= @_;
3480 9 my $r= create ($lx, ['Stmt','Update'],
3481 qw(
3482 opt_front
3483 table
3484 set
3485 from
3486 join
3487 where
3488 order_by
3489 limit_cnt
3490 limit_offset
3491 )
3492 );
3493  
3494 9 ▶ return unless expect($lx, 'UPDATE', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "UPDATE", 1) 0 9 9
3495  
3496 # PostgreSQL:
3497 # - RETURNING ...
3498  
3499 9 $r->{opt_front}= [];
3500 push_option_list ($lx, $r->{opt_front}, [
3501 ($read_dialect{mysql} ?
3502 (
3503 'IGNORE',
3504 'LOW_PRIORITY',
3505 )
3506 : ()
3507 ),
3508 ($read_dialect{postgresql} ?
3509 (
3510 9 ▶ 'ONLY',
Branch: 2 branches
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 9 0 9
$read_dialect{'postgresql'} ? : 9 0 9
3511 )
3512 : ()
3513 )
3514 ]);
3515  
3516 return unless
3517 $r->{table}= parse_list([], $lx, \&parse_table_as, ',')
3518 and expect($lx, 'SET', SHIFT)
3519 9 ▶ and $r->{set}= parse_list([], $lx, \&parse_expr, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") and &expect($lx, "SET", 1) and $r->{"set"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr, ",") 0 9 9
Condition33%2/6
$r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") and &expect($lx, "SET", 1) and $r->{"set"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr, ",")
!ll&&!rl&&r
009
$r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") and &expect($lx, "SET", 1)
!ll&&!rl&&r
009
MC/DC0%0/3
$r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") and &expect($lx, "SET", 1) and $r->{"set"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr, ",")
$r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") &expect($lx, "SET", 1) $r->{"set"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr, ",")
Truth table25%1/4
A and B and C
A= $r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",")B= &expect($lx, "SET", 1)C= $r->{"set"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_expr, ",")
ABCresult
0XX0
10X0
1100
1111
3520  
3521 9 ▶ if (looking_at($lx, 'FROM', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "FROM", 1)) 1 8 9
3522 return unless
3523 1 ▶ $r->{from}= parse_list([], $lx, \&parse_table_as, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"from"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") 0 1 1
3524 }
3525 return unless
3526 9 ▶ $r->{join}= parse_try_list([], $lx, \&parse_join);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"join"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_join) 0 9 9
3527  
3528 9 ▶ if (looking_at($lx, 'WHERE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "WHERE", 1)) 9 0 9
3529 return unless
3530 9 ▶ $r->{where}= parse_where ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"where"} = &parse_where($lx) 0 9 9
3531 }
3532 9 ▶ if (looking_at($lx, 'ORDER BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ORDER BY", 1)) 1 8 9
3533 return unless
3534 1 ▶ $r->{order_by}= parse_list([], $lx, \&parse_order, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"order_by"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_order, ",") 0 1 1
3535 }
3536 9 ▶ if (looking_at($lx, 'LIMIT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "LIMIT", 1)) 1 8 9
3537 1 $r->{limit_cnt}= parse_limit_num($lx);
3538 }
3539  
3540 9 lock_hash %$r;
3541 9 return $r;
3542 }
3543  
3544 sub parse_delete($)
3545 4 ▶{
Subroutine parse_delete: called CC=14 SCAR=29.7
Pod undocumented
3546 4 my ($lx)= @_;
3547 4 my $r= create ($lx, ['Stmt','Delete'],
3548 qw(
3549 opt_front
3550 from
3551 from_opt_front
3552 join
3553 using
3554 where
3555 order_by
3556 limit_cnt
3557 limit_offset
3558 )
3559 );
3560  
3561 4 ▶ return unless expect($lx, 'DELETE', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "DELETE", 1) 0 4 4
3562  
3563 # PostgreSQL:
3564 # - RETURNING ...
3565  
3566 4 $r->{opt_front}= [];
3567 push_option_list ($lx, $r->{opt_front}, [
3568 ($read_dialect{mysql} ?
3569 (
3570 4 ▶ 'IGNORE',
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 4 0 4
3571 'LOW_PRIORITY',
3572 'QUICK'
3573 )
3574 : ()
3575 )
3576 ]);
3577  
3578 4 ▶ return unless expect($lx, 'FROM', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "FROM", 1) 0 4 4
3579  
3580 4 $r->{from_opt_front}= [];
3581 push_option ($lx, $r->{from_opt_front}, [
3582 ($read_dialect{postgresql} ?
3583 4 ▶ ('ONLY')
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'postgresql'} ? : 4 0 4
3584 : ()
3585 )
3586 ]);
3587  
3588 return unless
3589 4 ▶ $r->{from}= parse_list([], $lx, \&parse_table_as, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"from"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") 0 4 4
3590  
3591 4 ▶ if (looking_at($lx, 'USING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "USING", 1)) 2 2 4
3592 return unless
3593 2 ▶ $r->{using}= parse_list([], $lx, \&parse_table_as, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"using"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table_as, ",") 0 2 2
3594 }
3595  
3596 return unless
3597 4 ▶ $r->{join}= parse_try_list([], $lx, \&parse_join);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"join"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_join) 0 4 4
3598  
3599 4 ▶ if (looking_at($lx, 'WHERE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "WHERE", 1)) 3 1 4
3600 return unless
3601 3 ▶ $r->{where}= parse_where ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"where"} = &parse_where($lx) 0 3 3
3602 }
3603 4 ▶ if (looking_at($lx, 'ORDER BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ORDER BY", 1)) 0 4 4
3604 return unless
3605 0 ▶ $r->{order_by}= parse_list([], $lx, \&parse_order, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"order_by"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_order, ",") 0 0 0
3606 }
3607 4 ▶ if (looking_at($lx, 'LIMIT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "LIMIT", 1)) 0 4 4
3608 0 $r->{limit_cnt}= parse_limit_num($lx);
3609 }
3610  
3611 4 lock_hash %$r;
3612 4 return $r;
3613 }
3614  
3615 sub keyword($$)
3616 1 ▶{
Subroutine keyword: called CC=3 SCAR=11.2
Pod undocumented
3617 1 my ($lx, $keyword)= @_;
3618 return
3619 1 ▶ unless $keyword;
Branch: 1 branch
BranchTrueFalseTotal
unless $keyword 0 1 1
3620  
3621 1 ▶ return $keyword
Branch: 1 branch
BranchTrueFalseTotal
if ref $keyword 0 1 1
3622 if ref($keyword);
3623
3624 1 my $r= create($lx, 'Keyword', qw(keyword));
3625 1 $r->{keyword}= $keyword;
3626 1 lock_hash %$r;
3627 1 return $r;
3628 }
3629  
3630 sub parse_index_option($)
3631 1 ▶{
Subroutine parse_index_option: called CC=3 SCAR=14.2
Pod undocumented
3632 1 my ($lx)= @_;
3633 1 my $r= create($lx, 'IndexOption', qw(arg));
3634  
3635 parse_choice($lx,
3636 1 ▶ -default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3637 1 $r= undef;
3638 },
3639  
3640 # MySQL does not like it here, but only accepts it in front of the
3641 # column list, which is against the manual's description.
3642 #'USING' => sub {
3643 # lexer_shift($lx);
3644 # return unless
3645 # my $t= expect($lx, ['BTREE','HASH','RTREE'], SHIFT);
3646 # $r->{type}= 'using';
3647 # $r->{arg}= $t;
3648 #},
3649 1 );
3650 1 ▶ return unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 1 0 1
3651 0 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 0 0
3652  
3653 0 lock_hash %$r;
3654 0 return $r;
3655 }
3656  
3657 sub parse_index_type ($)
3658 3 ▶{
Subroutine parse_index_type: called CC=2 SCAR=6.9
Pod undocumented
3659 3 my ($lx)= @_;
3660 3 ▶ if (looking_at($lx, 'USING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "USING", 1)) 1 2 3
3661 1 return expect($lx, ['BTREE','HASH','RTREE'], SHIFT);
3662 }
3663 2 return;
3664 }
3665  
3666 sub parse_table_constraint($)
3667 3 ▶{
Subroutine parse_table_constraint: called CC=5 SCAR=24.3
Pod undocumented
3668 3 my ($lx)= @_;
3669 3 my $r= create($lx, "TableConstraint", qw(constraint index_type column index_option reference));
3670 3 $r->{index_option}= [];
3671  
3672 3 ▶ if (looking_at($lx, 'CONSTRAINT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "CONSTRAINT", 1)) 3 0 3
3673 return unless
3674 3 ▶ $r->{constraint}= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"constraint"} = &parse_constraint($lx) 0 3 3
3675 }
3676  
3677 parse_choice($lx,
3678 0 ▶ 'PRIMARY KEY' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3679 0 lexer_shift($lx);
3680 0 $r->{type}= 'primary_key';
3681 0 $r->{index_type}= parse_index_type($lx);
3682 return unless
3683 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3684 0 ▶ and $r->{index_option}= parse_try_list([], $lx, \&parse_index_option);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option) 0 0 0
Condition0%0/3
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
!ll&&!rl&&r
000
MC/DC0%0/2
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
Truth table0%0/3
A and B
A= $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index)B= $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
ABresult
0X0
100
111
3685 },
3686 1 ▶ 'UNIQUE' => sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
3687 1 lexer_shift($lx);
3688 1 $r->{type}= 'unique';
3689 1 $r->{index_type}= parse_index_type($lx);
3690 return unless
3691 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3692 1 ▶ and $r->{index_option}= parse_try_list([], $lx, \&parse_index_option);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option) 0 1 1
Condition33%1/3
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
!ll&&!rl&&r
001
MC/DC0%0/2
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
Truth table33%1/3
A and B
A= $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index)B= $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
ABresult
0X0
100
111
3693 },
3694 0 ▶ 'FULLTEXT' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3695 0 lexer_shift($lx);
3696 0 $r->{type}= 'fulltext';
3697 0 $r->{index_type}= parse_index_type($lx);
3698 return unless
3699 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3700 0 ▶ and $r->{index_option}= parse_try_list([], $lx, \&parse_index_option);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option) 0 0 0
Condition0%0/3
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
!ll&&!rl&&r
000
MC/DC0%0/2
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
Truth table0%0/3
A and B
A= $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index)B= $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
ABresult
0X0
100
111
3701 },
3702 0 ▶ 'SPATIAL' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
3703 0 lexer_shift($lx);
3704 0 $r->{type}= 'spatial';
3705 0 $r->{index_type}= parse_index_type($lx);
3706 return unless
3707 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3708 0 ▶ and $r->{index_option}= parse_try_list([], $lx, \&parse_index_option);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option) 0 0 0
Condition0%0/3
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
!ll&&!rl&&r
000
MC/DC0%0/2
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) and $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
Truth table0%0/3
A and B
A= $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index)B= $r->{"index_option"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_index_option)
ABresult
0X0
100
111
3709 },
3710 2 ▶ 'FOREIGN KEY' => sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
3711 2 lexer_shift($lx);
3712 2 $r->{type}= 'foreign_key';
3713 2 $r->{index_type}= parse_index_type($lx);
3714 return unless
3715 $r->{column}= parse_list_delim($lx, \&parse_column_name)
3716 2 ▶ and $r->{reference}= parse_references($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name) and $r->{"reference"} = &parse_references($lx) 0 2 2
Condition33%1/3
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name) and $r->{"reference"} = &parse_references($lx)
!ll&&!rl&&r
002
MC/DC0%0/2
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name) and $r->{"reference"} = &parse_references($lx)
$r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name) $r->{"reference"} = &parse_references($lx)
Truth table33%1/3
A and B
A= $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_name)B= $r->{"reference"} = &parse_references($lx)
ABresult
0X0
100
111
3717 },
3718 # 'CHECK' => sub {
3719 # },
3720 ($read_dialect{mysql} ?
3721 (
3722 0 ▶ 'INDEX' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
3723 0 lexer_shift($lx);
3724 0 $r->{type}= 'index';
3725 # FIXME: mysql allows an index name here
3726 return unless
3727 0 ▶ $r->{column}= parse_list_delim($lx, \&parse_column_index);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"column"} = &parse_list_delim($lx, \&SQL::Yapp::parse_column_index) 0 0 0
3728 0 $r->{index_option}= parse_try_list([], $lx, \&parse_index_option);
3729 }
3730 )
3731 3 ▶ : ()
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 3 0 3
3732 ),
3733 );
3734 3 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 3 3
3735  
3736 3 lock_hash %$r;
3737 3 return $r;
3738 }
3739  
3740 sub parse_table_option1($$$$)
3741 6 ▶{
Subroutine parse_table_option1: called CC=3 SCAR=11.0
Pod undocumented
3742 6 my ($lx, $r, $name, $parse)= @_;
3743 6 $r->{type}= 'literal';
3744 6 $r->{name}= $name;
3745 6 lexer_shift($lx);
3746 6 looking_at($lx, '=', SHIFT); # optional =
3747 return unless
3748 6 ▶ $r->{value}= $parse->($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"value"} = &$parse($lx) 0 6 6
3749 6 ▶ while (looking_at($lx, ',', SHIFT)) {} # optional ,
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ",", 1)) 1 6 7
3750 6 return $r;
3751 }
3752  
3753 sub parse_on_commit_action($)
3754 1 ▶{
Subroutine parse_on_commit_action: called CC=2 SCAR=7.2
Pod undocumented
3755 1 my ($lx)= @_;
3756 return keyword ($lx,
3757 expect($lx,
3758 [
3759 'PRESERVE ROWS',
3760 'DELETE ROWS',
3761 ($read_dialect{postgresql} ?
3762 (
3763 1 ▶ 'DROP'
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'postgresql'} ? : 1 0 1
3764 )
3765 : ()
3766 )
3767 ],
3768 SHIFT
3769 )
3770 );
3771 }
3772  
3773 sub parse_table_option($)
3774 12 ▶{
Subroutine parse_table_option: called CC=4 SCAR=14.0
Pod undocumented
3775 12 my ($lx)= @_;
3776 12 my $r= create($lx, 'TableOption', qw(name value token));
3777  
3778 parse_choice($lx,
3779 4 ▶ -default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3780 4 $r= undef;
3781 },
3782  
3783 ($read_dialect{mysql} ?
3784 (
3785 2 ▶ 'ENGINE' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3786 2 return parse_table_option1($lx, $r, 'ENGINE', \&parse_engine);
3787 },
3788
3789 'CHARACTER SET' => 'DEFAULT CHARACTER SET',
3790 2 ▶ 'DEFAULT CHARACTER SET' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3791 2 return parse_table_option1($lx, $r, 'DEFAULT CHARACTER SET', \&parse_charset);
3792 },
3793  
3794 'COLLATE' => 'DEFAULT COLLATE',
3795 0 ▶ 'DEFAULT COLLATE' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3796 0 return parse_table_option1($lx, $r, 'DEFAULT COLLATE', \&parse_collate);
3797 },
3798  
3799 0 ▶ 'AUTO_INCREMENT' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
3800 0 return parse_table_option1($lx, $r, 'AUTO_INCREMENT', \&parse_expr);
3801 },
3802  
3803 1 ▶ 'COMMENT' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3804 1 return parse_table_option1($lx, $r, 'COMMENT', \&parse_expr);
3805 },
3806 )
3807 : ()
3808 ),
3809  
3810 1 ▶ 'ON COMMIT' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3811 1 return parse_table_option1($lx, $r, 'ON COMMIT', \&parse_on_commit_action);
3812 },
3813  
3814 'interpolTableOption' => 'interpol',
3815 2 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
3816 2 $r->{type}= 'interpol';
3817 2 $r->{token}= $lx->{token};
3818 2 lexer_shift($lx);
3819 2 ▶ while (looking_at($lx, ',', SHIFT)) {} # optional ,
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ",", 1)) 1 2 3
3820 2 return $r;
3821 },
3822 12 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 12 0 12
3823 12 ▶ return unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 4 8 12
3824 8 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 8 8
3825 8 lock_hash %$r;
3826 8 return $r;
3827 }
3828  
3829 sub parse_column_def($)
3830 6 ▶{
Subroutine parse_column_def: called CC=3 SCAR=11.8
Pod undocumented
3831 6 my ($lx)= @_;
3832 6 my $r= create($lx, 'ColumnDef', qw(name column_spec));
3833 return unless
3834 $r->{name}= parse_column_name($lx)
3835 6 ▶ and $r->{column_spec}= parse_column_spec($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"name"} = &parse_column_name($lx) and $r->{"column_spec"} = &parse_column_spec($lx) 0 6 6
Condition33%1/3
$r->{"name"} = &parse_column_name($lx) and $r->{"column_spec"} = &parse_column_spec($lx)
!ll&&!rl&&r
006
MC/DC0%0/2
$r->{"name"} = &parse_column_name($lx) and $r->{"column_spec"} = &parse_column_spec($lx)
$r->{"name"} = &parse_column_name($lx) $r->{"column_spec"} = &parse_column_spec($lx)
Truth table33%1/3
A and B
A= $r->{"name"} = &parse_column_name($lx)B= $r->{"column_spec"} = &parse_column_spec($lx)
ABresult
0X0
100
111
3836 6 lock_hash %$r;
3837 6 return $r;
3838 }
3839  
3840 sub parse_column_def_or_option($)
3841 6 ▶{
Subroutine parse_column_def_or_option: called CC=1 SCAR=0.0
Pod undocumented
3842 6 my ($lx)= @_;
3843 return parse_choice($lx,
3844 'interpol' => 'ident',
3845 4 ▶ 'ident' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3846 4 return parse_column_def($lx);
3847 },
3848 2 ▶ -default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3849 2 return parse_table_constraint($lx);
3850 },
3851 6 );
3852 }
3853  
3854 sub parse_create_table($)
3855 2 ▶{
Subroutine parse_create_table: called CC=13 SCAR=27.6
Pod undocumented
3856 2 my ($lx)= @_;
3857 return unless
3858 2 ▶ expect($lx, \@CREATE_TABLE_INITIAL);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, \@CREATE_TABLE_INITIAL) 0 2 2
3859  
3860 2 my $r= create($lx, ['Stmt','CreateTable'],
3861 qw(subtype if_not_exists table column_def tabconstr tableopt select));
3862 2 $r->{subtype}= lexer_shift($lx);
3863  
3864 2 ▶ if ($read_dialect{mysql} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($read_dialect{"mysql"} and &looking_at($lx, "IF NOT EXISTS", 1)) 1 1 2
Condition66%2/3
$read_dialect{"mysql"} and &looking_at($lx, "IF NOT EXISTS", 1)
!ll&&!rl&&r
011
MC/DC50%1/2
$read_dialect{"mysql"} and &looking_at($lx, "IF NOT EXISTS", 1)
$read_dialect{"mysql"} &looking_at($lx, "IF NOT EXISTS", 1)
Truth table66%2/3
A and B
A= $read_dialect{"mysql"}B= &looking_at($lx, "IF NOT EXISTS", 1)
ABresult
0X0
100
111
3865 looking_at($lx, 'IF NOT EXISTS', SHIFT))
3866 {
3867 1 $r->{if_not_exists}= 1;
3868 }
3869  
3870 return unless
3871 2 ▶ $r->{table}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_table($lx) 0 2 2
3872  
3873 2 $r->{column_def}= [];
3874 2 $r->{tabconstr}= [];
3875 2 ▶ if (looking_at($lx, '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "(")) 2 0 2
3876 return unless
3877 2 ▶ my $spec= parse_list_delim($lx, \&parse_column_def_or_option);
Branch: 1 branch
BranchTrueFalseTotal
unless my $spec = &parse_list_delim($lx, \&SQL::Yapp::parse_column_def_or_option) 0 2 2
3878  
3879 2 $r->{column_def}= [ grep { $_->{kind} eq 'ColumnDef' } @$spec ];
3880 2 $r->{tabconstr}= [ grep { $_->{kind} ne 'ColumnDef' } @$spec ];
3881 }
3882  
3883 return unless
3884 2 ▶ $r->{tableopt}= parse_try_list([], $lx, \&parse_table_option);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"tableopt"} = &parse_try_list(scalar [], $lx, \&SQL::Yapp::parse_table_option) 0 2 2
3885  
3886 2 ▶ if (looking_at($lx, 'AS', SHIFT) ||
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "AS", 1) or &looking_at($lx, \@SELECT_INITIAL)) 1 1 2
Condition66%2/3
&looking_at($lx, "AS", 1) or &looking_at($lx, \@SELECT_INITIAL)
l!l&&r!l&&!r
101
MC/DC50%1/2
&looking_at($lx, "AS", 1) or &looking_at($lx, \@SELECT_INITIAL)
&looking_at($lx, "AS", 1) &looking_at($lx, \@SELECT_INITIAL)
Truth table66%2/3
A or B
A= &looking_at($lx, "AS", 1)B= &looking_at($lx, \@SELECT_INITIAL)
ABresult
1X1
011
000
3887 looking_at($lx, \@SELECT_INITIAL))
3888 {
3889 return unless
3890 1 ▶ $r->{select}= parse_select($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"select"} = &parse_select($lx) 0 1 1
3891 }
3892  
3893 2 ▶ unless (scalar(@{ $r->{column_def} }) || $r->{select}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$r->{"column_def"};} or $r->{"select"}) 0 2 2
Condition33%1/3
scalar @{$r->{"column_def"};} or $r->{"select"}
l!l&&r!l&&!r
200
MC/DC0%0/2
scalar @{$r->{"column_def"};} or $r->{"select"}
scalar @{$r->{"column_def"};} $r->{"select"}
Truth table33%1/3
A or B
A= scalar @{$r->{"column_def"};}B= $r->{"select"}
ABresult
1X1
011
000
3894 0 $lx->{error}= 'Either query or at least one column expected';
3895 0 return;
3896 }
3897  
3898 2 lock_hash %$r;
3899 2 return $r;
3900 }
3901  
3902 sub parse_drop_table($)
3903 1 ▶{
Subroutine parse_drop_table: called CC=5 SCAR=17.0
Pod undocumented
3904 1 my ($lx)= @_;
3905 return unless
3906 1 ▶ expect($lx, \@DROP_TABLE_INITIAL);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, \@DROP_TABLE_INITIAL) 0 1 1
3907  
3908 1 my $r= create($lx, ['Stmt','DropTable'],
3909 qw(subtype if_exists table cascade));
3910 1 $r->{subtype}= lexer_shift($lx);
3911  
3912 1 ▶ if ($read_dialect{mysql} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($read_dialect{"mysql"} and &looking_at($lx, "IF EXISTS", 1)) 1 0 1
Condition33%1/3
$read_dialect{"mysql"} and &looking_at($lx, "IF EXISTS", 1)
!ll&&!rl&&r
001
MC/DC0%0/2
$read_dialect{"mysql"} and &looking_at($lx, "IF EXISTS", 1)
$read_dialect{"mysql"} &looking_at($lx, "IF EXISTS", 1)
Truth table33%1/3
A and B
A= $read_dialect{"mysql"}B= &looking_at($lx, "IF EXISTS", 1)
ABresult
0X0
100
111
3913 looking_at($lx, 'IF EXISTS', SHIFT))
3914 {
3915 1 $r->{if_exists}= 1;
3916 }
3917  
3918 return unless
3919 1 ▶ $r->{table}= parse_list([], $lx, \&parse_table, ',');
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_list(scalar [], $lx, \&SQL::Yapp::parse_table, ",") 0 1 1
3920  
3921 1 $r->{cascade}= looking_at($lx, ['RESTRICT','CASCADE'], SHIFT);
3922  
3923 1 lock_hash %$r;
3924 1 return $r;
3925 }
3926  
3927 sub parse_column_pos_perhaps($)
3928 3 ▶{
Subroutine parse_column_pos_perhaps: called CC=1 SCAR=0.0
Pod undocumented
3929 3 my ($lx)= @_;
3930 return parse_choice($lx,
3931 1 ▶ -default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3932 1 return;
3933 },
3934 1 ▶ 'FIRST' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3935 1 return lexer_shift($lx);
3936 },
3937 1 ▶ 'AFTER' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3938 1 lexer_shift($lx);
3939 1 return ('AFTER', parse_column_name($lx));
3940 },
3941 3 );
3942 }
3943  
3944 sub parse_alter_table($)
3945 20 ▶{
Subroutine parse_alter_table: called CC=5 SCAR=16.6
Pod undocumented
3946 20 my ($lx)= @_;
3947 return unless
3948 20 ▶ expect($lx, \@ALTER_TABLE_INITIAL);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, \@ALTER_TABLE_INITIAL) 0 20 20
3949  
3950 20 my $r= create($lx, ['Stmt','AlterTable'],
3951 qw(subtype functor subfunctor arg online ignore table only));
3952 20 $r->{subtype}= lexer_shift($lx);
3953 20 $r->{arg}= [];
3954  
3955 return unless
3956 20 ▶ $r->{table}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_table($lx) 0 20 20
3957  
3958 20 $r->{only}= looking_at($lx, 'ONLY', SHIFT);
3959  
3960 parse_choice($lx,
3961 1 ▶ 'DROP CONSTRAINT' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
3962 1 $r->{functor}= lexer_shift($lx);
3963 return unless
3964 1 ▶ my $constraint= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $constraint = &parse_constraint($lx) 0 1 1
3965 1 push @{ $r->{arg} }, $constraint, looking_at($lx, ['RESTRICT','CASCADE'], SHIFT);
3966 },
3967  
3968 3 ▶ 'DROP COLUMN' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
3969 3 $r->{functor}= lexer_shift($lx);
3970 return unless
3971 3 ▶ my $column= parse_column_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $column = &parse_column_name($lx) 0 3 3
3972 3 push @{ $r->{arg} }, $column, looking_at($lx, ['RESTRICT','CASCADE'], SHIFT);
3973 },
3974  
3975 1 ▶ 'RENAME COLUMN' => sub {
Subroutine __ANON__: called CC=4 SCAR=16.4
3976 1 $r->{functor}= lexer_shift($lx);
3977  
3978 return unless
3979 1 ▶ my $column= parse_column_name($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless my $column = &parse_column_name($lx) and &expect($lx, "TO", 1) and my $column2 = &parse_column_name($lx) 0 1 1
Condition33%2/6
my $column = &parse_column_name($lx) and &expect($lx, "TO", 1) and my $column2 = &parse_column_name($lx)
!ll&&!rl&&r
001
my $column = &parse_column_name($lx) and &expect($lx, "TO", 1)
!ll&&!rl&&r
001
MC/DC0%0/3
my $column = &parse_column_name($lx) and &expect($lx, "TO", 1) and my $column2 = &parse_column_name($lx)
my $column = &parse_column_name($lx) &expect($lx, "TO", 1) my $column2 = &parse_column_name($lx)
Truth table25%1/4
A and B and C
A= my $column = &parse_column_name($lx)B= &expect($lx, "TO", 1)C= my $column2 = &parse_column_name($lx)
ABCresult
0XX0
10X0
1100
1111
3980 and expect($lx, 'TO', SHIFT)
3981 and my $column2= parse_column_name($lx);
3982  
3983 1 push @{ $r->{arg} }, $column, 'TO', $column2;
3984 },
3985  
3986 1 ▶ 'DROP PRIMARY KEY' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3987 1 $r->{functor}= lexer_shift($lx);
3988 },
3989  
3990 6 ▶ 'ALTER COLUMN' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
3991 6 $r->{functor}= lexer_shift($lx);
3992 6 push @{ $r->{arg} }, parse_column_name($lx);
3993 6 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 6 6
3994  
3995 parse_choice($lx,
3996 'DROP DEFAULT' => 'SET NOT NULL',
3997 'DROP NOT NULL' => 'SET NOT NULL',
3998 3 ▶ 'SET NOT NULL' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3999 3 push @{ $r->{arg} }, lexer_shift($lx);
4000 },
4001  
4002 1 ▶ 'SET DEFAULT' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4003 1 push @{ $r->{arg} }, lexer_shift($lx);
4004 1 push @{ $r->{arg} }, parse_expr($lx);
4005 },
4006  
4007 ($read_dialect{postgresql} ?
4008 (
4009 2 ▶ 'TYPE' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
4010 2 push @{ $r->{arg} }, lexer_shift($lx);
4011 2 push @{ $r->{arg} }, parse_type($lx);
4012 2 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 2 2
4013 2 ▶ if (my $x= looking_at($lx, 'USING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = &looking_at($lx, "USING", 1)) 1 1 2
4014 1 push @{ $r->{arg} }, $x, parse_expr($lx);
4015 }
4016 }
4017 )
4018 6 ▶ : ()
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'postgresql'} ? : 6 0 6
4019 ),
4020 );
4021 },
4022  
4023 1 ▶ 'RENAME TO' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4024 1 $r->{functor}= lexer_shift($lx);
4025 1 push @{ $r->{arg} }, parse_table($lx);
4026 },
4027  
4028 2 ▶ 'ADD COLUMN' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
4029 2 $r->{functor}= lexer_shift($lx);
4030 2 ▶ if (looking_at($lx, '(', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '(', 1)) { } 1 1 2
4031 1 push @{ $r->{arg} }, parse_list([], $lx, \&parse_column_def, ',');
4032 1 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 1 1
4033 1 expect($lx, ')', SHIFT);
4034 }
4035 else {
4036 return unless
4037 1 ▶ my $col1= parse_column_name($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless my $col1 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx) 0 1 1
Condition33%1/3
my $col1 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx)
!ll&&!rl&&r
001
MC/DC0%0/2
my $col1 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx)
my $col1 = &parse_column_name($lx) my $spec = &parse_column_spec($lx)
Truth table33%1/3
A and B
A= my $col1 = &parse_column_name($lx)B= my $spec = &parse_column_spec($lx)
ABresult
0X0
100
111
4038 and my $spec= parse_column_spec($lx);
4039 1 push @{ $r->{arg} }, $col1, $spec, parse_column_pos_perhaps($lx);
4040 }
4041 },
4042  
4043 1 ▶ 'ADD' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4044 1 $r->{functor}= lexer_shift($lx);
4045 1 push @{ $r->{arg} }, parse_table_constraint($lx);
4046 },
4047  
4048 ($read_dialect{mysql} ?
4049 (
4050 1 ▶ 'MODIFY COLUMN' => sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
4051 1 $r->{functor}= lexer_shift($lx);
4052 return unless
4053 1 ▶ my $col1= parse_column_name($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless my $col1 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx) 0 1 1
Condition33%1/3
my $col1 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx)
!ll&&!rl&&r
001
MC/DC0%0/2
my $col1 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx)
my $col1 = &parse_column_name($lx) my $spec = &parse_column_spec($lx)
Truth table33%1/3
A and B
A= my $col1 = &parse_column_name($lx)B= my $spec = &parse_column_spec($lx)
ABresult
0X0
100
111
4054 and my $spec= parse_column_spec($lx);
4055 1 push @{ $r->{arg} }, $col1, $spec, parse_column_pos_perhaps($lx);
4056 },
4057 1 ▶ 'CHANGE COLUMN' => sub {
Subroutine __ANON__: called CC=4 SCAR=16.4
4058 1 $r->{functor}= lexer_shift($lx);
4059 return unless
4060 1 ▶ my $col1= parse_column_name($lx)
Branch: 1 branch
BranchTrueFalseTotal
unless my $col1 = &parse_column_name($lx) and my $col2 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx) 0 1 1
Condition33%2/6
my $col1 = &parse_column_name($lx) and my $col2 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx)
!ll&&!rl&&r
001
my $col1 = &parse_column_name($lx) and my $col2 = &parse_column_name($lx)
!ll&&!rl&&r
001
MC/DC0%0/3
my $col1 = &parse_column_name($lx) and my $col2 = &parse_column_name($lx) and my $spec = &parse_column_spec($lx)
my $col1 = &parse_column_name($lx) my $col2 = &parse_column_name($lx) my $spec = &parse_column_spec($lx)
Truth table25%1/4
A and B and C
A= my $col1 = &parse_column_name($lx)B= my $col2 = &parse_column_name($lx)C= my $spec = &parse_column_spec($lx)
ABCresult
0XX0
10X0
1100
1111
4061 and my $col2= parse_column_name($lx)
4062 and my $spec= parse_column_spec($lx);
4063 1 push @{ $r->{arg} }, $col1, $col2, $spec, parse_column_pos_perhaps($lx);
4064 },
4065 1 ▶ 'DROP FOREIGN KEY' => sub { # standard SQL: DROP CONSTRAINT
Subroutine __ANON__: called CC=2 SCAR=7.0
4066 1 $r->{functor}= lexer_shift($lx);
4067 return unless
4068 1 ▶ my $constraint= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $constraint = &parse_constraint($lx) 0 1 1
4069 1 push @{ $r->{arg} }, $constraint;
4070 },
4071 1 ▶ 'DROP INDEX' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
4072 1 $r->{functor}= lexer_shift($lx);
4073 return unless
4074 1 ▶ my $index= parse_index($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $index = &parse_index($lx) 0 1 1
4075 1 push @{ $r->{arg} }, $index;
4076 },
4077 )
4078 20 ▶ : ()
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 20 0 20
4079 ),
4080 );
4081 20 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 20 20
4082  
4083 20 lock_hash %$r;
4084 20 return $r;
4085 }
4086  
4087 sub parse_stmt_interpol($)
4088 3 ▶{
Subroutine parse_stmt_interpol: called CC=5 SCAR=20.0
Pod undocumented
4089 3 my ($lx)= @_;
4090  
4091 # Some interpols will never be good statements, so issue an error as early
4092 # as possible (i.e., at compile time instead of at runtime):
4093 3 ▶ if ($lx->{token}{type} eq 'num' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{"token"}{"type"} eq "num" or $lx->{"token"}{"type"} eq "string") 0 3 3
Condition33%1/3
$lx->{"token"}{"type"} eq "num" or $lx->{"token"}{"type"} eq "string"
l!l&&r!l&&!r
003
MC/DC0%0/2
$lx->{"token"}{"type"} eq "num" or $lx->{"token"}{"type"} eq "string"
$lx->{"token"}{"type"} eq "num" $lx->{"token"}{"type"} eq "string"
Truth table33%1/3
A or B
A= $lx->{"token"}{"type"} eq "num"B= $lx->{"token"}{"type"} eq "string"
ABresult
1X1
011
000
4094 $lx->{token}{type} eq 'string')
4095 {
4096 0 $lx->{error}= "Expected 'Stmt', but found $lx->{token}{type}";
4097 0 return;
4098 }
4099  
4100 3 ▶ if (! $lx->{token}{type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lx->{"token"}{"type"}) 0 3 3
4101 0 $lx->{error}= "Expected 'Stmt', but found $lx->{token}{kind}";
4102 0 return;
4103 }
4104  
4105 3 ▶ if ($lx->{token}{perltype} eq 'hash') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{"token"}{"perltype"} eq "hash") 0 3 3
4106 0 $lx->{error}= "Expected scalar or array, but found $lx->{token}{perltype}.";
4107 0 return;
4108 }
4109  
4110 # But some may be:
4111 3 my $r= create ($lx, ['Stmt','Interpol'], qw(token));
4112 3 $r->{token}= $lx->{token};
4113 3 lexer_shift($lx);
4114  
4115 3 lock_hash %$r;
4116 3 return $r;
4117 }
4118  
4119 sub parse_select_stmt($)
4120 8 ▶{
Subroutine parse_select_stmt: called CC=1 SCAR=0.2
Pod undocumented
4121 8 my ($lx)= @_;
4122 return parse_choice($lx,
4123 8 ▶ 'SELECT' => sub { parse_select ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4124  
4125 'interpolStmt' => 'interpol',
4126 0 ▶ 'interpol' => sub { parse_stmt_interpol ($lx) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4127 8 );
4128 }
4129  
4130 sub parse_stmt($)
4131 228 ▶{
Subroutine parse_stmt: called CC=1 SCAR=0.0
Pod undocumented
4132 228 my ($lx)= @_;
4133 return parse_choice($lx,
4134 176 ▶ 'SELECT' => sub { parse_select ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4135 13 ▶ 'INSERT' => sub { parse_insert ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4136 9 ▶ 'UPDATE' => sub { parse_update ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4137 4 ▶ 'DELETE' => sub { parse_delete ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4138  
4139 1368 (map { $_ => 'CREATE TABLE' } @CREATE_TABLE_INITIAL),
4140 2 ▶ 'CREATE TABLE' => sub { parse_create_table($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4141  
4142 456 (map { $_ => 'DROP TABLE' } @DROP_TABLE_INITIAL),
4143 1 ▶ 'DROP TABLE' => sub { parse_drop_table($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4144  
4145 1368 (map { $_ => 'ALTER TABLE' } @ALTER_TABLE_INITIAL),
4146 20 ▶ 'ALTER TABLE' => sub { parse_alter_table($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4147  
4148 'interpolStmt' => 'interpol',
4149 3 ▶ 'interpol' => sub { parse_stmt_interpol ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4150 228 );
4151 }
4152  
4153 ######################################################################
4154 # Perl generation:
4155  
4156  
4157 ## First: creating a list of strings.
4158 #
4159 # The str_ family implements a simple concatenator for strings. The goal
4160 # is to generate a list of literal strings and Perl code generating strings,
4161 # separated by commas. For appending such things to the list, there is
4162 # str_append_str() and str_append_perl(), resp. E.g.:
4163 #
4164 # my $s= str_new();
4165 # str_append_str ($s, "a");
4166 # str_append_perl ($s, "b");
4167 #
4168 # This would result in the following string:
4169 #
4170 # 'a',b
4171 #
4172 # Appending the comma separator is done automatically.
4173 #
4174 # Further, we need to keep track of the line number. So there is a function
4175 # str_target_line() for setting the target line number for the next string
4176 # or raw perl code that is appended. Appending the necessary newline
4177 # characters is done automatically by the str_ functions.
4178 #
4179 # Finally, we need to generate substrings by joining them. This is done
4180 # with the str_append_join() and str_append_end() functions. E.g.
4181 #
4182 # my $s= str_new();
4183 # str_append_str ($s, 'a');
4184 # str_append_join ($s, sep => ':');
4185 # str_append_perl ($s, 'b');
4186 # str_target_line ($s, 2);
4187 # str_append_str ($s, 'c');
4188 # str_append_end ($s);
4189 # str_append_perl ($s, 'd');
4190 #
4191 # This results in the following string in $s:
4192 #
4193 # 'a',join(':',b,
4194 # 'c'),d
4195 #
4196 # Another possible sub-list structure is a map, which can be added with
4197 # str_append_map() ... str_append_en() functions. E.g.:
4198 #
4199 # str_append_str ($s, 'a');
4200 # str_append_map ($s, '$_." DESC"');
4201 # str_append_perl ($s, 'b');
4202 # str_append_str ($s, 'c');
4203 # str_append_end ($s);
4204 # str_append_perl ($s, 'd');
4205 #
4206 # This results in:
4207 #
4208 # 'a',(map{$_." DESC"} b,'c'),d
4209 #
4210 # A str_append_min1() ... str_append_end() block checks that there
4211 # is at least one result in the enclosed list. This, together with
4212 # _max1_if_scalar, are slightly inefficient and should later be eliminated
4213 # if possible.
4214 #
4215 # str_get_string() returns the current string as composed so far. If the
4216 # string is empty, an empty list () is returned instead, because the
4217 # empty string is not a valid syntactic empty list in Perl, so it causes
4218 # problems, e.g. after map:
4219 #
4220 # (map {...} -->HERE<--)
4221 #
4222 # If we insert an empty string -->HERE<--, then we get a syntax error.
4223 #
4224 # The implementation of the str_ family is very straightforward: we have a
4225 # current state that is updated and a string that is appended to accordingly.
4226 sub str_new($)
4227 278 ▶{
Subroutine str_new: called CC=1 SCAR=0.0
Pod undocumented
4228 278 my ($line_start)= @_;
4229 278 my $text= [];
4230 278 my $s= {
4231 buff => '',
4232 need_comma => 0,
4233 line_is => 1,
4234 line_target => 1,
4235 line_start => $line_start,
4236 end_str => [], # final str to push, if defined
4237 };
4238 278 lock_keys %$s; # poor-man's bless()
4239 278 return $s;
4240 }
4241  
4242 sub str_append_raw($$)
4243 11884 ▶{
Subroutine str_append_raw: called CC=1 SCAR=0.0
Pod undocumented
4244 11884 my ($s, $text)= @_;
4245 11884 $s->{buff}.= $text;
4246 11884 $s->{line_is}+= ($text =~ tr/\n//);
4247 }
4248  
4249 sub str_sync_line($)
4250 5929 ▶{
Subroutine str_sync_line: called CC=2 SCAR=6.9
Pod undocumented
4251 5929 my ($s)= @_;
4252 5929 ▶ while ($s->{line_is} < $s->{line_target}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"line_is"} < $s->{"line_target"}) 315 5929 6244
4253 315 str_append_raw ($s, "\n");
4254 }
4255 }
4256 sub str_target_line($$)
4257 2885 ▶{
Subroutine str_target_line: called CC=2 SCAR=7.1
Pod undocumented
4258 2885 my ($s, $n)= @_;
4259 2885 ▶ my_confess "undefined line number" unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 2885 2885
4260 2885 $s->{line_target}= $n;
4261 }
4262  
4263 sub str_append_comma($)
4264 7553 ▶{
Subroutine str_append_comma: called CC=2 SCAR=6.9
Pod undocumented
4265 7553 my ($s)= @_;
4266 7553 ▶ if ($s->{need_comma}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"need_comma"}) 3877 3676 7553
4267 3877 str_append_raw ($s, COMMA_STR);
4268 3877 $s->{need_comma}= 0;
4269 }
4270 }
4271  
4272 sub str_append_perl($$)
4273 4435 ▶{
Subroutine str_append_perl: called CC=2 SCAR=7.0
Pod undocumented
4274 4435 my ($s, $perl)= @_;
4275 4435 ▶ if ($perl ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl ne "") 4435 0 4435
4276 4435 str_append_comma($s);
4277 4435 str_sync_line ($s);
4278 4435 str_append_raw ($s, $perl);
4279 4435 $s->{need_comma}= 1;
4280 }
4281 }
4282  
4283 sub str_append_str($$)
4284 2690 ▶{
Subroutine str_append_str: called CC=1 SCAR=0.0
Pod undocumented
4285 2690 my ($s, $contents)= @_;
4286 2690 str_append_perl ($s, quote_perl($contents));
4287 }
4288  
4289 sub str_append_join($%)
4290 783 ▶{
Subroutine str_append_join: called CC=16 SCAR=27.8
Pod undocumented
4291 783 my ($s, %opt)= @_;
4292 783 ▶ $opt{prefix}||= '';
Condition100%2/2
$opt{"prefix"} ||= ""
l!l
390393
MC/DC100%1/1
$opt{"prefix"} ||= ""
$opt{"prefix"}
Truth table100%2/2
A
A= $opt{"prefix"}
Aresult
11
00
4293 783 ▶ $opt{suffix}||= '';
Condition100%2/2
$opt{"suffix"} ||= ""
l!l
42741
MC/DC100%1/1
$opt{"suffix"} ||= ""
$opt{"suffix"}
Truth table100%2/2
A
A= $opt{"suffix"}
Aresult
11
00
4294 783 ▶ $opt{sep}||= '';
Condition100%2/2
$opt{"sep"} ||= ""
l!l
420363
MC/DC100%1/1
$opt{"sep"} ||= ""
$opt{"sep"}
Truth table100%2/2
A
A= $opt{"sep"}
Aresult
11
00
4295  
4296 783 str_append_comma($s);
4297 783 str_sync_line ($s);
4298 783 ▶ if ($opt{joinfunc}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($opt{'joinfunc'}) { } 94 689 783
elsif ($opt{'prefix'} eq '' and $opt{'suffix'} eq '' and $opt{'never_empty'} || defined $opt{'result0'} && $opt{'result0'} eq '') { } 262 427 689
elsif ($opt{'sep'} eq '' and $opt{'never_empty'} || defined $opt{'result0'} && $opt{'result0'} eq $opt{'prefix'} . $opt{'suffix'}) { } 21 406 427
4299 # special case: ignore all other settings
4300 94 str_append_raw ($s, "$opt{joinfunc}(");
4301 94 $s->{need_comma}= 0;
4302 94 push @{ $s->{end_str} }, undef;
4303 }
4304 ▶ elsif ($opt{prefix} eq '' &&
Condition83%10/12
$opt{"prefix"} eq "" and $opt{"suffix"} eq "" and $opt{"never_empty"} || defined $opt{"result0"} && $opt{"result0"} eq ""
!ll&&!rl&&r
39037262
$opt{"prefix"} eq "" and $opt{"suffix"} eq ""
!ll&&!rl&&r
3900299
$opt{"never_empty"} or defined $opt{"result0"} and $opt{"result0"} eq ""
l!l&&r!l&&!r
2511137
defined $opt{"result0"} and $opt{"result0"} eq ""
!ll&&!rl&&r
37011
MC/DC60%3/5
$opt{"prefix"} eq "" and $opt{"suffix"} eq "" and $opt{"never_empty"} || defined $opt{"result0"} && $opt{"result0"} eq ""
$opt{"prefix"} eq "" $opt{"suffix"} eq "" $opt{"never_empty"} defined $opt{"result0"} $opt{"result0"} eq ""
Truth table66%4/6
A and B and C or D and E
A= $opt{"prefix"} eq ""B= $opt{"suffix"} eq ""C= $opt{"never_empty"}D= defined $opt{"result0"}E= $opt{"result0"} eq ""
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
4305 $opt{suffix} eq '' &&
4306 (
4307 $opt{never_empty} ||
4308 (defined $opt{result0} && $opt{result0} eq '')
4309 ))
4310 {
4311 # simple case 1
4312 262 str_append_raw ($s, 'join(');
4313 262 str_append_str ($s, $opt{sep});
4314 262 $s->{need_comma}= 1;
4315 262 push @{ $s->{end_str} }, undef;
4316 }
4317 ▶ elsif ($opt{sep} eq '' &&
Condition66%6/9
$opt{"sep"} eq "" and $opt{"never_empty"} || defined $opt{"result0"} && $opt{"result0"} eq $opt{"prefix"} . $opt{"suffix"}
!ll&&!rl&&r
405121
$opt{"never_empty"} or defined $opt{"result0"} and $opt{"result0"} eq $opt{"prefix"} . $opt{"suffix"}
l!l&&r!l&&!r
2101
defined $opt{"result0"} and $opt{"result0"} eq $opt{"prefix"} . $opt{"suffix"}
!ll&&!rl&&r
100
MC/DC50%2/4
$opt{"sep"} eq "" and $opt{"never_empty"} || defined $opt{"result0"} && $opt{"result0"} eq $opt{"prefix"} . $opt{"suffix"}
$opt{"sep"} eq "" $opt{"never_empty"} defined $opt{"result0"} $opt{"result0"} eq $opt{"prefix"} . $opt{"suffix"}
Truth table60%3/5
A and B or C and D
A= $opt{"sep"} eq ""B= $opt{"never_empty"}C= defined $opt{"result0"}D= $opt{"result0"} eq $opt{"prefix"} . $opt{"suffix"}
ABCDresult
0XXX0
100X0
10100
11XX1
10111
4318 (
4319 $opt{never_empty} ||
4320 (defined $opt{result0} && $opt{result0} eq $opt{prefix}.$opt{suffix})
4321 ))
4322 {
4323 # simple case 2
4324 21 str_append_raw ($s, 'join(');
4325 21 str_append_str ($s, '');
4326  
4327 21 ▶ if($opt{prefix} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"prefix"} ne "") 21 0 21
4328 21 str_append_str ($s, $opt{prefix});
4329 }
4330  
4331 21 ▶ push @{ $s->{end_str} }, $opt{suffix} || undef;
Condition100%2/2
$opt{'suffix'} || undef
l!l
183
MC/DC100%1/1
$opt{'suffix'} || undef
$opt{'suffix'}
Truth table100%2/2
A
A= $opt{'suffix'}
Aresult
11
00
4332 }
4333 else {
4334 # complex case:
4335 406 str_append_raw ($s, __PACKAGE__.'::joinlist(');
4336 406 str_append_perl ($s, $s->{line_target} + $s->{line_start});
4337 # Unfortunately, Perl's caller() is often imprecise for the
4338 # generated code, and I couldn't find a cause for that to avoid
4339 # that. So the original line number is passed long for
4340 # nicer error messages if necessary.
4341 406 str_append_comma($s);
4342 406 str_append_str ($s, $opt{result0});
4343 406 str_append_comma($s);
4344 406 str_append_str ($s, $opt{prefix});
4345 406 str_append_comma($s);
4346 406 str_append_str ($s, $opt{sep});
4347 406 str_append_comma($s);
4348 406 str_append_str ($s, $opt{suffix});
4349 406 $s->{need_comma}= 1;
4350 406 push @{ $s->{end_str} }, undef;
4351 }
4352 }
4353  
4354 sub str_append_map($$)
4355 178 ▶{
Subroutine str_append_map: called CC=1 SCAR=0.0
Pod undocumented
4356 178 my ($s,$code)= @_;
4357 178 str_append_comma($s);
4358 178 str_sync_line ($s);
4359 178 str_append_raw ($s, "(map{ $code } ");
4360 178 $s->{need_comma}= 0;
4361 178 push @{ $s->{end_str} }, undef;
4362 }
4363  
4364 sub str_append_funcall_begin($$$)
4365 532 ▶{
Subroutine str_append_funcall_begin: called CC=2 SCAR=6.9
Pod undocumented
4366 532 my ($s, $func, $in_list)= @_;
4367 532 str_append_comma($s);
4368 532 str_sync_line ($s);
4369 532 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 280 252 532
4370 280 str_append_raw ($s, "(map { $func(");
4371 }
4372 else {
4373 252 str_append_raw ($s, "$func(");
4374 }
4375 532 $s->{need_comma}= 0;
4376 532 push @{ $s->{end_str} }, undef;
4377 }
4378  
4379 sub str_append_funcall_end($$)
4380 532 ▶{
Subroutine str_append_funcall_end: called CC=2 SCAR=6.9
Pod undocumented
4381 532 my ($s, $in_list)= @_;
4382 532 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) 280 252 532
4383 280 str_append_perl ($s, '$_');
4384 280 str_append_raw ($s, ') }');
4385 280 $s->{need_comma}= 0;
4386 }
4387 }
4388  
4389 sub str_append_funcall($$$)
4390 454 ▶{
Subroutine str_append_funcall: called CC=1 SCAR=0.0
Pod undocumented
4391 454 my ($s, $code, $in_list)= @_;
4392 454 str_append_funcall_begin ($s, $code, $in_list);
4393 454 str_append_funcall_end ($s, $in_list);
4394 }
4395  
4396 sub str_append_end($)
4397 # Terminator for:
4398 # str_append_map
4399 # str_append_funcall
4400 # str_append_join
4401 1483 ▶{
Subroutine str_append_end: called CC=2 SCAR=6.9
Pod undocumented
4402 1483 my ($s)= @_;
4403 1483 my $end_str= pop @{ $s->{end_str} };
4404 1483 ▶ if (defined $end_str) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $end_str) 18 1465 1483
4405 18 str_append_str($s, $end_str);
4406 }
4407 1483 str_append_raw ($s, ')');
4408 1483 $s->{need_comma}= 1;
4409 }
4410  
4411 sub str_get_string($)
4412 275 ▶{
Subroutine str_get_string: called CC=2 SCAR=7.1
Pod undocumented
4413 275 my ($s)= @_;
4414 275 ▶ return '()' if $s->{buff} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"buff"} eq "" 0 275 275
4415 275 return $s->{buff};
4416 }
4417  
4418 # Now start appending more complex things:
4419  
4420 sub str_append_thing($$$$);
4421  
4422 sub str_append_list($$$;%)
4423 # If you know the list is non-empty, please specify never_empty => 1
4424 # so str_append_join() can optimise.
4425 365 ▶{
Subroutine str_append_list: called CC=5 SCAR=16.1
Pod undocumented
4426 365 my ($str, $list, $parens, %opt)= @_;
4427 365 local $SIG{__DIE__}= \&my_confess;
4428  
4429 # set line to first element (if any):
4430 365 ▶ if (scalar(@$list)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list) 365 0 365
4431 365 str_target_line ($str, $list->[0]{line});
4432 }
4433  
4434 # joining, delimiters, result if empty:
4435 str_append_join($str,
4436 sep => defined $opt{sep} ? $opt{sep} : COMMA_STR, # waiting for Perl 5.10: //
4437 prefix => $opt{prefix},
4438 suffix => $opt{suffix},
4439 result0 => $opt{result0},
4440 365 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'sep'} ? : 2 363 365
4441  
4442 # map?
4443 365 ▶ if (my $x= $opt{map}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $opt{"map"}) 1 364 365
4444 1 str_append_comma ($str);
4445 1 str_sync_line ($str);
4446 1 str_append_raw ($str, "map{$x} ");
4447 1 $str->{need_comma}= 0;
4448 };
4449  
4450 # the list:
4451 365 for my $l (@$list) {
4452 439 str_append_thing ($str, $l, IN_LIST, $parens);
4453 }
4454  
4455 # end:
4456 363 str_append_end($str);
4457 }
4458  
4459 sub interpol_set_context ($$);
4460  
4461 sub perl_val($$$)
4462 1068 ▶{
Subroutine perl_val: called CC=3 SCAR=11.6
Pod undocumented
4463 1068 my ($token, $ctxt, $allow)= @_;
4464  
4465 my_confess "Expected ".(english_or \&quote_perl, $allow).", but found '$token->{kind}'"
4466 if $allow &&
4467 1068 ▶ scalar(grep { $token->{kind} eq $_ } flatten($allow)) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $allow and scalar grep({$token->{"kind"} eq $_;} &flatten($allow)) == 0 0 1068 1068
Condition66%2/3
$allow and scalar grep({$token->{"kind"} eq $_;} &flatten($allow)) == 0
!ll&&!rl&&r
1036320
MC/DC0%0/2
$allow and scalar grep({$token->{"kind"} eq $_;} &flatten($allow)) == 0
$allow scalar grep({$token->{"kind"} eq $_;} &flatten($allow)) == 0
Truth table66%2/3
A and B
A= $allowB= scalar grep({$token->{"kind"} eq $_;} &flatten($allow)) == 0
ABresult
0X0
100
111
4468  
4469 return switch($token->{kind},
4470 535 ▶ 'ident' => sub { quote_perl($token->{value}) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4471 12 ▶ '*' => sub { __PACKAGE__.'::ASTERISK' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4472 2 ▶ '?' => sub { __PACKAGE__.'::QUESTION' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4473 2 ▶ 'NULL' => sub { __PACKAGE__.'::NULL' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4474 1 ▶ 'TRUE' => sub { __PACKAGE__.'::TRUE' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4475 0 ▶ 'FALSE' => sub { __PACKAGE__.'::FALSE' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4476 0 ▶ 'UNKNOWN' => sub { __PACKAGE__.'::UNKNOWN' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4477 1 ▶ 'DEFAULT' => sub { __PACKAGE__.'::DEFAULT' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4478 515 ▶ -default => sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
4479 515 ▶ if ($token->{kind} =~ /^interpol/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{'kind'} =~ /^interpol/) { } 515 0 515
4480 515 return interpol_set_context ($token->{value}, $ctxt);
4481 }
4482 else {
4483 0 my_confess "No idea how to print thing in Perl: ".token_describe($token);
4484 }
4485 }
4486 1068 );
4487 }
4488  
4489 sub perl_val_list($$$)
4490 46 ▶{
Subroutine perl_val_list: called CC=2 SCAR=6.9
Pod undocumented
4491 46 my ($token, $ctxt, $allow)= @_;
4492 46 my $s= perl_val($token, $ctxt, $allow);
4493  
4494 46 ▶ if ($token->{perltype} eq 'hash') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{'perltype'} eq 'hash') { } 9 37 46
4495 9 return "sort keys $s";
4496 }
4497 else {
4498 37 return $s;
4499 }
4500 }
4501  
4502 sub token_pos($)
4503 3 ▶{
Subroutine token_pos: called CC=1 SCAR=0.0
Pod undocumented
4504 3 my ($token)= @_;
4505 3 return "$token->{lx}{file}:".($token->{line} + $token->{lx}{line_start});
4506 }
4507  
4508 sub lx_pos($)
4509 2 ▶{
Subroutine lx_pos: called CC=1 SCAR=0.0
Pod undocumented
4510 2 my ($lx)= @_;
4511 2 return "$lx->{file}:".($lx->{line} + $lx->{line_start});
4512 }
4513  
4514 sub croak_unless_scalar($)
4515 870 ▶{
Subroutine croak_unless_scalar: called CC=3 SCAR=11.1
Pod undocumented
4516 870 my ($token)= @_;
4517 die token_pos($token).": ".
4518 "Error: Scalar context, embedded Perl must not be syntactic array or hash.\n"
4519 870 ▶ if $token->{perltype} eq 'array' || $token->{perltype} eq 'hash';
Branch: 1 branch
BranchTrueFalseTotal
if $token->{"perltype"} eq "array" or $token->{"perltype"} eq "hash" 3 867 870
Condition66%2/3
$token->{"perltype"} eq "array" or $token->{"perltype"} eq "hash"
l!l&&r!l&&!r
30867
MC/DC50%1/2
$token->{"perltype"} eq "array" or $token->{"perltype"} eq "hash"
$token->{"perltype"} eq "array" $token->{"perltype"} eq "hash"
Truth table66%2/3
A or B
A= $token->{"perltype"} eq "array"B= $token->{"perltype"} eq "hash"
ABresult
1X1
011
000
4520 }
4521  
4522 sub str_append_typed($$$$$%)
4523 476 ▶{
Subroutine str_append_typed: called CC=6 SCAR=17.9
Pod undocumented
4524 476 my ($str, $callback, $ctxt, $thing, $in_list, %opt)= @_;
4525 476 my $q_val= perl_val ($thing->{token}, $ctxt, undef);
4526  
4527 476 ▶ if (!$in_list ||
Branch: 2 branches
BranchTrueFalseTotal
if (not $in_list or $thing->{'token'}{'perltype'} eq 'scalar') { } 360 116 476
elsif ($thing->{'token'}{'perltype'} eq 'hash') { } 19 97 116
Condition100%3/3
not $in_list or $thing->{"token"}{"perltype"} eq "scalar"
l!l&&r!l&&!r
209151116
MC/DC100%2/2
not $in_list or $thing->{"token"}{"perltype"} eq "scalar"
not $in_list $thing->{"token"}{"perltype"} eq "scalar"
Truth table100%3/3
not(A) or B
A= not $in_listB= $thing->{"token"}{"perltype"} eq "scalar"
ABresult
1X1
011
000
4528 $thing->{token}{perltype} eq 'scalar')
4529 {
4530 360 croak_unless_scalar ($thing->{token});
4531 358 str_append_perl ($str, __PACKAGE__."::${callback}($q_val)");
4532 }
4533 elsif ($thing->{token}{perltype} eq 'hash') {
4534 19 ▶ if ($opt{hash}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{'hash'}) { } 16 3 19
elsif ($opt{'hashkeys'}) { } 3 0 3
4535 16 str_append_perl ($str, __PACKAGE__."::${callback}_hash($q_val)");
4536 }
4537 elsif ($opt{hashkeys}) {
4538 3 str_append_map ($str, __PACKAGE__."::${callback}(\$_)");
4539 3 str_append_perl ($str, "sort keys $q_val");
4540 3 str_append_end ($str);
4541 }
4542 else {
4543 0 die token_pos($thing->{token}).": Error: Hashes are not allowed here.\n";
4544 }
4545 }
4546 else {
4547 97 str_append_map ($str, __PACKAGE__."::${callback}(\$_)");
4548 97 str_append_perl ($str, $q_val);
4549 97 str_append_end ($str);
4550 }
4551 }
4552  
4553 sub is_multicol($);
4554 sub is_multicol($)
4555 526 ▶{
Subroutine is_multicol: called CC=1 SCAR=0.0
Pod undocumented
4556 526 my ($thing) = @_;
4557 return switch ($thing->{kind},
4558 170 ▶ 'ExprAs' => sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
4559 170 return is_multicol($thing->{expr});
4560 },
4561 170 ▶ 'Expr' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
4562 170 ▶ if ($thing->{type} eq 'column') {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"type"} eq "column") 93 77 170
4563 93 return is_multicol($thing->{arg});
4564 }
4565 77 return 0;
4566 },
4567 93 ▶ 'Column' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4568 93 return is_multicol($thing->{ident_chain}[-1]);
4569 },
4570 7 ▶ '*' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4571 7 return 1;
4572 },
4573 21 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4574 21 return $thing->{perltype} ne 'scalar';
4575 },
4576 65 ▶ -default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
4577 65 return 0;
4578 },
4579 526 );
4580 }
4581  
4582 # Contexts for the different sql{...} interpolation blocks:
4583 5 my %ident_context= (
4584 'Column' => {
4585 1 => [ 'Column' ],
4586 2 => [ 'Table', 'none' ],
4587 },
4588 );
4589  
4590 sub str_append_ident_chain($$$@)
4591 519 ▶{
Subroutine str_append_ident_chain: called CC=10 SCAR=23.1
Pod undocumented
4592 519 my ($str, $in_list, $family, @token)= @_;
4593 519 my $func= lc($family);
4594  
4595 519 ▶ my $ctxt= $ident_context{$family}{scalar @token} ||
Branch: 1 branch
BranchTrueFalseTotal
scalar @token == 1 ? : 181 11 192
Condition66%2/3
$ident_context{$family}{scalar @token} || (scalar @token == 1 ? [$family] : [map('none', 1 .. scalar @token)])
l!l&&r!l&&!r
3271920
MC/DC0%0/2
$ident_context{$family}{scalar @token} || (scalar @token == 1 ? [$family] : [map('none', 1 .. scalar @token)])
$ident_context{$family}{scalar @token} (scalar @token == 1 ? [$family] : [map('none', 1 .. scalar @token)])
Truth table66%2/3
A || B
A= $ident_context{$family}{scalar @token}B= (scalar @token == 1 ? [$family] : [map('none', 1 .. scalar @token)])
ABresult
1X1
011
000
4596 (scalar(@token) == 1 ?
4597 [ $family ]
4598 : [ map 'none', 1..scalar(@token) ]
4599 );
4600  
4601 519 my $n= scalar(@token);
4602 519 my @non_scalar_i= grep { $token[$_]{perltype} ne 'scalar' } 0..$n-1;
4603  
4604 519 ▶ if (!$in_list ||
Branch: 2 branches
BranchTrueFalseTotal
if (not $in_list or scalar @non_scalar_i == 0) { } 477 42 519
elsif (scalar @non_scalar_i == 1) { } 38 4 42
Condition100%3/3
not $in_list or scalar @non_scalar_i == 0
l!l&&r!l&&!r
16631142
MC/DC100%2/2
not $in_list or scalar @non_scalar_i == 0
not $in_list scalar @non_scalar_i == 0
Truth table100%3/3
not(A) or B
A= not $in_listB= scalar @non_scalar_i == 0
ABresult
1X1
011
000
4605 scalar(@non_scalar_i) == 0)
4606 {
4607 477 for my $a (@token) { croak_unless_scalar ($a); }
4608 my $q_vals= join(",",
4609 map
4610 476 { perl_val($token[$_], $ctxt->[$_], undef) }
4611 0..$n-1
4612 );
4613 476 str_append_perl ($str, __PACKAGE__."::${func}${n}($q_vals)");
4614 }
4615 elsif (scalar(@non_scalar_i) == 1) {
4616 str_append_map ($str,
4617 __PACKAGE__."::${func}${n}(".
4618 join(",",
4619 map {
4620 38 ▶ ($token[$_]{perltype} eq 'scalar' ?
Branch: 1 branch
BranchTrueFalseTotal
$token[$_]{'perltype'} eq 'scalar' ? : 5 38 43
4621 perl_val($token[$_], $ctxt->[$_], undef)
4622 : '$_'
4623 )
4624 }
4625 0..$n-1
4626 ).
4627 ")"
4628 );
4629 38 my ($i)= @non_scalar_i;
4630 38 str_append_perl ($str, perl_val_list($token[$i], $ctxt->[$i], undef));
4631 38 str_append_end ($str);
4632 }
4633 else {
4634 4 ▶ my $f_ident= "${func}${n}_".join('', map{ $_->{perltype} eq 'scalar' ? 1 : 'n' } @token);
Branch: 1 branch
BranchTrueFalseTotal
$_->{'perltype'} eq 'scalar' ? : 0 8 8
4635 str_append_perl ($str,
4636 __PACKAGE__."::$f_ident(".
4637 join(",",
4638 map {
4639 4 ▶ ($token[$_]{perltype} eq 'scalar' ?
Branch: 1 branch
BranchTrueFalseTotal
$token[$_]{'perltype'} eq 'scalar' ? : 0 8 8
4640 perl_val($token[$_], $ctxt->[$_], undef)
4641 : '['.perl_val_list($token[$_], $ctxt->[$_], undef).']'
4642 )
4643 }
4644 0..$n-1
4645 ).
4646 ")"
4647 );
4648 }
4649 }
4650  
4651 sub str_append_limit ($$$)
4652 111 ▶{
Subroutine str_append_limit: called CC=5 SCAR=16.2
Pod undocumented
4653 111 my ($str, $limit_cnt, $limit_offset)= @_;
4654  
4655 111 ▶ if (defined $limit_cnt || defined $limit_offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit_cnt or defined $limit_offset) 5 106 111
Condition66%2/3
defined $limit_cnt or defined $limit_offset
l!l&&r!l&&!r
50106
MC/DC50%1/2
defined $limit_cnt or defined $limit_offset
defined $limit_cnt defined $limit_offset
Truth table66%2/3
A or B
A= defined $limit_cntB= defined $limit_offset
ABresult
1X1
011
000
4656 5 my $limit_cnt_str= 'undef';
4657 5 ▶ if ($limit_cnt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit_cnt) 5 0 5
4658 5 $limit_cnt_str= perl_val($limit_cnt, 'Expr', ['interpol', 'interpolExpr', '?']);
4659 }
4660  
4661 5 my $limit_offset_str= 'undef';
4662 5 ▶ if ($limit_offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit_offset) 3 2 5
4663 3 $limit_offset_str= perl_val($limit_offset, 'Expr', ['interpol', 'interpolExpr', '?']);
4664 }
4665  
4666 5 str_append_perl ($str, __PACKAGE__."::limit($limit_cnt_str, $limit_offset_str)");
4667 }
4668 }
4669  
4670 sub str_append_parens($$$)
4671 18 ▶{
Subroutine str_append_parens: called CC=2 SCAR=8.1
Pod undocumented
4672 18 my ($str, $thing, $in_list)= @_;
4673 18 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 0 18 18
4674 0 str_append_map ($str, "\"(\$_)\"");
4675 0 str_append_thing ($str, $thing, $in_list, NO_PARENS);
4676 0 str_append_end ($str);
4677 }
4678 else {
4679 18 str_append_join ($str, prefix => '(', suffix => ')', never_empty => 1);
4680 18 str_append_thing ($str, $thing, $in_list, NO_PARENS);
4681 18 str_append_end ($str);
4682 }
4683 }
4684  
4685 sub str_append_table_key($$$)
4686 3 ▶{
Subroutine str_append_table_key: called CC=5 SCAR=16.1
Pod undocumented
4687 3 my ($str, $thing, $type)= @_;
4688 3 str_append_join ($str, sep => ' ');
4689 3 ▶ if (my $x= $thing->{constraint}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"constraint"}) 3 0 3
4690 3 str_append_str ($str, 'CONSTRAINT');
4691 3 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4692 }
4693 3 str_append_str ($str, $type);
4694 3 ▶ if (my $x= $thing->{index_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"index_type"}) 1 2 3
4695 1 str_append_str ($str, "USING $x");
4696 }
4697 3 str_append_list ($str, $thing->{column}, NO_PARENS, prefix=>'(', suffix=>')');
4698 3 for my $o (@{ $thing->{index_option} }) {
4699 0 str_append_thing ($str, $o, IN_LIST, NO_PARENS);
4700 }
4701 3 ▶ if (my $x= $thing->{reference}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"reference"}) 2 1 3
4702 2 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4703 }
4704 3 str_append_end ($str);
4705 }
4706  
4707 # str_append_thing() converts a recursive representation of the parsed SQL
4708 # structure into a Perl string that generates a list of either string
4709 # representations of the SQL structure (in good SQL syntax), or blessed
4710 # objects of the correct type.
4711 #
4712 # The result of this function is then used to wrap and bless the string
4713 # or objects appropriately according to which kind of SQL structure the
4714 # string contains (statement, expressions, column, etc.).
4715 #
4716 # In detail, str_append_thing() appends pieces of Perl code to $str, that
4717 # each represent a small piece of the SQL command.
4718 #
4719 # Each invocation of str_append_thing appends code to $str that generates
4720 # exactly the amount of objects that are represented. This might seem
4721 # obvious, but since $str is actually a comma separated list, this
4722 # requirement means that if multiple pieces are pushed for a single
4723 # thing, then a join(...) must enclose and group these. E.g.
4724 # the code that generates a SELECT statement from scratch appends
4725 # several pieces of code to $str, and to make only one string, a
4726 # join() is generated.
4727 #
4728 sub str_append_thing($$$$)
4729 2864 ▶{
Subroutine str_append_thing: called CC=4 SCAR=14.7
Pod undocumented
4730 2864 my ($str, $thing, $in_list, $parens)= @_;
4731 2864 local $SIG{__DIE__}= \&my_confess;
4732  
4733 # simple things to append:
4734 2864 ▶ unless (defined $thing) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $thing) 16 2848 2864
4735 16 str_append_perl ($str, 'undef');
4736 16 return;
4737 }
4738 2848 ▶ unless (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $thing) 384 2464 2848
4739 384 str_append_str ($str, $thing);
4740 384 return;
4741 }
4742 2464 ▶ if (ref($thing) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing eq "ARRAY") 1 2463 2464
4743 1 str_append_list ($str, $thing, NO_PARENS, prefix => '(', suffix => ')');
4744 1 return;
4745 }
4746  
4747 # normal structure:
4748 2463 str_target_line ($str, $thing->{line});
4749  
4750 switch($thing->{kind},
4751 141 ▶ 'Stmt' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.4
4752 switch($thing->{type},
4753 118 ▶ 'Select' => sub {
Subroutine __ANON__: called CC=12 SCAR=25.1
4754 # find out type name depending on number of columns:
4755 118 my $type_name = 'SelectStmt';
4756 118 ▶ if (scalar(@{ $thing->{expr_list} }) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$thing->{"expr_list"};} == 1) 114 4 118
4757 114 ▶ unless (is_multicol($thing->{expr_list}[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&is_multicol($thing->{"expr_list"}[0])) 98 16 114
4758 98 $type_name = 'SelectStmtSingle';
4759 }
4760 }
4761  
4762 # generate:
4763 118 str_append_funcall ($str, __PACKAGE__.'::'.$type_name.'->obj', $in_list);
4764 118 str_append_join ($str, never_empty => 1);
4765  
4766 str_append_list ($str, $thing->{expr_list}, NO_PARENS,
4767 prefix => join(' ', 'SELECT',
4768 118 @{ $thing->{opt_front} }
4769 ).' '
4770 );
4771  
4772 116 ▶ if (my $x= $thing->{from}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"from"}) 85 31 116
4773 85 str_append_list ($str, $x, NO_PARENS, prefix => ' FROM ');
4774  
4775 85 ▶ if (my $x= $thing->{join}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"join"}) 85 0 85
4776 85 ▶ if (@$x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x) 3 82 85
4777 3 str_append_map ($str, '" $_" ');
4778 3 for my $xi (@$x) {
4779 3 str_append_thing ($str, $xi, IN_LIST, NO_PARENS);
4780 }
4781 3 str_append_end ($str);
4782 }
4783 }
4784 85 ▶ if (my $x= $thing->{where}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"where"}) 42 43 85
4785 42 str_target_line ($str, $x->{line});
4786 42 str_append_str ($str, ' WHERE ');
4787 42 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4788 }
4789 84 ▶ if (my $x= $thing->{group_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"group_by"}) 4 80 84
4790 4 my $suffix= '';
4791 4 ▶ if ($thing->{group_by_with_rollup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"group_by_with_rollup"}) 0 4 4
4792 0 $suffix= ' WITH ROLLUP';
4793 }
4794 4 str_append_list ($str, $x, NO_PARENS,
4795 prefix => ' GROUP BY ',
4796 suffix => $suffix,
4797 result0 => '',
4798 );
4799 }
4800 84 ▶ if (my $x= $thing->{having}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"having"}) 0 84 84
4801 0 str_target_line ($str, $x->{line});
4802 0 str_append_str ($str, ' HAVING ');
4803 0 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4804 }
4805 84 ▶ if (my $x= $thing->{order_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"order_by"}) 5 79 84
4806 5 str_append_list ($str, $x, NO_PARENS,
4807 prefix => ' ORDER BY ',
4808 result0 => ''
4809 );
4810 }
4811 84 str_append_limit ($str, $thing->{limit_cnt}, $thing->{limit_offset});
4812  
4813 84 str_append_str ($str, join('', map " $_", @{ $thing->{opt_back} }));
4814 }
4815  
4816 115 str_append_end ($str);
4817 115 str_append_end ($str);
4818 },
4819 1 ▶ 'Delete' => sub {
Subroutine __ANON__: called CC=7 SCAR=19.9
4820 1 str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
4821 1 str_append_join ($str, never_empty => 1);
4822  
4823 str_append_list ($str, $thing->{from}, NO_PARENS,
4824 prefix =>
4825 join(' ',
4826 'DELETE',
4827 1 @{ $thing->{opt_front} },
4828 'FROM',
4829 1 @{ $thing->{from_opt_front} },
4830 ).' '
4831 );
4832  
4833 1 ▶ if (my $x= $thing->{using}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"using"}) 1 0 1
4834 1 str_append_list ($str, $x, NO_PARENS,
4835 prefix => ' USING ',
4836 result0 => ''
4837 );
4838 }
4839  
4840 1 ▶ if (my $x= $thing->{join}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"join"}) 1 0 1
4841 1 ▶ if (@$x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x) 1 0 1
4842 1 str_append_map ($str, '" $_" ');
4843 1 for my $xi (@$x) {
4844 2 str_append_thing ($str, $xi, IN_LIST, NO_PARENS);
4845 }
4846 1 str_append_end ($str);
4847 }
4848 }
4849 1 ▶ if (my $x= $thing->{where}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"where"}) 1 0 1
4850 1 str_target_line ($str, $x->{line});
4851 1 str_append_str ($str, ' WHERE ');
4852 1 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4853 }
4854 1 ▶ if (my $x= $thing->{order_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"order_by"}) 0 1 1
4855 0 str_append_list ($str, $x, NO_PARENS,
4856 prefix => ' ORDER BY ',
4857 result0 => ''
4858 );
4859 }
4860 1 str_append_limit ($str, $thing->{limit_cnt}, $thing->{limit_offset});
4861  
4862 1 str_append_end ($str);
4863 1 str_append_end ($str);
4864 },
4865 11 ▶ 'Insert' => sub {
Subroutine __ANON__: called CC=8 SCAR=23.6
4866 11 str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
4867 11 str_append_join ($str, never_empty => 1);
4868  
4869 str_append_str ($str,
4870 join(' ',
4871 'INSERT',
4872 11 @{ $thing->{opt_front} },
4873 'INTO',
4874 ).' '
4875 );
4876  
4877 11 str_append_thing ($str, $thing->{into}, NOT_IN_LIST, NO_PARENS);
4878  
4879 11 ▶ if (my $col= $thing->{column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = $thing->{"column"}) 4 7 11
4880 4 str_append_list ($str, $col, NO_PARENS, prefix => ' (', suffix => ')');
4881 }
4882  
4883 11 ▶ if (my $val= $thing->{value}) {
Branch: 4 branches
BranchTrueFalseTotal
if (my $val = $thing->{'value'}) { } 4 7 11
elsif (my $set = $thing->{'set'}) { } 7 0 7
elsif (my $sel = $thing->{'select'}) { } 0 0 0
elsif ($thing->{'default_values'}) { } 0 0 0
4884 4 str_append_str ($str, ' VALUES ');
4885 4 str_append_list ($str, $val, NO_PARENS);
4886 }
4887 elsif (my $set= $thing->{set}) {
4888 7 str_append_funcall ($str, __PACKAGE__."::set2values", NOT_IN_LIST);
4889 7 for my $l (@$set) {
4890 11 str_append_thing ($str, $l, IN_LIST, NO_PARENS);
4891 }
4892 7 str_append_end ($str);
4893 }
4894 elsif (my $sel= $thing->{select}) {
4895 0 str_append_str ($str, ' ');
4896 0 str_append_thing ($str, $sel, NOT_IN_LIST, NO_PARENS);
4897 }
4898 elsif ($thing->{default_values}) {
4899 0 str_append_str ($str, ' DEFAULT VALUES');
4900 }
4901 else {
4902 0 die;
4903 }
4904  
4905 11 ▶ if (my $x= $thing->{duplicate_update}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"duplicate_update"}) 0 11 11
4906 0 str_append_str ($str, ' ON DUPLICATE KEY UPDATE ');
4907 0 str_append_list ($str, $x, NO_PARENS, map => __PACKAGE__.'::assign($_)');
4908 }
4909  
4910 11 str_append_end ($str);
4911 11 str_append_end ($str);
4912 },
4913 8 ▶ 'Update' => sub {
Subroutine __ANON__: called CC=8 SCAR=23.6
4914 8 str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
4915 8 str_append_join ($str, never_empty => 1);
4916  
4917 str_append_list ($str, $thing->{table}, NO_PARENS,
4918 prefix => join(' ', 'UPDATE',
4919 8 @{ $thing->{opt_front} }
4920 ).' '
4921 );
4922  
4923 8 ▶ if (my $x= $thing->{from}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"from"}) 0 8 8
4924 0 str_append_list ($str, $x, NO_PARENS,
4925 prefix => ' FROM ',
4926 result0 => ''
4927 );
4928 }
4929 8 ▶ if (my $x= $thing->{join}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"join"}) 8 0 8
4930 8 ▶ if (@$x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x) 0 8 8
4931 0 str_append_map ($str, '" $_" ');
4932 0 for my $xi (@$x) {
4933 0 str_append_thing ($str, $xi, IN_LIST, NO_PARENS);
4934 }
4935 0 str_append_end ($str);
4936 }
4937 }
4938 8 ▶ if (my $x= $thing->{set}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"set"}) 8 0 8
4939 8 str_append_list ($str, $x, NO_PARENS,
4940 prefix => ' SET ',
4941 result0 => '' # this is an error.
4942 );
4943 }
4944 8 ▶ if (my $x= $thing->{where}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"where"}) 8 0 8
4945 8 str_target_line ($str, $x->{line});
4946 8 str_append_str ($str, ' WHERE ');
4947 8 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4948 }
4949 8 ▶ if (my $x= $thing->{order_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"order_by"}) 0 8 8
4950 0 str_append_list ($str, $x, NO_PARENS,
4951 prefix => ' ORDER BY ',
4952 result0 => ''
4953 );
4954 }
4955 8 str_append_limit ($str, $thing->{limit_cnt}, $thing->{limit_offset});
4956  
4957 8 str_append_end ($str);
4958 8 str_append_end ($str);
4959 },
4960 1 ▶ 'CreateTable' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
4961 1 str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
4962 1 str_append_join ($str, never_empty => 1);
4963  
4964 1 str_append_str ($str, "$thing->{subtype} ");
4965 1 ▶ if ($thing->{if_not_exists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"if_not_exists"}) 0 1 1
4966 0 str_append_str ($str, 'IF NOT EXISTS ');
4967 }
4968 1 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
4969  
4970 my @tabspec= (
4971 1 @{ $thing->{column_def} },
4972 1 @{ $thing->{tabconstr} }
4973 );
4974 1 str_append_list ($str, \@tabspec, NO_PARENS,
4975 result0 => '',
4976 prefix => ' (',
4977 suffix => ')'
4978 );
4979  
4980 1 str_append_list ($str, $thing->{tableopt}, NO_PARENS,
4981 result0 => '',
4982 prefix => ' ',
4983 sep => ' ',
4984 );
4985  
4986 1 ▶ if (my $x= $thing->{select}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"select"}) 0 1 1
4987 0 str_append_str ($str, ' AS ');
4988 0 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4989 }
4990  
4991 1 str_append_end ($str);
4992 1 str_append_end ($str);
4993 },
4994 0 ▶ 'DropTable' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
4995 0 str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
4996 0 str_append_join ($str, never_empty => 1);
4997  
4998 0 str_append_str ($str, "$thing->{subtype} ");
4999 0 ▶ if ($thing->{if_exists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"if_exists"}) 0 0 0
5000 0 str_append_str ($str, 'IF EXISTS ');
5001 }
5002 0 str_append_list ($str, $thing->{table}, NO_PARENS);
5003  
5004 0 ▶ if (my $x= $thing->{cascade}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"cascade"}) 0 0 0
5005 0 str_append_str ($str, " $x");
5006 }
5007 0 str_append_end ($str);
5008 0 str_append_end ($str);
5009 },
5010 0 ▶ 'AlterTable' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
5011 0 str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
5012 0 str_append_join ($str, never_empty => 1);
5013  
5014 0 str_append_str ($str, "$thing->{subtype} ");
5015 0 ▶ if ($thing->{only}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"only"}) 0 0 0
5016 0 str_append_str ($str, 'ONLY ');
5017 }
5018 0 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
5019  
5020 0 str_append_join ($str, sep => ' ', prefix => ' ');
5021 0 for my $l ($thing->{functor}, @{ $thing->{arg} }) {
5022 0 str_append_thing ($str, $l, NOT_IN_LIST, NO_PARENS);
5023 }
5024 0 str_append_end ($str);
5025  
5026 0 str_append_end ($str);
5027 0 str_append_end ($str);
5028 },
5029 2 ▶ 'Interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5030 2 str_append_typed ($str, 'stmt', 'Stmt', $thing, $in_list);
5031 },
5032 141 );
5033 },
5034  
5035 3 ▶ 'TableOption' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5036 switch ($thing->{type},
5037 1 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5038 1 str_append_typed ($str, 'tableopt', 'TableOption', $thing, $in_list);
5039 },
5040 2 ▶ 'literal' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5041 2 str_append_join ($str, sep => ' ');
5042 2 str_append_str ($str, $thing->{name});
5043 2 str_append_thing ($str, $thing->{value}, NOT_IN_LIST, NO_PARENS);
5044 2 str_append_end ($str);
5045 }
5046 3 );
5047 },
5048  
5049 0 ▶ 'Keyword' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5050 0 str_append_str ($str, $thing->{keyword});
5051 },
5052  
5053 9 ▶ 'Join' => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
5054 9 ▶ if ($thing->{type} eq 'interpol') {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'type'} eq 'interpol') { } 3 6 9
5055 3 str_append_typed ($str, 'joinclause', 'Join', $thing, $in_list);
5056 }
5057 else {
5058 6 str_append_join ($str, result0 => '');
5059  
5060 6 ▶ if ($thing->{natural}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'natural'}) { } 2 4 6
5061 2 ▶ if ($thing->{type} eq 'INNER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'type'} eq 'INNER') { } 2 0 2
5062 2 str_append_str ($str, "NATURAL JOIN ");
5063 }
5064 else {
5065 0 str_append_str ($str, "NATURAL $thing->{type} JOIN ");
5066 }
5067 }
5068 else {
5069 4 str_append_str ($str, "$thing->{type} JOIN ");
5070 }
5071  
5072 6 str_append_list ($str, $thing->{table}, NO_PARENS);
5073  
5074 6 ▶ if (my $on= $thing->{on}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $on = $thing->{'on'}) { } 1 5 6
elsif (my $using = $thing->{'using'}) { } 1 4 5
5075 1 str_append_str ($str, ' ON ');
5076 1 str_append_thing ($str, $on, NOT_IN_LIST, NO_PARENS);
5077 }
5078 elsif (my $using= $thing->{using}) {
5079 1 str_append_str ($str, ' USING (');
5080 1 str_append_list ($str, $using, NO_PARENS);
5081 1 str_append_str ($str, ')');
5082 };
5083  
5084 6 str_append_end ($str);
5085 }
5086 },
5087  
5088 'Table' => 'Column',
5089 'CharSet' => 'Column',
5090 'Collate' => 'Column',
5091 'Index' => 'Column',
5092 'Constraint' => 'Column',
5093 'Transliteration' => 'Column',
5094 'Transcoding' => 'Column',
5095 'Engine' => 'Column',
5096 355 ▶ 'Column' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5097 355 str_append_ident_chain ($str, $in_list, $thing->{kind}, @{ $thing->{ident_chain} });
5098 },
5099  
5100 102 ▶ 'TableAs' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
5101 102 ▶ if (my $x= $thing->{as}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{'as'}) { } 1 101 102
5102 # Oracle does not allow AS in table aliases. But this module
5103 # does not allow leaving it out. To avoid generating what
5104 # this module cannot read back in the default case, check for
5105 # the write dialect.
5106 1 ▶ if ($write_dialect eq 'oracle') {
Branch: 1 branch
BranchTrueFalseTotal
if ($write_dialect eq 'oracle') { } 0 1 1
5107 0 str_append_join ($str, sep => ' ', never_empty => 1);
5108 }
5109 else {
5110 1 str_append_join ($str, sep => ' AS ', never_empty => 1);
5111 }
5112 1 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
5113 1 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
5114 1 str_append_end ($str);
5115 }
5116 else {
5117 101 str_append_thing ($str, $thing->{table}, $in_list, NO_PARENS);
5118 }
5119 },
5120  
5121 123 ▶ 'ExprAs' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
5122 123 ▶ if (my $x= $thing->{as}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{'as'}) { } 3 120 123
5123 3 str_append_join ($str, sep => ' AS ', never_empty => 1);
5124 3 str_append_thing ($str, $thing->{expr}, NOT_IN_LIST, NO_PARENS);
5125 2 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
5126 2 str_append_end ($str);
5127 }
5128 else {
5129 120 str_append_thing ($str, $thing->{expr}, $in_list, $parens);
5130 }
5131 },
5132 17 ▶ 'Order' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5133 switch($thing->{type},
5134 9 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
5135 9 ▶ if ($thing->{desc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'desc'}) { } 3 6 9
5136 3 str_append_typed ($str, 'desc', 'Order', $thing, $in_list, hashkeys => 1);
5137 }
5138 else {
5139 6 str_append_typed ($str, 'asc', 'Order', $thing, $in_list, hashkeys => 1);
5140 }
5141 },
5142 8 ▶ 'expr' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
5143 8 ▶ if ($thing->{desc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'desc'}) { } 4 4 8
5144 4 str_append_map ($str, __PACKAGE__.'::desc($_)');
5145 4 str_append_thing ($str, $thing->{expr}, $in_list, NO_PARENS);
5146 4 str_append_end ($str);
5147 }
5148 else {
5149 4 str_append_thing ($str, $thing->{expr}, $in_list, NO_PARENS);
5150 }
5151 },
5152 17 );
5153 },
5154 0 ▶ 'TypeList' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5155 switch($thing->{type},
5156 0 ▶ 'interpol' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5157 0 str_append_typed ($str, 'typelist', 'Type', $thing, $in_list);
5158 },
5159  
5160 0 ▶ 'explicit' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5161 0 str_append_list ($str, $thing->{arg}, NO_PARENS, prefix => '(', suffix => ')');
5162 # may not be empty!
5163 },
5164 0 );
5165 },
5166 15 ▶ 'Type' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5167 switch ($thing->{type},
5168 6 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5169 6 str_append_typed ($str, 'type', 'Type', $thing, $in_list);
5170 },
5171 9 ▶ 'base' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5172 9 str_append_perl ($str, __PACKAGE__.'::Type->new()');
5173 },
5174 15 );
5175 },
5176 23 ▶ 'TypePost' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
5177 23 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 23 23
5178 if $parens;
5179  
5180 23 str_append_funcall_begin ($str, __PACKAGE__.'::type_'.$thing->{functor}, $in_list);
5181 23 for my $arg (@{ $thing->{arg} }) {
5182 25 str_append_thing ($str, $arg, NOT_IN_LIST, NO_PARENS);
5183 }
5184 23 str_append_funcall_end ($str, $in_list);
5185 23 str_append_thing ($str, $thing->{base}, $in_list, NO_PARENS);
5186 23 str_append_end ($str);
5187 },
5188 1 ▶ 'ColumnDef' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5189 1 str_append_join ($str, sep => ' ');
5190 1 str_append_thing ($str, $thing->{name}, NOT_IN_LIST, NO_PARENS);
5191 1 str_append_thing ($str, $thing->{column_spec}, NOT_IN_LIST, NO_PARENS);
5192 1 str_append_end ($str);
5193 },
5194  
5195 4 ▶ 'ColumnSpec' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5196 switch ($thing->{type},
5197 2 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5198 2 str_append_typed ($str, 'colspec', 'ColumnSpec', $thing, $in_list);
5199 },
5200 2 ▶ 'base' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5201 2 str_append_funcall ($str, __PACKAGE__.'::ColumnSpec->new', $in_list);
5202 2 str_append_thing ($str, $thing->{datatype}, $in_list, NO_PARENS);
5203 2 str_append_end ($str);
5204 }
5205 4 );
5206 },
5207 4 ▶ 'ColumnSpecPost' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
5208 4 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 4 4
5209 if $parens;
5210  
5211 4 str_append_funcall_begin ($str, __PACKAGE__.'::colspec_'.$thing->{functor}, $in_list);
5212 4 for my $arg (@{ $thing->{arg} }) {
5213 12 str_append_thing ($str, $arg, NOT_IN_LIST, NO_PARENS);
5214 }
5215 4 str_append_funcall_end ($str, $in_list);
5216 4 str_append_thing ($str, $thing->{base}, $in_list, NO_PARENS);
5217 4 str_append_end ($str);
5218 },
5219  
5220 0 ▶ 'TableConstraint' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5221 switch($thing->{type},
5222 0 ▶ 'primary_key' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5223 0 str_append_table_key ($str, $thing, 'PRIMARY KEY');
5224 },
5225 0 ▶ 'unique' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5226 0 str_append_table_key ($str, $thing, 'UNIQUE');
5227 },
5228 0 ▶ 'fulltext' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5229 0 str_append_table_key ($str, $thing, 'FULLTEXT');
5230 },
5231 0 ▶ 'spatial' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5232 0 str_append_table_key ($str, $thing, 'SPATIAL');
5233 },
5234 0 ▶ 'index' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5235 0 str_append_table_key ($str, $thing, 'INDEX');
5236 },
5237 0 ▶ 'foreign_key' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5238 0 str_append_table_key ($str, $thing, 'FOREIGN KEY');
5239 },
5240 0 );
5241 },
5242  
5243 0 ▶ 'IndexOption' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5244 switch($thing->{type},
5245 0 ▶ 'using' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5246 0 str_append_str ($str, "USING $thing->{arg}");
5247 }
5248 0 );
5249 },
5250  
5251 0 ▶ 'References' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
5252 # table column match on_delete on_update));
5253 str_append_join ($str, sep => ' ',
5254 prefix => 'REFERENCES ',
5255 suffix =>
5256 0 ▶ join('', map { " $_" }
Branch: 3 branches
BranchTrueFalseTotal
$thing->{'match'} ? : 0 0 0
$thing->{'on_delete'} ? : 0 0 0
$thing->{'on_update'} ? : 0 0 0
5257 ($thing->{match} ?
5258 ('MATCH', $thing->{match})
5259 : ()
5260 ),
5261 ($thing->{on_delete} ?
5262 ('ON DELETE', $thing->{on_delete})
5263 : ()
5264 ),
5265 ($thing->{on_update} ?
5266 ('ON UPDATE', $thing->{on_update})
5267 0 : ()
5268 ),
5269 )
5270 );
5271 0 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
5272 0 str_append_list ($str, $thing->{column}, NO_PARENS,
5273 prefix => '(', suffix => ')', result0 => '');
5274 0 str_append_end ($str);
5275 },
5276  
5277 0 ▶ 'CharUnit' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
5278 0 str_append_str ($str, $thing->{name});
5279 },
5280  
5281 8 ▶ 'ExprList' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5282 switch($thing->{type},
5283 4 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5284 4 str_append_typed ($str, 'exprlist', 'Expr', $thing, $in_list);
5285 },
5286  
5287 4 ▶ 'explicit' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5288 4 str_append_list ($str, $thing->{arg}, NO_PARENS, prefix => '(', suffix => ')');
5289 # may not be empty!
5290 },
5291 8 );
5292 },
5293 10 ▶ 'ExprEmpty' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5294 # Append an empty string. Must have an operand here, otherwise
5295 # parameters might get mixed up.
5296 10 str_append_str($str, '');
5297 },
5298 9 ▶ 'Check' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5299 9 str_append_join ($str, joinfunc => __PACKAGE__.'::Check->obj');
5300 9 str_append_thing ($str, $thing->{expr}, NOT_IN_LIST, NO_PARENS);
5301 9 str_append_end ($str);
5302 },
5303 618 ▶ 'Expr' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5304 switch($thing->{type},
5305 10 ▶ 'limit' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5306 10 my $limit_cnt_str= perl_val($thing->{arg}, 'Expr',
5307 ['interpol', 'interpolExpr', '?']);
5308 10 str_append_perl ($str, __PACKAGE__."::limit_number($limit_cnt_str)");
5309 },
5310 204 ▶ 'interpol' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
5311 my $func= $thing->{maybe_check} ?
5312 'expr_or_check'
5313 : ($thing->{token}{type} eq 'num' ||
5314 204 ▶ $thing->{token}{type} eq 'string' ||
Branch: 2 branches
BranchTrueFalseTotal
$thing->{'maybe_check'} ? : 5 199 204
$thing->{'token'}{'type'} eq 'num' || $thing->{'token'}{'type'} eq 'string' || !$parens ? : 150 49 199
Condition100%6/6
$thing->{"token"}{"type"} eq "num" or $thing->{"token"}{"type"} eq "string" or not $parens
l!l&&r!l&&!r
1163449
$thing->{"token"}{"type"} eq "num" or $thing->{"token"}{"type"} eq "string"
l!l&&r!l&&!r
1001683
MC/DC100%3/3
$thing->{"token"}{"type"} eq "num" or $thing->{"token"}{"type"} eq "string" or not $parens
$thing->{"token"}{"type"} eq "num" $thing->{"token"}{"type"} eq "string" not $parens
Truth table100%4/4
A or B or not(C)
A= $thing->{"token"}{"type"} eq "num"B= $thing->{"token"}{"type"} eq "string"C= not $parens
ABCresult
1XX1
01X1
0011
0000
5315 !$parens) ?
5316 'expr'
5317 : 'exprparen';
5318 204 str_append_typed ($str, $func, 'Expr', $thing, $in_list, hash => 1);
5319 },
5320 227 ▶ 'column' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5321 227 str_append_thing ($str, $thing->{arg}, $in_list, NO_PARENS);
5322 },
5323 4 ▶ '()' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5324 4 str_append_thing ($str, $thing->{arg}, $in_list, PARENS);
5325 },
5326 2 ▶ 'subquery' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5327 2 str_append_funcall ($str, __PACKAGE__.'::subquery', $in_list);
5328 2 str_append_thing ($str, $thing->{arg}, $in_list, NO_PARENS);
5329 2 str_append_end ($str);
5330 },
5331 1 ▶ 'prefix1' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.6
5332 1 $in_list= NOT_IN_LIST; # just to be sure
5333 1 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 1 1
5334 if $parens;
5335 1 ▶ die 'Expected exactly 1 argument' unless scalar(@{ $thing->{arg} }) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$thing->{"arg"};} == 1 0 1 1
5336  
5337 1 str_append_join ($str,
5338 prefix => "$thing->{functor}{value} ",
5339 never_empty => 1
5340 );
5341 1 str_append_thing ($str, $thing->{arg}[0], NOT_IN_LIST, PARENS);
5342 0 str_append_end ($str);
5343 },
5344 0 ▶ 'prefixn' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
5345 0 $parens= NO_PARENS; # just to be sure
5346 0 ▶ die 'Expected exactly 1 argument' unless scalar(@{ $thing->{arg} }) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$thing->{"arg"};} == 1 0 0 0
5347  
5348 0 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 0 0 0
5349 0 str_append_map ($str, "'$thing->{functor}{value} '.(\$_)");
5350 }
5351 else {
5352 0 str_append_join ($str,
5353 prefix => "$thing->{functor}{value} ",
5354 never_empty => 1
5355 );
5356 }
5357 0 str_append_thing ($str, $thing->{arg}[0], $in_list, PARENS);
5358 0 str_append_end ($str);
5359 },
5360  
5361 61 ▶ 'infix2' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
5362 61 $in_list= NOT_IN_LIST; # just to be sure
5363 61 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 2 59 61
5364 if $parens;
5365  
5366 59 my $f= $thing->{functor};
5367 59 str_append_join ($str, joinfunc => __PACKAGE__.'::Infix->obj');
5368 59 str_append_str ($str, $thing->{functor}{value});
5369 59 str_append_thing ($str, $thing->{arg}[0], NOT_IN_LIST, PARENS);
5370 59 str_append_thing ($str, $thing->{arg}[1], NOT_IN_LIST, PARENS);
5371 59 str_append_end ($str);
5372 },
5373  
5374 'infix23' => 'infix3',
5375 3 ▶ 'infix3' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
5376 3 $in_list= NOT_IN_LIST; # just to be sure
5377 3 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 3 3
5378 if $parens;
5379  
5380 3 my $f= $thing->{functor};
5381 3 str_append_join ($str, never_empty => 1);
5382 3 str_append_thing ($str, $thing->{arg}[0], NOT_IN_LIST, PARENS);
5383 3 str_append_str ($str, " $thing->{functor}{value} ");
5384 3 str_append_thing ($str, $thing->{arg}[1], NOT_IN_LIST, PARENS);
5385 3 ▶ if (scalar(@{ $thing->{arg} }) == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$thing->{"arg"};} == 3) 1 2 3
5386 1 str_append_str ($str, " $thing->{functor}{value2} ");
5387 1 str_append_thing ($str, $thing->{arg}[2], NOT_IN_LIST, PARENS);
5388 }
5389 3 str_append_end ($str);
5390 },
5391  
5392 # prefix and suffix allow bitwise application:
5393 # Currently not supported via _prefix() and _suffix() helper
5394 # functions, but may be later. (Needs only a little rewrite
5395 # here. The helper functions don't need to be changed.)
5396 'prefix()' => 'prefix',
5397 'suffix' => 'prefix',
5398 37 ▶ 'prefix' => sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
5399 37 ▶ if ($thing->{type} eq 'prefix()') { # for AND() and OR() as functors
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"type"} eq "prefix()") 20 17 37
5400 20 $in_list = NOT_IN_LIST;
5401 }
5402 37 my $f= $thing->{functor};
5403 37 ▶ my $fk= $functor_kind{$f->{type} || ''}
Branch: 1 branch
BranchTrueFalseTotal
my $fk = $functor_kind{$f->{"type"} or ""} or die qq[Expected $thing->{"type"} to be mapped by %functor_kind] 37 0 37
Condition50%1/2
$f->{'type'} || ''
l!l
370
MC/DC0%0/1
$f->{'type'} || ''
$f->{'type'}
Truth table50%1/2
A
A= $f->{'type'}
Aresult
11
00
5404 or die "Expected $thing->{type} to be mapped by \%functor_kind";
5405 37 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 13 24 37
5406 13 my $qt= quote_perl($f->{value});
5407 13 ▶ str_append_map ($str, __PACKAGE__."::_".$fk."($qt,".($parens?1:0).",\$_)");
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 11 2 13
5408 13 for my $l (@{ $thing->{arg} }) {
5409 21 str_append_thing ($str, $l, IN_LIST, PARENS);
5410 }
5411 13 str_append_end ($str);
5412 }
5413 else {
5414 24 str_append_funcall($str, __PACKAGE__."::_".$fk, NOT_IN_LIST);
5415 24 str_append_thing ($str, $f->{value}, IN_LIST, NO_PARENS);
5416 24 ▶ str_append_thing ($str, $parens?1:0, IN_LIST, NO_PARENS);
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 7 17 24
5417 24 for my $l (@{ $thing->{arg} }) {
5418 34 str_append_thing ($str, $l, IN_LIST, PARENS);
5419 }
5420 24 str_append_end ($str);
5421 }
5422 },
5423  
5424 # funcall and infix use args inline if they are in list context.
5425 # They are handled by _prefix() and _suffix() helper functions in order
5426 # to allow dialect conversion:
5427 'funcall' => 'infix()',
5428 60 ▶ 'infix()' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
5429 60 $in_list= NOT_IN_LIST; # just to be sure
5430 60 my $f= $thing->{functor};
5431 60 ▶ my $fk= $functor_kind{$f->{type} || ''}
Branch: 1 branch
BranchTrueFalseTotal
my $fk = $functor_kind{$f->{"type"} or ""} or die "Expected \$thing->{type} to be mapped by %functor_kind" 60 0 60
Condition50%1/2
$f->{'type'} || ''
l!l
600
MC/DC0%0/1
$f->{'type'} || ''
$f->{'type'}
Truth table50%1/2
A
A= $f->{'type'}
Aresult
11
00
5432 or die 'Expected $thing->{type} to be mapped by %functor_kind';
5433  
5434 60 str_append_funcall($str, __PACKAGE__."::_".$fk, NOT_IN_LIST);
5435 60 str_append_thing ($str, $f->{value}, IN_LIST, NO_PARENS);
5436 60 ▶ str_append_thing ($str, $parens?1:0, IN_LIST, NO_PARENS);
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 7 53 60
5437 60 for my $l (@{ $thing->{arg} }) {
5438 115 str_append_thing ($str, $l, IN_LIST, PARENS);
5439 }
5440 60 str_append_end ($str);
5441 },
5442  
5443 1 ▶ 'funcsep' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
5444 1 $in_list= NOT_IN_LIST; # just to be sure
5445 1 str_append_join ($str, never_empty => 1, sep => ' ');
5446 1 str_append_str ($str, "$thing->{functor}{value}(");
5447 1 for my $t (@{ $thing->{arg} }) {
5448 4 str_append_thing ($str, $t, NOT_IN_LIST, NO_PARENS);
5449 }
5450 1 str_append_end ($str);
5451 },
5452  
5453 8 ▶ 'case' => sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
5454 8 $in_list= NOT_IN_LIST; # just to be sure
5455  
5456 # FIXME (maybe): we add parens here, so if there are no
5457 # when-then pairs at all and only the else part is printed,
5458 # it will get parens, too, no matter what. That's ok,
5459 # since it's a non-standard, marginal special case.
5460 8 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 8 8
5461 if $parens;
5462  
5463 8 my $sw= $thing->{switchval};
5464 8 ▶ if ($sw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sw) { } 8 0 8
5465 8 str_append_funcall ($str, __PACKAGE__."::caseswitch", NOT_IN_LIST);
5466 8 str_append_thing ($str, $sw, NOT_IN_LIST, NO_PARENS);
5467 }
5468 else {
5469 0 str_append_funcall ($str, __PACKAGE__."::casecond", NOT_IN_LIST);
5470 }
5471  
5472 8 ▶ if (my $e= $thing->{otherwise}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $thing->{'otherwise'}) { } 6 2 8
5473 6 str_append_thing ($str, $e, NOT_IN_LIST, NO_PARENS);
5474 }
5475 else {
5476 2 str_append_str ($str, 'NULL');
5477 }
5478  
5479 8 for my $wh (@{ $thing->{arg} }) {
5480 6 ▶ if (ref($wh) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $wh eq 'ARRAY') { } 6 0 6
5481 6 my ($when,$expr)= @$wh;
5482 6 str_append_funcall ($str, __PACKAGE__.'::whenthen', NOT_IN_LIST);
5483 6 str_append_thing ($str, $when, NOT_IN_LIST, NO_PARENS);
5484 6 str_append_thing ($str, $expr, NOT_IN_LIST, NO_PARENS);
5485 6 str_append_end ($str);
5486 }
5487 else {
5488 0 die 'expected array';
5489 }
5490 }
5491  
5492 8 str_append_end ($str);
5493 },
5494 618 );
5495 },
5496  
5497 11 ▶ 'ColumnName' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5498 switch ($thing->{type},
5499 'interpol' => 'ident',
5500 11 ▶ 'ident' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5501 11 str_append_typed ($str, 'colname', 'none', $thing, $in_list, hashkeys => 1);
5502 }
5503 11 );
5504 },
5505  
5506 0 ▶ 'ColumnIndex' => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
5507 0 ▶ if (defined $thing->{length} || $thing->{desc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $thing->{'length'} or $thing->{'desc'}) { } 0 0 0
Condition0%0/3
defined $thing->{"length"} or $thing->{"desc"}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $thing->{"length"} or $thing->{"desc"}
defined $thing->{"length"} $thing->{"desc"}
Truth table0%0/3
A or B
A= defined $thing->{"length"}B= $thing->{"desc"}
ABresult
1X1
011
000
5508 0 str_append_join ($str, sep => ' ');
5509 0 str_append_thing ($str, $thing->{name}, NOT_IN_LIST, NO_PARENS);
5510 0 ▶ if (defined $thing->{length}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $thing->{"length"}) 0 0 0
5511 0 str_append_join ($str, prefix => '(', suffix => ')');
5512 0 str_append_thing ($str, $thing->{length}, NOT_IN_LIST, NO_PARENS);
5513 0 str_append_end ($str);
5514 }
5515 0 ▶ if ($thing->{desc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"desc"}) 0 0 0
5516 0 str_append_str ($str, 'DESC');
5517 }
5518 0 str_append_end ($str);
5519 }
5520 else {
5521 0 str_append_thing ($str, $thing->{name}, $in_list, $parens);
5522 }
5523 },
5524  
5525 1 ▶ 'TableName' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5526 switch ($thing->{type},
5527 'interpol' => 'ident',
5528 1 ▶ 'ident' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5529 1 str_append_typed ($str, 'tabname', 'none', $thing, $in_list, hashkeys => 1);
5530 }
5531 1 );
5532 },
5533  
5534 'Fetch' => 'Do',
5535 12 ▶ 'Do' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
5536 12 str_append_thing ($str, $thing->{stmt}, $in_list, $parens);
5537 },
5538 2463 );
5539 }
5540  
5541 sub to_perl($$\@)
5542 278 ▶{
Subroutine to_perl: called CC=2 SCAR=6.9
Pod undocumented
5543 278 my ($line_start, $kind, $things)= @_;
5544 278 my $str= str_new($line_start);
5545 278 for my $thing (@$things) {
5546 386 str_append_thing ($str, $thing, IN_LIST, NO_PARENS);
5547 }
5548 275 my $text= str_get_string($str);
5549 275 return "do{".__PACKAGE__."::_max1_if_scalar map{".__PACKAGE__."::${kind}->obj(\$_)} $text}",
5550 }
5551  
5552 ######################################################################
5553 # Top-level parser interface:
5554  
5555 sub lx_die_perhaps($;$)
5556 559 ▶{
Subroutine lx_die_perhaps: called CC=5 SCAR=16.1
Pod undocumented
5557 559 my $lx= shift;
5558  
5559 # if a test value is given, check that it is defined:
5560 559 ▶ if (scalar(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 280 279 559
5561 280 my ($check_val)= @_;
5562 280 ▶ unless (defined $check_val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $check_val) 1 279 280
5563 1 ▶ $lx->{error}||= 'Unknown error';
Condition50%1/2
$lx->{"error"} ||= "Unknown error"
l!l
10
MC/DC0%0/1
$lx->{"error"} ||= "Unknown error"
$lx->{"error"}
Truth table50%1/2
A
A= $lx->{"error"}
Aresult
11
00
5564 }
5565 }
5566  
5567 # if an error is set, then die:
5568 559 ▶ if ($lx->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{"error"}) 2 557 559
5569 2 die lx_pos($lx).": Error: $lx->{error}\n";
5570 }
5571 }
5572  
5573  
5574 sub parse_1_or_list($$$;$)
5575 273 ▶{
Subroutine parse_1_or_list: called CC=1 SCAR=0.0
Pod undocumented
5576 273 my ($lx, $parse_elem, $list_sep, $end)= @_;
5577 273 my $r= parse_list([], $lx, $parse_elem, $list_sep, $end);
5578 273 lx_die_perhaps($lx, $r);
5579 272 return @$r;
5580 }
5581  
5582 sub parse_0_try_list($$)
5583 7 ▶{
Subroutine parse_0_try_list: called CC=1 SCAR=0.0
Pod undocumented
5584 7 my ($lx, $parse_elem)= @_;
5585 7 my $r= parse_try_list([], $lx, $parse_elem);
5586 7 lx_die_perhaps($lx, $r);
5587 7 return @$r;
5588 }
5589  
5590 sub parse_stmt_list($)
5591 137 ▶{
Subroutine parse_stmt_list: called CC=1 SCAR=0.0
Pod undocumented
5592 137 parse_1_or_list ($_[0], \&parse_stmt, ';', ['}',')',']']);
5593 }
5594  
5595 sub parse_do_stmt($)
5596 2 ▶{
Subroutine parse_do_stmt: called CC=1 SCAR=0.0
Pod undocumented
5597 2 my ($lx) = @_;
5598 map {
5599 2 my $stmt = $_;
5600 2 my $r = create($lx, 'Do', qw(stmt));
5601 2 $r->{stmt} = $stmt;
5602 2 $r;
5603 }
5604 parse_stmt_list($lx);
5605 }
5606  
5607 sub parse_fetch_stmt($)
5608 10 ▶{
Subroutine parse_fetch_stmt: called CC=1 SCAR=0.0
Pod undocumented
5609 10 my ($lx) = @_;
5610 map {
5611 10 my $stmt = $_;
5612 10 my $r = create($lx, 'Fetch', qw(stmt));
5613 10 $r->{stmt} = $stmt;
5614 10 $r;
5615 }
5616 parse_stmt_list($lx);
5617 }
5618  
5619 my %top_parse= (
5620 # pure parse actions:
5621 'Stmt' => \&parse_stmt_list,
5622  
5623 5 ▶ 'Join' => sub { parse_0_try_list($_[0], \&parse_join) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5624 2 ▶ 'TableOption' => sub { parse_0_try_list($_[0], \&parse_table_option) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5625  
5626 81 ▶ 'Expr' => sub { parse_1_or_list ($_[0], \&parse_expr, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5627 9 ▶ 'Check' => sub { parse_1_or_list ($_[0], \&parse_check, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5628 15 ▶ 'Type' => sub { parse_1_or_list ($_[0], \&parse_type, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5629 9 ▶ 'Column' => sub { parse_1_or_list ($_[0], \&parse_column, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5630 6 ▶ 'Table' => sub { parse_1_or_list ($_[0], \&parse_table, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5631 0 ▶ 'Index' => sub { parse_1_or_list ($_[0], \&parse_index, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5632 1 ▶ 'CharSet' => sub { parse_1_or_list ($_[0], \&parse_charset, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5633 0 ▶ 'Collate' => sub { parse_1_or_list ($_[0], \&parse_collate, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5634 0 ▶ 'Constraint' => sub { parse_1_or_list ($_[0], \&parse_constraint, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5635 0 ▶ 'Transliteration' => sub { parse_1_or_list ($_[0], \&parse_transliteration, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5636 0 ▶ 'Transcoding' => sub { parse_1_or_list ($_[0], \&parse_transcoding, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5637 8 ▶ 'Order' => sub { parse_1_or_list ($_[0], \&parse_order, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5638 7 ▶ 'ColumnSpec' => sub { parse_1_or_list ($_[0], \&parse_column_spec, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5639  
5640 # parse & execute actions:
5641 2 ▶ 'Do' => sub { parse_do_stmt ($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5642 10 ▶ 'Fetch' => sub { parse_fetch_stmt($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5643 5 );
5644 5 my $top_parse_re= '(?:'.join('|', sort { length($b) <=> length($a) } '', keys %top_parse).')';
5645 5 my $top_parse_re2= '(?:'.join('|', sort { length($b) <=> length($a) } 'none', keys %top_parse).')';
5646  
5647 sub interpol_set_context ($$)
5648 515 ▶{
Subroutine interpol_set_context: called CC=1 SCAR=0.0
Pod undocumented
5649 515 my ($text, $ctxt)= @_;
5650 515 $text=~ s/(\Q${\SQL_MARK}\E$top_parse_re)(?::$top_parse_re2)?(\s*\{)/$1:$ctxt$2/gs;
5651 515 return $text;
5652 }
5653  
5654 sub good_interpol_type($)
5655 8 ▶{
Subroutine good_interpol_type: called CC=1 SCAR=0.0
Pod undocumented
5656 8 my ($type)= @_;
5657 8 return !!$top_parse{$type};
5658 }
5659  
5660 sub mark_sql()
5661 5 ▶{
Subroutine mark_sql: called CC=1 SCAR=0.0
Pod undocumented
5662 # Step 1:
5663 # This function will get the text without comments, strings, etc.,
5664 # and replace the initial SQL marking the start of SQL syntax by
5665 # our special SQL_MARK. Then, the unprocessed text will be
5666 # processed by replace_sql().
5667 5 s/\b\Q$sql_marker\E($top_parse_re\s*\{)/${\SQL_MARK}$1/gs;
5668  
5669 # Step 2:
5670 # Unmark false positives. The above finds false matches in
5671 # variables:
5672 #
5673 # $sql{...}
5674 #
5675 # We cannot(?) do this in one go, as we'd need a variable-width
5676 # negative look-behind regexp, which Perl does not have. This
5677 # is because there can be arbitrary white space between $ and
5678 # a variable name.
5679 5 s/([\$\@\%]\s*)\Q${\SQL_MARK}\E/$1$sql_marker/gs;
5680  
5681 # Note that there are still false positives, which are really hard
5682 # to find unless we start parsing Perl completely:
5683 #
5684 # ${ sql{blah} }
5685 }
5686  
5687 sub parse($$)
5688 22 ▶{
Subroutine parse: called CC=3 SCAR=11.1
Pod undocumented
5689 22 my ($kind, $str)= @_;
5690 22 my $lx= lexer_new ($str, "<string>", 0);
5691 22 my $func= $top_parse{$kind};
5692 22 ▶ return undef unless $func;
Branch: 1 branch
BranchTrueFalseTotal
unless $func 0 22 22
5693 22 ▶ return () if looking_at($lx, '<EOF>');
Branch: 1 branch
BranchTrueFalseTotal
if &looking_at($lx, "<EOF>") 0 22 22
5694 22 my @thing= $func->($lx);
5695 21 expect($lx, '<EOF>', SHIFT);
5696 21 lx_die_perhaps ($lx);
5697 20 return to_perl(1, $kind, @thing);
5698 }
5699  
5700 sub replace_sql()
5701 5 ▶{
Subroutine replace_sql: called CC=10 SCAR=23.6
Pod undocumented
5702 5 my ($module, $file, $line)= caller(4); # find our from where we were invoked
5703  
5704 5 mark_sql();
5705 #print STDERR "DEBUG: BEFORE: $_\n";
5706  
5707 5 pos($_)= 0;
5708 5 ▶ REPLACEMENT: while (/(\Q${\SQL_MARK}\E($top_parse_re)(?::($top_parse_re2))?\s*\{)/gs) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(\Q${\"\0__SQL__";}\E($top_parse_re)(?::($top_parse_re2))?\s*\{)/gs) 258 5 263
5709 # prepare lexer:
5710 258 ▶ my $ctxt= $3 || 'Stmt';
Condition100%2/2
$3 || 'Stmt'
l!l
20238
MC/DC100%1/1
$3 || 'Stmt'
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
5711 258 my $speckind= $2;
5712 258 ▶ my $kind= $speckind || $ctxt;
Condition66%2/3
$speckind || $ctxt
l!l&&r!l&&!r
1361220
MC/DC0%0/2
$speckind || $ctxt
$speckind $ctxt
Truth table66%2/3
A || B
A= $speckindB= $ctxt
ABresult
1X1
011
000
5713 258 my $start= pos($_) - length($1);
5714 258 my $prefix= substr($_, 0, $start);
5715 258 my $line_rel= ($prefix =~ tr/\n//);
5716 258 my $lx= lexer_new ($_, $file, $line + $line_rel);
5717  
5718 # select parser:
5719 258 my $func= $top_parse{$kind};
5720 258 ▶ unless ($func) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($func) 0 258 258
5721 0 die "$file:".($line+$line_rel+1).
5722 ": Error: Plain ${sql_marker}${speckind}{...} is illegal, because the ".
5723 "surrounding block must not return an object.\n\tPlease use ".
5724 (english_or map "${sql_marker}${_}{...}", keys %top_parse)." to disambiguate.\n";
5725 0 last REPLACEMENT;
5726 }
5727  
5728 # parse (including closing brace):
5729 258 my @thing= $func->($lx);
5730 258 expect ($lx, '}', SHIFT);
5731 258 lx_die_perhaps ($lx);
5732  
5733 258 my $end= $lx->{token}{pos};
5734 258 ▶ my_confess unless defined $end && $start < $end;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end and $start < $end 0 258 258
Condition33%1/3
defined $end and $start < $end
!ll&&!rl&&r
00258
MC/DC0%0/2
defined $end and $start < $end
defined $end $start < $end
Truth table33%1/3
A and B
A= defined $endB= $start < $end
ABresult
0X0
100
111
5735  
5736 # Make Perl code:
5737 # Represent the parse result as a list in Perl (if it's only
5738 # one element, the parens don't hurt). Each thing is
5739 # handled individually by to_perl():
5740 258 my $perl= to_perl($line + $line_rel, $kind, @thing);
5741  
5742 # replace:
5743 258 ▶ print STDERR "$file:".($line+$line_rel+1).': DEBUG: '.__PACKAGE__." replacement: $perl\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 258 258
5744 if $debug;
5745  
5746 258 my $old_text= substr($_, $start, $end-$start, $perl); # extract and replace text
5747 # pos($_) is now undef, which is ok, we will
5748 # rescan the text anyway.
5749  
5750 # Insert newlines at the end that have been dropped so that the line
5751 # count does not change and Perl's error messages are useful:
5752 258 my $line_cnt_old= ($old_text =~ tr/\n//);
5753 258 my $line_cnt_new= ($perl =~ tr/\n//);
5754 258 ▶ my_confess "More newlines than before" #.": \n###\n$old_text\n###$perl\n###\n"
Branch: 1 branch
BranchTrueFalseTotal
if $line_cnt_new > $line_cnt_old 0 258 258
5755 if $line_cnt_new > $line_cnt_old;
5756  
5757 258 ▶ if (my $line_cnt_less= $line_cnt_old - $line_cnt_new) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line_cnt_less = $line_cnt_old - $line_cnt_new) 101 157 258
5758 101 substr($_, $start + length($perl), 0, "\n" x $line_cnt_less);
5759 }
5760  
5761 # rescan everything in order to recurse into embedded sql{...}:
5762 258 pos($_)= 0;
5763 }
5764 5 pos($_)= undef;
5765  
5766 #print STDERR "DEBUG: AFTER: $_\n";
5767 };
5768  
5769 5 FILTER_ONLY
5770 # code_no_comments => \&mark_sql, # This is way to slow.
5771 all => \&replace_sql;
5772  
5773 ######################################################################
5774 # Functions used in generated code:
5775  
5776 # Obj:
5777 {
5778 package SQL::Yapp::Obj;
5779  
5780 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5781 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5782 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5783  
5784 0 ▶ sub op($) { return ''; }
Subroutine op: not called CC=1 SCAR=6.9
5785  
5786 ######################################################################
5787 # stringify: simply return second entry in array, the string:
5788 5 ▶ use overload '""' => 'value',
Subroutine BEGIN: called CC=1 SCAR=0.0
5789 5 ▶ cmp => sub { "$_[0]" cmp "$_[1]" };
Subroutine __ANON__: called CC=1 SCAR=0.0
5790  
5791 sub type_error($$)
5792 3 ▶ {
Subroutine type_error: called CC=1 SCAR=0.0
5793 3 my ($x, $want)= @_;
5794 3 my $r= ref($x);
5795 3 $r=~ s/^SQL::Yapp:://;
5796 3 croak "Error: Expected $want, but found ".$r;
5797 }
5798  
5799 0 ▶ sub asc($) { $_[0]->type_error('Asc'); }
Subroutine asc: not called CC=1 SCAR=6.9
5800 0 ▶ sub assign($) { $_[0]->type_error('assignment'); }
Subroutine assign: not called CC=1 SCAR=6.9
5801 0 ▶ sub charset($) { $_[0]->type_error('CharSet'); }
Subroutine charset: not called CC=1 SCAR=6.9
5802 0 ▶ sub constraint($) { $_[0]->type_error('Constraint'); }
Subroutine constraint: not called CC=1 SCAR=6.9
5803 0 ▶ sub charset1($) { $_[0]->type_error('CharSet'); }
Subroutine charset1: not called CC=1 SCAR=6.9
5804 0 ▶ sub collate1($) { $_[0]->type_error('Collate'); }
Subroutine collate1: not called CC=1 SCAR=6.9
5805 0 ▶ sub colname($) { $_[0]->type_error('ColumnName'); }
Subroutine colname: not called CC=1 SCAR=6.9
5806 0 ▶ sub colspec($) { $_[0]->type_error('ColumnSpec'); }
Subroutine colspec: not called CC=1 SCAR=6.9
5807 0 ▶ sub column1($) { $_[0]->type_error('Column'); }
Subroutine column1: not called CC=1 SCAR=6.9
5808 1 ▶ sub column1_single($) { $_[0]->type_error('Column'); }
Subroutine column1_single: called CC=1 SCAR=0.0
5809 0 ▶ sub constraint1($) { $_[0]->type_error('Constraint'); }
Subroutine constraint1: not called CC=1 SCAR=6.9
5810 0 ▶ sub desc($) { $_[0]->type_error('Desc'); }
Subroutine desc: not called CC=1 SCAR=6.9
5811 0 ▶ sub engine1($) { $_[0]->type_error('Engine'); }
Subroutine engine1: not called CC=1 SCAR=6.9
5812 0 ▶ sub expr($) { $_[0]->type_error('Expr'); }
Subroutine expr: not called CC=1 SCAR=6.9
5813 0 ▶ sub expr_or_check($) { $_[0]->type_error('Expr or Check'); }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5814 0 ▶ sub check($) { $_[0]->type_error('Check'); }
Subroutine check: not called CC=1 SCAR=6.9
5815 1 ▶ sub exprparen($) { $_[0]->type_error('Expr'); }
Subroutine exprparen: called CC=1 SCAR=0.0
5816 0 ▶ sub index1($) { $_[0]->type_error('Index'); }
Subroutine index1: not called CC=1 SCAR=6.9
5817 0 ▶ sub joinclause($) { $_[0]->type_error('JOIN clause'); }
Subroutine joinclause: not called CC=1 SCAR=6.9
5818 0 ▶ sub limit_number($) { $_[0]->type_error('number or ?'); }
Subroutine limit_number: not called CC=1 SCAR=6.9
5819 0 ▶ sub stmt($) { $_[0]->type_error('Stmt'); }
Subroutine stmt: not called CC=1 SCAR=6.9
5820 0 ▶ sub subquery($) { $_[0]->type_error('subquery'); }
Subroutine subquery: not called CC=1 SCAR=6.9
5821 0 ▶ sub table1($) { $_[0]->type_error('Table'); }
Subroutine table1: not called CC=1 SCAR=6.9
5822 0 ▶ sub tabname($) { $_[0]->type_error('TableName'); }
Subroutine tabname: not called CC=1 SCAR=6.9
5823 0 ▶ sub tableopt($) { $_[0]->type_error('TableOption'); }
Subroutine tableopt: not called CC=1 SCAR=6.9
5824 0 ▶ sub transcoding($) { $_[0]->type_error('Transcoding'); }
Subroutine transcoding: not called CC=1 SCAR=6.9
5825 0 ▶ sub transliteration1($) { $_[0]->type_error('Transliteration'); }
Subroutine transliteration1: not called CC=1 SCAR=6.9
5826 0 ▶ sub type($) { $_[0]->type_error('Type'); }
Subroutine type: not called CC=1 SCAR=6.9
5827  
5828 0 ▶ sub do($) { $_[0]->type_error('Do'); }
Subroutine do: not called CC=1 SCAR=6.9
5829 0 ▶ sub fetch($) { $_[0]->type_error('Fetch'); }
Subroutine fetch: not called CC=1 SCAR=6.9
5830 }
5831  
5832 # Obj1:
5833 {
5834 5 package SQL::Yapp::Obj1;
5835  
5836 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5837 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5838 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
5839 5 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
5840  
5841 sub obj($$)
5842 890 ▶ {
Subroutine obj: called CC=3 SCAR=11.0
5843 890 my ($class,$x)= @_;
5844 890 ▶ return $x
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($x) and $x->isa(__PACKAGE__) 159 731 890
Condition66%2/3
builtin::blessed($x) and $x->isa(__PACKAGE__)
!ll&&!rl&&r
7310159
MC/DC50%1/2
builtin::blessed($x) and $x->isa(__PACKAGE__)
builtin::blessed($x) $x->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($x)B= $x->isa(__PACKAGE__)
ABresult
0X0
100
111
5845 if blessed($x) && $x->isa(__PACKAGE__);
5846 731 return bless([$x], $class);
5847 }
5848  
5849 806 ▶ sub value($) { return $_[0][0]; }
Subroutine value: called CC=1 SCAR=0.0
5850 }
5851  
5852 ###############
5853 # Asterisk:
5854 {
5855 5 package SQL::Yapp::Asterisk;
5856  
5857 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5858 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5859 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
5860  
5861 sub obj($)
5862 2 ▶ {
Subroutine obj: called CC=1 SCAR=0.0
5863 2 my ($class)= @_;
5864 2 return bless([], $class);
5865 }
5866  
5867 2 ▶ sub value($) { return '*'; }
Subroutine value: called CC=1 SCAR=0.0
5868  
5869 2 ▶ sub column1($) { return $_[0]; }
Subroutine column1: called CC=1 SCAR=0.0
5870 0 ▶ sub column1_single($) { return $_[0]; }
Subroutine column1_single: not called CC=1 SCAR=6.9
5871 0 ▶ sub expr($) { return $_[0]; }
Subroutine expr: not called CC=1 SCAR=6.9
5872 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5873  
5874 0 ▶ sub asterisk($) { return $_[0]; }
Subroutine asterisk: not called CC=1 SCAR=6.9
5875 }
5876  
5877 # Question:
5878 {
5879 5 package SQL::Yapp::Question;
5880  
5881 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5882 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5883 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
5884  
5885 sub obj($)
5886 1 ▶ {
Subroutine obj: called CC=1 SCAR=0.0
5887 1 my ($class)= @_;
5888 1 return bless([], $class);
5889 }
5890  
5891 1 ▶ sub value($) { return '?' }
Subroutine value: called CC=1 SCAR=0.0
5892  
5893 0 ▶ sub limit_number($) { return $_[0]; }
Subroutine limit_number: not called CC=1 SCAR=6.9
5894 1 ▶ sub exprparen($) { return $_[0]; }
Subroutine exprparen: called CC=1 SCAR=0.0
5895 0 ▶ sub expr($) { return $_[0]; }
Subroutine expr: not called CC=1 SCAR=6.9
5896 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5897 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
5898 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
5899 }
5900  
5901 # ExprSpecial:
5902 {
5903 5 package SQL::Yapp::ExprSpecial;
5904  
5905 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5906 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5907 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
5908  
5909 0 ▶ sub exprparen($) { return $_[0]; }
Subroutine exprparen: not called CC=1 SCAR=6.9
5910 0 ▶ sub expr($) { return $_[0]; }
Subroutine expr: not called CC=1 SCAR=6.9
5911 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5912 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
5913 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
5914 }
5915  
5916 # Stmt:
5917 {
5918 5 package SQL::Yapp::Stmt;
5919  
5920 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5921 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5922 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5923 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
5924  
5925 1 ▶ sub subquery($) { $_[0]->type_error('SELECT statement'); }
Subroutine subquery: called CC=1 SCAR=0.0
5926 0 ▶ sub exprparen($) { $_[0]->subquery(); }
Subroutine exprparen: not called CC=1 SCAR=6.9
5927 2 ▶ sub expr($) { $_[0]->subquery(); }
Subroutine expr: called CC=1 SCAR=0.0
5928 0 ▶ sub expr_or_check($) { $_[0]->subquery(); }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5929 0 ▶ sub table1($) { $_[0]->subquery(); }
Subroutine table1: not called CC=1 SCAR=6.9
5930  
5931 3 ▶ sub stmt($) { return $_[0]; }
Subroutine stmt: called CC=1 SCAR=0.0
5932  
5933 sub do($)
5934 0 ▶ {
Subroutine do: not called CC=1 SCAR=6.9
5935 0 my ($stmt) = @_;
5936 0 my $dbh = SQL::Yapp::get_dbh();
5937 0 $dbh->do($stmt);
5938 0 return; # return no statements so that _max1_if_scalar is ok with void context
5939 }
5940 }
5941  
5942 # SelectStmt:
5943 {
5944 5 package SQL::Yapp::SelectStmt;
5945  
5946 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5947 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5948 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5949 5 ▶ use base qw(SQL::Yapp::Stmt);
Subroutine BEGIN: called CC=1 SCAR=0.0
5950  
5951 2 ▶ sub subquery($) { return '('.($_[0]->value).')'; }
Subroutine subquery: called CC=1 SCAR=0.0
5952  
5953 sub fetch($)
5954 0 ▶ {
Subroutine fetch: not called CC=2 SCAR=17.9
5955 0 my ($stmt) = @_;
5956 0 my $dbh = SQL::Yapp::get_dbh();
5957 0 my $sth = $dbh->prepare($stmt);
5958 0 my $aref = $dbh->selectall_arrayref($sth, { Slice => {} });
5959 0 ▶ return unless $aref;
Branch: 1 branch
BranchTrueFalseTotal
unless $aref 0 0 0
5960 0 return @$aref;
5961 }
5962 }
5963  
5964 # SelectStmtSingle:
5965 {
5966 5 package SQL::Yapp::SelectStmtSingle;
5967  
5968 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5969 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5970 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5971 5 ▶ use base qw(SQL::Yapp::SelectStmt);
Subroutine BEGIN: called CC=1 SCAR=0.0
5972  
5973 sub fetch($)
5974 0 ▶ {
Subroutine fetch: not called CC=4 SCAR=30.0
5975 0 my ($stmt) = @_;
5976 0 my $dbh = SQL::Yapp::get_dbh();
5977 0 my $sth = $dbh->prepare($stmt);
5978 0 ▶ return unless $sth->execute;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth->execute 0 0 0
5979 0 my @r= ();
5980 0 ▶ while (my $a= $sth->fetchrow_arrayref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $sth->fetchrow_arrayref) 0 0 0
5981 0 ▶ die unless scalar(@$a) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$a == 1 0 0 0
5982 0 push @r, $a->[0];
5983 }
5984 0 return @r;
5985 }
5986 }
5987  
5988 # Do:
5989 # This is a bit different, since the obj() method will actually execute the statement.
5990 {
5991 5 package SQL::Yapp::Do;
5992  
5993 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5994 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5995 5 ▶ use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
5996  
5997 sub obj($$)
5998 0 ▶ {
Subroutine obj: not called CC=1 SCAR=6.9
5999 0 my ($class, $stmt) = @_;
6000 0 return $stmt->do;
6001 }
6002 }
6003  
6004 # Fetch:
6005 # This is a bit different, since the obj() method will actually execute the statement.
6006 {
6007 5 package SQL::Yapp::Fetch;
6008  
6009 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6010 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6011  
6012 sub obj($$)
6013 0 ▶ {
Subroutine obj: not called CC=1 SCAR=6.9
6014 0 my ($class, $stmt) = @_;
6015 0 return $stmt->fetch;
6016 }
6017 }
6018  
6019 # ColumnName:
6020 {
6021 5 package SQL::Yapp::ColumnName;
6022  
6023 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6024 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6025 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6026  
6027 0 ▶ sub colname($) { return $_[0]; }
Subroutine colname: not called CC=1 SCAR=6.9
6028 }
6029  
6030 # TableName:
6031 {
6032 5 package SQL::Yapp::TableName;
6033  
6034 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6035 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6036 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6037  
6038 0 ▶ sub tabname($) { return $_[0]; }
Subroutine tabname: not called CC=1 SCAR=6.9
6039 }
6040  
6041 # Column:
6042 {
6043 5 package SQL::Yapp::Column;
6044  
6045 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6046 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6047 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6048  
6049 2 ▶ sub column1($) { return $_[0]; }
Subroutine column1: called CC=1 SCAR=0.0
6050 3 ▶ sub exprparen($) { return $_[0]; }
Subroutine exprparen: called CC=1 SCAR=0.0
6051 1 ▶ sub expr($) { return $_[0]; }
Subroutine expr: called CC=1 SCAR=0.0
6052 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
6053 2 ▶ sub asc($) { return $_[0]; }
Subroutine asc: called CC=1 SCAR=0.0
6054 5 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: called CC=1 SCAR=0.0
6055 }
6056  
6057 # Table:
6058 {
6059 5 package SQL::Yapp::Table;
6060 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6061 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6062 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6063 5 ▶ sub table1($) { return $_[0]; }
Subroutine table1: called CC=1 SCAR=0.0
6064 }
6065  
6066 # CharSet:
6067 {
6068 5 package SQL::Yapp::CharSet;
6069 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6070 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6071 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6072 0 ▶ sub charset1($) { return $_[0]; }
Subroutine charset1: not called CC=1 SCAR=6.9
6073 }
6074  
6075 # Collate:
6076 {
6077 5 package SQL::Yapp::Collate;
6078 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6079 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6080 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6081 0 ▶ sub collate1($) { return $_[0]; }
Subroutine collate1: not called CC=1 SCAR=6.9
6082 }
6083  
6084 # Constraint:
6085 {
6086 5 package SQL::Yapp::Constraint;
6087 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6088 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6089 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6090 0 ▶ sub constraint1($) { return $_[0]; }
Subroutine constraint1: not called CC=1 SCAR=6.9
6091 }
6092  
6093 # Index:
6094 {
6095 5 package SQL::Yapp::Index;
6096 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6097 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6098 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6099 0 ▶ sub index1($) { return $_[0]; }
Subroutine index1: not called CC=1 SCAR=6.9
6100 }
6101  
6102 # Transliteration:
6103 {
6104 5 package SQL::Yapp::Transliteration;
6105 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6106 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6107 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6108 0 ▶ sub transliteration($) { return $_[0]; }
Subroutine transliteration: not called CC=1 SCAR=6.9
6109 }
6110  
6111 # Transcoding:
6112 {
6113 5 package SQL::Yapp::Transcoding;
6114 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6115 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6116 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6117 0 ▶ sub transcoding($) { return $_[0]; }
Subroutine transcoding: not called CC=1 SCAR=6.9
6118 }
6119  
6120 # TableOption:
6121 {
6122 5 package SQL::Yapp::TableOption;
6123 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6124 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6125 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6126 2 ▶ sub tableopt($) { return $_[0]; }
Subroutine tableopt: called CC=1 SCAR=0.0
6127 }
6128  
6129 # Engine:
6130 {
6131 5 package SQL::Yapp::Engine;
6132 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6133 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6134 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6135 0 ▶ sub engine1($) { return $_[0]; }
Subroutine engine1: not called CC=1 SCAR=6.9
6136 }
6137  
6138  
6139 # Join:
6140 {
6141 5 package SQL::Yapp::Join;
6142  
6143 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6144 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6145 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6146  
6147 4 ▶ sub joinclause($) { return $_[0]; }
Subroutine joinclause: called CC=1 SCAR=0.0
6148 }
6149  
6150 # Check:
6151 {
6152 5 package SQL::Yapp::Check;
6153  
6154 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6155 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6156 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6157  
6158 3 ▶ sub check($) { return $_[0]; }
Subroutine check: called CC=1 SCAR=0.0
6159 3 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: called CC=1 SCAR=0.0
6160  
6161 sub obj($$)
6162 18 ▶ {
Subroutine obj: called CC=3 SCAR=11.0
6163 18 ▶ if (ref($_[1]) eq $_[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[1] eq $_[0]) { } 9 9 18
elsif (ref $_[1]) { } 7 2 9
6164 9 return $_[1];
6165 }
6166 elsif (ref($_[1])) {
6167 7 bless($_[1], $_[0]);
6168 }
6169 else {
6170 2 $_[0]->SUPER::obj($_[1]);
6171 }
6172 }
6173 }
6174  
6175 # Expr:
6176 {
6177 5 package SQL::Yapp::Expr;
6178  
6179 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6180 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6181 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6182  
6183 0 ▶ sub exprparen($) { return '('.($_[0]->value).')'; }
Subroutine exprparen: not called CC=1 SCAR=6.9
6184 18 ▶ sub expr($) { return $_[0]; }
Subroutine expr: called CC=1 SCAR=0.0
6185 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
6186 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
6187 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
6188 }
6189  
6190 # Infix:
6191 {
6192 5 package SQL::Yapp::Infix;
6193  
6194 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6195 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6196 5 ▶ use base qw(SQL::Yapp::Expr);
Subroutine BEGIN: called CC=1 SCAR=0.0
6197 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6198  
6199 sub obj($$$$)
6200 56 ▶ {
Subroutine obj: called CC=1 SCAR=0.0
6201 56 my ($class, $op, $a1, $a2)= @_;
6202 56 return bless(["$a1 $op $a2", $op, $a1, $a2], $class);
6203 }
6204  
6205 14 ▶ sub op($) { return $_[0][1]; }
Subroutine op: called CC=1 SCAR=0.0
6206 14 ▶ sub arg1($) { return $_[0][2]; }
Subroutine arg1: called CC=1 SCAR=0.0
6207 14 ▶ sub arg2($) { return $_[0][3]; }
Subroutine arg2: called CC=1 SCAR=0.0
6208  
6209 sub assign($)
6210 14 ▶ {
Subroutine assign: called CC=2 SCAR=7.6
6211 14 my ($self)= @_;
6212 14 ▶ if ($self->op() eq '=') { # we're not checking everything, just whether it's an assignment
Branch: 1 branch
BranchTrueFalseTotal
if ($self->op eq "=") 14 0 14
6213 14 return $self;
6214 }
6215 0 croak "Assignment expected, but found top-level operator '".($self->op)."'.";
6216 }
6217 }
6218  
6219 # Order:
6220 {
6221 5 package SQL::Yapp::Order;
6222  
6223 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6224 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6225 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6226 5 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
6227  
6228 sub obj($$)
6229 7 ▶ {
Subroutine obj: called CC=3 SCAR=14.2
6230 7 my ($class,$x)= @_;
6231 7 ▶ return $x
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($x) and $x->isa("SQL::Yapp::Obj") 7 0 7
Condition33%1/3
builtin::blessed($x) and $x->isa("SQL::Yapp::Obj")
!ll&&!rl&&r
007
MC/DC0%0/2
builtin::blessed($x) and $x->isa("SQL::Yapp::Obj")
builtin::blessed($x) $x->isa("SQL::Yapp::Obj")
Truth table33%1/3
A and B
A= builtin::blessed($x)B= $x->isa("SQL::Yapp::Obj")
ABresult
0X0
100
111
6232 if blessed($x) && $x->isa('SQL::Yapp::Obj');
6233 0 return bless([$x], 'SQL::Yapp::Asc'); # not Order, but Asc.
6234 }
6235 }
6236  
6237 # Asc:
6238 {
6239 5 package SQL::Yapp::Asc;
6240  
6241 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6242 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6243 5 ▶ use base qw(SQL::Yapp::Order);
Subroutine BEGIN: called CC=1 SCAR=0.0
6244  
6245 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
6246 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
6247 }
6248  
6249 # Desc:
6250 {
6251 5 package SQL::Yapp::Desc;
6252  
6253 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6254 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6255 5 ▶ use base qw(SQL::Yapp::Order);
Subroutine BEGIN: called CC=1 SCAR=0.0
6256  
6257 sub obj($$)
6258 9 ▶ {
Subroutine obj: called CC=1 SCAR=0.0
6259 9 my ($class, $orig)= @_;
6260 9 return bless(["$orig DESC",$orig],$class);
6261 }
6262  
6263 1 ▶ sub orig($) { return $_[0][1]; }
Subroutine orig: called CC=1 SCAR=0.0
6264  
6265 2 ▶ sub asc($) { return $_[0]; }
Subroutine asc: called CC=1 SCAR=0.0
6266 1 ▶ sub desc($) { return &orig; }
Subroutine desc: called CC=1 SCAR=0.0
6267 }
6268  
6269 # Type:
6270 {
6271 5 package SQL::Yapp::Type;
6272  
6273 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6274 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6275 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
6276 5 ▶ use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
6277 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6278  
6279 sub set_base($$$)
6280 11 ▶ {
Subroutine set_base: called CC=3 SCAR=11.0
6281 11 my ($self, $base, $spec)= @_;
6282  
6283 # set new spec:
6284 11 $self->{base}= $base;
6285 11 $self->{spec}= $spec;
6286  
6287 # filter options by new spec:
6288 11 for my $o (keys %{ $self->{option} }) {
6289 3 ▶ unless ($spec->{$o}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($spec->{$o}) 1 2 3
6290 1 delete $self->{option}{$o};
6291 }
6292 }
6293  
6294 11 return $self;
6295 }
6296  
6297 sub set_property($$$)
6298 13 ▶ {
Subroutine set_property: called CC=2 SCAR=7.0
6299 13 my ($self, $key, $value)= @_;
6300 13 my %a= %$self;
6301 13 ▶ croak "No $key for $self->{base} allowed." unless $self->{spec}{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"spec"}{$key} 0 13 13
6302 13 $self->{option}{$key}= $value;
6303 13 return $self;
6304 }
6305  
6306 sub new($)
6307 9 ▶ {
Subroutine new: called CC=1 SCAR=0.0
6308 9 my $r= bless({ base => undef, spec => undef, option => {} }, $_[0]);
6309 9 lock_keys %$r;
6310 9 return $r;
6311 }
6312  
6313 sub obj($$)
6314 13 ▶ {
Subroutine obj: called CC=1 SCAR=0.0
6315 13 return $_[1];
6316 }
6317  
6318 sub clone($)
6319 11 ▶ {
Subroutine clone: called CC=1 SCAR=0.0
6320 11 my ($self)= @_;
6321 my $r= bless({
6322 %$self,
6323 # no need to make a deep copy of 'spec', because it is never changed.
6324 11 option => { %{ $self->{option} } },
6325 }, __PACKAGE__);
6326 11 lock_keys %$r;
6327 11 return $r;
6328 }
6329  
6330 sub type($)
6331 7 ▶ {
Subroutine type: called CC=1 SCAR=0.0
6332 7 return $_[0]->clone(); # make a copy before trying to modify this
6333 }
6334  
6335 sub colspec($)
6336 1 ▶ {
Subroutine colspec: called CC=1 SCAR=0.0
6337 1 return SQL::Yapp::ColumnSpec->new($_[0]); # make a copy producing a ColumnSpec
6338 }
6339  
6340 sub value($)
6341 27 ▶ {
Subroutine value: called CC=19 SCAR=35.0
6342 27 my ($self)= @_;
6343 27 ▶ return '<error: no base type>' unless $self->{base};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"base"} 9 18 27
6344 18 my @r= ($self->{base});
6345 18 ▶ if ($self->{spec}{prec1} && defined $self->{option}{prec1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"spec"}{"prec1"} and defined $self->{"option"}{"prec1"}) 17 1 18
Condition66%2/3
$self->{"spec"}{"prec1"} and defined $self->{"option"}{"prec1"}
!ll&&!rl&&r
0117
MC/DC50%1/2
$self->{"spec"}{"prec1"} and defined $self->{"option"}{"prec1"}
$self->{"spec"}{"prec1"} defined $self->{"option"}{"prec1"}
Truth table66%2/3
A and B
A= $self->{"spec"}{"prec1"}B= defined $self->{"option"}{"prec1"}
ABresult
0X0
100
111
6346 17 my $len_str= '';
6347 17 $len_str.= $self->{option}{prec1};
6348 17 ▶ if ($self->{spec}{prec2} && defined $self->{option}{prec2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'spec'}{'prec2'} and defined $self->{'option'}{'prec2'}) { } 0 17 17
Condition66%2/3
$self->{"spec"}{"prec2"} and defined $self->{"option"}{"prec2"}
!ll&&!rl&&r
1520
MC/DC0%0/2
$self->{"spec"}{"prec2"} and defined $self->{"option"}{"prec2"}
$self->{"spec"}{"prec2"} defined $self->{"option"}{"prec2"}
Truth table66%2/3
A and B
A= $self->{"spec"}{"prec2"}B= defined $self->{"option"}{"prec2"}
ABresult
0X0
100
111
6349 0 $len_str.= ', '.$self->{option}{prec2};
6350 }
6351 else {
6352 17 ▶ if ($self->{spec}{prec_mul} && $self->{option}{prec_mul}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"spec"}{"prec_mul"} and $self->{"option"}{"prec_mul"}) 0 17 17
Condition33%1/3
$self->{"spec"}{"prec_mul"} and $self->{"option"}{"prec_mul"}
!ll&&!rl&&r
1700
MC/DC0%0/2
$self->{"spec"}{"prec_mul"} and $self->{"option"}{"prec_mul"}
$self->{"spec"}{"prec_mul"} $self->{"option"}{"prec_mul"}
Truth table33%1/3
A and B
A= $self->{"spec"}{"prec_mul"}B= $self->{"option"}{"prec_mul"}
ABresult
0X0
100
111
6353 0 $len_str.= ' '.$self->{option}{prec_mul};
6354 }
6355 17 ▶ if ($self->{spec}{prec_unit} && $self->{option}{prec_unit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"spec"}{"prec_unit"} and $self->{"option"}{"prec_unit"}) 0 17 17
Condition33%1/3
$self->{"spec"}{"prec_unit"} and $self->{"option"}{"prec_unit"}
!ll&&!rl&&r
1700
MC/DC0%0/2
$self->{"spec"}{"prec_unit"} and $self->{"option"}{"prec_unit"}
$self->{"spec"}{"prec_unit"} $self->{"option"}{"prec_unit"}
Truth table33%1/3
A and B
A= $self->{"spec"}{"prec_unit"}B= $self->{"option"}{"prec_unit"}
ABresult
0X0
100
111
6356 0 $len_str.= ' '.$self->{option}{prec_unit};
6357 }
6358 }
6359 17 push @r, '('.$len_str.')';
6360 }
6361 18 ▶ if (my $value_list= $self->{spec}{value_list} && $self->{option}{value_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $value_list = $self->{"spec"}{"value_list"} && $self->{"option"}{"value_list"}) 0 18 18
Condition33%1/3
$self->{'spec'}{'value_list'} && $self->{'option'}{'value_list'}
!ll&&!rl&&r
1800
MC/DC0%0/2
$self->{'spec'}{'value_list'} && $self->{'option'}{'value_list'}
$self->{'spec'}{'value_list'} $self->{'option'}{'value_list'}
Truth table33%1/3
A && B
A= $self->{'spec'}{'value_list'}B= $self->{'option'}{'value_list'}
ABresult
0X0
100
111
6362 0 push @r, '('.join(', ',@$value_list).')';
6363 }
6364 18 ▶ if (my $x= $self->{spec}{charset} && $self->{option}{charset}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"spec"}{"charset"} && $self->{"option"}{"charset"}) 2 16 18
Condition100%3/3
$self->{'spec'}{'charset'} && $self->{'option'}{'charset'}
!ll&&!rl&&r
5112
MC/DC100%2/2
$self->{'spec'}{'charset'} && $self->{'option'}{'charset'}
$self->{'spec'}{'charset'} $self->{'option'}{'charset'}
Truth table100%3/3
A && B
A= $self->{'spec'}{'charset'}B= $self->{'option'}{'charset'}
ABresult
0X0
100
111
6365 2 push @r, 'CHARACTER SET', $x;
6366 }
6367 18 ▶ if (my $x= $self->{spec}{collate} && $self->{option}{collate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"spec"}{"collate"} && $self->{"option"}{"collate"}) 0 18 18
Condition66%2/3
$self->{'spec'}{'collate'} && $self->{'option'}{'collate'}
!ll&&!rl&&r
5130
MC/DC0%0/2
$self->{'spec'}{'collate'} && $self->{'option'}{'collate'}
$self->{'spec'}{'collate'} $self->{'option'}{'collate'}
Truth table66%2/3
A && B
A= $self->{'spec'}{'collate'}B= $self->{'option'}{'collate'}
ABresult
0X0
100
111
6368 0 push @r, 'COLLATE', $x;
6369 }
6370 18 for my $key ('sign', 'zerofill', 'timezone') {
6371 54 ▶ if (my $x= $self->{spec}{$key} && $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"spec"}{$key} && $self->{"option"}{$key}) 0 54 54
Condition66%2/3
$self->{'spec'}{$key} && $self->{'option'}{$key}
!ll&&!rl&&r
44100
MC/DC0%0/2
$self->{'spec'}{$key} && $self->{'option'}{$key}
$self->{'spec'}{$key} $self->{'option'}{$key}
Truth table66%2/3
A && B
A= $self->{'spec'}{$key}B= $self->{'option'}{$key}
ABresult
0X0
100
111
6372 0 push @r, $x;
6373 }
6374 }
6375  
6376 18 return join(' ', @r);
6377 }
6378 }
6379  
6380  
6381 # ColumnSpec:
6382 {
6383 5 package SQL::Yapp::ColumnSpec;
6384  
6385 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6386 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6387 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
6388 5 ▶ use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
6389 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6390  
6391 sub new($$)
6392 3 ▶ {
Subroutine new: called CC=1 SCAR=0.0
6393 3 my ($class, $type)= @_;
6394 3 my $r= bless({ datatype => $type->clone(), name => {}, option => {} }, $class);
6395 3 lock_keys %$r;
6396 3 return $r;
6397 }
6398  
6399 sub obj($$)
6400 3 ▶ {
Subroutine obj: called CC=1 SCAR=0.0
6401 3 return $_[1];
6402 }
6403  
6404 sub clone($)
6405 1 ▶ {
Subroutine clone: called CC=1 SCAR=0.0
6406 1 my ($self)= @_;
6407 my $r= bless({
6408 datatype => $self->{datatype}->clone(),
6409 1 name => { %{ $self->{name} } },
6410 1 option => { %{ $self->{option} } },
6411 }, __PACKAGE__);
6412 1 lock_keys %$r;
6413 1 return $r;
6414 }
6415  
6416 sub colspec($)
6417 1 ▶ {
Subroutine colspec: called CC=1 SCAR=0.0
6418 1 return $_[0]->clone(); # make a copy before trying to modify this
6419 }
6420  
6421 sub name($$)
6422 6 ▶ {
Subroutine name: called CC=2 SCAR=7.6
6423 6 my ($self, $key)= @_;
6424 6 ▶ if (my $x= $self->{name}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"name"}{$key}) 0 6 6
6425 0 return ('CONSTRAINT', $x);
6426 }
6427 6 return;
6428 }
6429  
6430 sub value($)
6431 4 ▶ {
Subroutine value: called CC=9 SCAR=22.4
6432 4 my ($self)= @_;
6433 4 my @r= ($self->{datatype});
6434  
6435 4 for my $key ('notnull', 'autoinc', 'unique', 'primary', 'key') {
6436 20 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 4 16 20
6437 4 push @r, $self->name($key), $x;
6438 }
6439 }
6440  
6441 4 for my $key ('default', 'column_format', 'storage') {
6442 12 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 2 10 12
6443 2 push @r, $self->name($key), uc($key), $x;
6444 }
6445 }
6446  
6447 4 for my $key ('check') {
6448 4 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 0 4 4
6449 0 push @r, $self->name($key), uc($key), '('.$x.')';
6450 }
6451 }
6452  
6453 4 for my $key ('references') {
6454 4 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 0 4 4
6455 0 push @r, $self->name($key), $x;
6456 }
6457 }
6458  
6459 4 return join(' ', @r);
6460 }
6461 }
6462  
6463  
6464 # Special Constants:
6465 2 ▶sub ASTERISK { SQL::Yapp::Asterisk->obj(); }
Subroutine ASTERISK: called CC=1 SCAR=0.0
Pod undocumented
6466 1 ▶sub QUESTION { SQL::Yapp::Question->obj(); }
Subroutine QUESTION: called CC=1 SCAR=0.0
Pod undocumented
6467 0 ▶sub NULL { SQL::Yapp::ExprSpecial->obj('NULL'); }
Subroutine NULL: not called CC=1 SCAR=6.9
Pod undocumented
6468 0 ▶sub TRUE { SQL::Yapp::ExprSpecial->obj('TRUE'); }
Subroutine TRUE: not called CC=1 SCAR=6.9
Pod undocumented
6469 0 ▶sub FALSE { SQL::Yapp::ExprSpecial->obj('FALSE'); }
Subroutine FALSE: not called CC=1 SCAR=6.9
Pod undocumented
6470 0 ▶sub UNKNOWN { SQL::Yapp::ExprSpecial->obj('UNKNOWN'); }
Subroutine UNKNOWN: not called CC=1 SCAR=6.9
Pod undocumented
6471 0 ▶sub DEFAULT { SQL::Yapp::ExprSpecial->obj('DEFAULT'); }
Subroutine DEFAULT: not called CC=1 SCAR=6.9
Pod undocumented
6472  
6473  
6474 # Wrapped DBI methods:
6475 sub croak_no_ref($)
6476 1 ▶{
Subroutine croak_no_ref: called CC=1 SCAR=0.0
Pod undocumented
6477 1 my ($self)= @_;
6478 1 croak "Error: Wrong type argument from interpolated code:\n".
6479 "\tExpected scalar, but found ".my_dumper($self);
6480 }
6481  
6482 ########################################
6483 # Generators:
6484  
6485 # These functions are used to typecheck interpolated Perl code's
6486 # result values and to generate objects on the fly if that's possible.
6487 # Usually on-the-fly generation coerces basic Perl types to a blessed
6488 # object, but it would also be feasible to coerce objects to objects.
6489 # Some 'generator' functions don't generate at all, but simply type
6490 # check.
6491 #
6492 # Note: often these functions are invoked in string context, which
6493 # means that directly after their invocation, the string cast operator
6494 # is invoked. However, there's no easy way to prevent object creation
6495 # in that case, because there is no such thing as 'wantstring'
6496 # (would-be analog to 'wantarray'). So these functions must always
6497 # return a blessed reference.
6498  
6499 sub _functor($$@)
6500 106 ▶{
Subroutine _functor: called CC=4 SCAR=13.9
6501 106 my ($functor, $parens, @arg)= @_;
6502  
6503 # possibly translate the functor to a different SQL dialect:
6504 106 ▶ if (my $dialect= $functor->{dialect}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dialect = $functor->{"dialect"}) 97 9 106
6505 97 ▶ if (my $f2= find_ref(%$dialect, $write_dialect)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f2 = &find_ref(\%$dialect, $write_dialect)) 28 69 97
6506 28 $functor= $f2;
6507 }
6508 }
6509  
6510 # print it:
6511 106 my $name= $functor->{value};
6512  
6513 # prefix and suffix are not handled here, because they behave
6514 # differently: they assume exactly one argument are applied
6515 # point-wise. They cannot be switched (ok, we might switch
6516 # between prefix and suffix, but that's not supported yet).
6517 my $s= switch ($functor->{type},
6518 52 ▶ 'infix()' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
6519 (scalar(@arg) ?
6520 join(" $name ", @arg)
6521 : defined($functor->{result0}) ?
6522 get_quote_val->($functor->{result0})
6523 52 ▶ : die "Error: Functor $functor->{value} used with 0 args, but requires at least one."
Branch: 2 branches
BranchTrueFalseTotal
scalar @arg ? : 46 6 52
defined $functor->{'result0'} ? : 6 0 6
6524 );
6525 },
6526 21 ▶ 'funcall' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
6527 21 $parens= 0;
6528 21 "$name(".join(", ", @arg).")";
6529 },
6530 26 ▶ 'prefix' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
6531 26 ▶ die "Error: Exactly one argument expected for operator $functor->{value},\n".
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @arg == 1 1 25 26
6532 "\tfound (".join(",", @arg).")"
6533 unless scalar(@arg) == 1;
6534 25 "$name $arg[0]"
6535 },
6536 7 ▶ 'suffix' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
6537 7 ▶ die "Error: exactly one argument expected, found @arg" unless scalar(@arg) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @arg == 1 0 7 7
6538 7 "$arg[0] $name"
6539 },
6540 106 );
6541 105 ▶ return $parens ? "($s)" : $s;
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 35 70 105
6542 }
6543  
6544 sub _prefix($$@)
6545 67 ▶{
Subroutine _prefix: called CC=2 SCAR=6.9
6546 67 my ($name, $parens)= splice @_,0,2;
6547 67 ▶ return _functor($functor_prefix{$name} || { value => $name, type => 'funcall' } , $parens, @_);
Condition100%2/2
$functor_prefix{$name} || {'value', $name, 'type', 'funcall'}
l!l
589
MC/DC100%1/1
$functor_prefix{$name} || {'value', $name, 'type', 'funcall'}
$functor_prefix{$name}
Truth table100%2/2
A
A= $functor_prefix{$name}
Aresult
11
00
6548 }
6549  
6550 sub _suffix($$@)
6551 39 ▶{
Subroutine _suffix: called CC=1 SCAR=0.0
6552 39 my ($name, $parens)= splice @_,0,2;
6553 39 return _functor($functor_suffix{$name}, $parens, @_);
6554 }
6555  
6556 sub _max1_if_scalar(@)
6557 219 ▶{
Subroutine _max1_if_scalar: called CC=5 SCAR=16.1
6558 # void context:
6559 219 ▶ unless (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 1 218 219
6560 1 ▶ return if scalar(@_) == 0; # allow void context with no params (e.g. after Do)
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 0 0 1 1
6561 1 croak 'Error: NYI: void context is currently not supported for SQL blocks.';
6562 }
6563  
6564 # list context:
6565 218 ▶ return @_ if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 27 191 218
6566  
6567 # scalar context:
6568 191 ▶ croak 'Error: Multiple results cannot be assigned to scalar'
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 1 1 190 191
6569 if scalar(@_) > 1;
6570 190 return $_[0];
6571 }
6572  
6573 sub min1(@)
6574 0 ▶{
Subroutine min1: not called CC=2 SCAR=17.9
Pod undocumented
6575 0 ▶ croak 'Error: Expected at least one element, but found an empty list'
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 0 0 0 0
6576 if scalar(@_) == 0;
6577 0 return @_;
6578 }
6579  
6580 sub min1default($@)
6581 0 ▶{
Subroutine min1default: not called CC=2 SCAR=17.9
Pod undocumented
6582 0 ▶ return @_ if scalar(@_) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 0 0 0
6583 0 shift;
6584 0 return @_;
6585 }
6586  
6587 sub joinlist($$$$$@)
6588 213 ▶{
Subroutine joinlist: called CC=3 SCAR=12.0
Pod undocumented
6589 213 ▶ if (scalar(@_) == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 5) 1 212 213
6590 1 ▶ return $_[1] if defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 1 0 1
6591 0 my ($module, $file, $line)= caller;
6592 0 croak "$file:$_[0]: Error: Expected at least one element, but found an empty list";
6593 }
6594 212 return $_[2].join ($_[3], @_[5..$#_]).$_[4];
6595 }
6596  
6597 sub assign($) # check that the result is an assignment, i.e.:`a` = <expr>
6598 14 ▶{
Subroutine assign: called CC=2 SCAR=7.6
Pod undocumented
6599 14 my ($x)= @_;
6600 14 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 14 0 14
6601 14 return $x->assign();
6602 }
6603 else {
6604 0 croak "Assignment expected, but found non-reference.";
6605 }
6606 }
6607  
6608 sub set2values(@)
6609 7 ▶{
Subroutine set2values: called CC=2 SCAR=7.0
Pod undocumented
6610 7 ▶ croak "At least one value expected" if scalar(@_) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 0 0 7 7
6611 return
6612 ' ('.
6613 14 join(',', map { assign($_)->arg1() } @_).
6614 ') VALUES ('.
6615 7 join(',', map { $_->arg2() } @_).
6616 ')';
6617 }
6618  
6619 sub exprlist($)
6620 7 ▶{
Subroutine exprlist: called CC=3 SCAR=11.3
Pod undocumented
6621 7 my ($x)= @_;
6622 7 ▶ croak "Array reference expected for expression list"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x eq "ARRAY" 0 7 7
6623 unless ref($x) eq 'ARRAY';
6624 7 ▶ croak "At least one element expected in expression list"
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$x >= 1 0 7 7
6625 unless scalar(@$x) >= 1;
6626 7 return '('.join(', ', map { expr($_) } @$x).')';
6627 }
6628  
6629 ####################
6630 # Type
6631  
6632 sub type($)
6633 7 ▶{
Subroutine type: called CC=2 SCAR=7.6
Pod undocumented
6634 7 my ($x)= @_;
6635 7 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 7 0 7
6636 7 return $x->type();
6637 }
6638 else {
6639 0 croak "Type expected, but found non-reference (user types are not supported yet).";
6640 }
6641 }
6642  
6643 # These have $self at the end because it's easier to generate code like that.
6644 sub type_base($$)
6645 11 ▶{
Subroutine type_base: called CC=3 SCAR=11.3
Pod undocumented
6646 11 my $self= pop @_;
6647 11 my ($base)= @_;
6648 11 ▶ croak "Unrecognised base type '$base'" unless
Branch: 1 branch
BranchTrueFalseTotal
unless my $spec = &find_ref(\%type_spec, $base) 0 11 11
6649 my $spec= find_ref(%type_spec, $base);
6650 11 ▶ die unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 11 11
6651 11 return $self->set_base($base, $spec);
6652 }
6653  
6654 sub type_basewlist($@)
6655 0 ▶{
Subroutine type_basewlist: not called CC=3 SCAR=24.8
Pod undocumented
6656 0 my $self= pop @_;
6657 0 my ($base, @value)= @_;
6658 0 ▶ croak "Unrecognised base type '$base'" unless
Branch: 1 branch
BranchTrueFalseTotal
unless my $spec = &find_ref(\%type_spec, $base) 0 0 0
6659 my $spec= find_ref(%type_spec, $base);
6660 0 ▶ die unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
6661 0 $self->set_base($base, $spec);
6662 0 $self->set_property('value_list', \@value);
6663 0 return $self;
6664 }
6665  
6666 sub type_length($$;$)
6667 11 ▶{
Subroutine type_length: called CC=2 SCAR=7.0
Pod undocumented
6668 11 my $self= pop @_;
6669 11 my ($prec1, $prec2)= @_;
6670 11 $self->set_property('prec1', $prec1);
6671 11 ▶ $self->set_property('prec2', $prec2) if defined $prec2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prec2 0 11 11
6672 11 return $self;
6673 }
6674  
6675 sub type_largelength($$$;$)
6676 0 ▶{
Subroutine type_largelength: not called CC=3 SCAR=24.8
Pod undocumented
6677 0 my $self= pop @_;
6678 0 my ($coeff, $mul, $unit)= @_;
6679 0 $self->set_property('prec1', $coeff);
6680 0 ▶ $self->set_property('prec_mul', $mul) if defined $mul;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mul 0 0 0
6681 0 ▶ $self->set_property('prec_unit', $unit) if defined $unit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $unit 0 0 0
6682 0 return $self;
6683 }
6684  
6685 sub type_property($$$)
6686 2 ▶{
Subroutine type_property: called CC=1 SCAR=0.0
Pod undocumented
6687 2 my $self= pop @_;
6688 2 my ($key,$value)= @_;
6689 2 $self->set_property($key,$value);
6690 2 return $self;
6691 }
6692  
6693 ####################
6694 # ColumnSpec
6695  
6696 sub colspec($)
6697 2 ▶{
Subroutine colspec: called CC=2 SCAR=7.6
Pod undocumented
6698 2 my ($x)= @_;
6699 2 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 2 0 2
6700 2 return $x->colspec();
6701 }
6702 else {
6703 0 croak "ColumnSpec expected, but found non-reference (user types are not supported yet).";
6704 }
6705 }
6706  
6707 sub colspec_property($$$$)
6708 4 ▶{
Subroutine colspec_property: called CC=1 SCAR=0.0
Pod undocumented
6709 4 my $self= pop @_;
6710 4 my ($name, $key, $value)= @_;
6711 4 $self->{name}{$key}= $name;
6712 4 $self->{option}{$key}= $value;
6713 4 return $self;
6714 }
6715  
6716 sub colspec_type_base($$)
6717 0 ▶{
Subroutine colspec_type_base: not called CC=1 SCAR=6.9
Pod undocumented
6718 0 my $self= pop @_;
6719 0 my ($base)= @_;
6720 0 type_base($base, $self->{datatype});
6721 0 return $self;
6722 }
6723  
6724 sub colspec_type_property($$$)
6725 0 ▶{
Subroutine colspec_type_property: not called CC=1 SCAR=6.9
Pod undocumented
6726 0 my $self= pop @_;
6727 0 my ($key, $value)= @_;
6728 0 type_property($key, $value, $self->{datatype});
6729 0 return $self;
6730 }
6731  
6732 sub colspec_type_basewlist($@)
6733 0 ▶{
Subroutine colspec_type_basewlist: not called CC=1 SCAR=6.9
Pod undocumented
6734 0 my $self= pop @_;
6735 0 my ($base, @value)= @_;
6736 0 type_basewlist($base, @value, $self->{datatype});
6737 0 return $self;
6738 }
6739  
6740 sub colspec_type_length($$;$)
6741 0 ▶{
Subroutine colspec_type_length: not called CC=1 SCAR=6.9
Pod undocumented
6742 0 my $self= pop @_;
6743 0 my ($prec1, $prec2)= @_;
6744 0 type_length($prec1, $prec2, $self->{datatype});
6745 0 return $self;
6746 }
6747  
6748 sub colspec_type_largelength($$$;$)
6749 0 ▶{
Subroutine colspec_type_largelength: not called CC=1 SCAR=6.9
Pod undocumented
6750 0 my $self= pop @_;
6751 0 my ($coeff, $mul, $unit)= @_;
6752 0 type_largelength($coeff, $mul, $unit, $self->{datatype});
6753 0 return $self;
6754 }
6755  
6756 ####################
6757 # identifier interpolation, column and table:
6758  
6759 sub tabname($)
6760 1 ▶{
Subroutine tabname: called CC=3 SCAR=13.3
Pod undocumented
6761 1 my ($x)= @_;
6762 1 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 0 1 1
elsif (defined $x) { } 1 0 1
6763 0 return $x->tabname;
6764 }
6765 elsif (defined $x) {
6766 1 return SQL::Yapp::TableName->obj(get_quote_id->($xlat_table->($x)));
6767 }
6768 else {
6769 0 croak "Error: Cannot use undef/NULL as a table name";
6770 }
6771 }
6772  
6773 # Schema-qualified names:
6774 sub schemaname1($$$)
6775 122 ▶{
Subroutine schemaname1: called CC=2 SCAR=7.6
Pod undocumented
6776 122 my ($class,$xlat,$x)= @_;
6777 122 ▶ if (defined $x) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $x) { } 122 0 122
6778 122 return $class->obj(get_quote_id->($xlat->($x)));
6779 }
6780 else {
6781 0 croak "Error: Cannot use undef/NULL as a table name";
6782 }
6783 }
6784  
6785 sub schemaname2($$$$)
6786 2 ▶{
Subroutine schemaname2: called CC=5 SCAR=17.0
Pod undocumented
6787 2 my ($class,$xlat,$x,$y)= @_;
6788  
6789 2 ▶ if (ref($x)) { croak_no_ref($x); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) 1 1 2
6790 0 ▶ if (ref($y)) { croak_no_ref($y); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $y) 0 1 1
6791 1 ▶ croak "Error: Cannot use undef/NULL as an identifier"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $y 0 1 1
6792 unless defined $y;
6793  
6794 1 ▶ return $class->obj(
Branch: 1 branch
BranchTrueFalseTotal
defined $x ? : 1 0 1
6795 get_quote_id->(
6796 undef,
6797 (defined $x ? $xlat_schema->($x) : undef),
6798 $xlat->($y)));
6799 }
6800  
6801 sub schemaname3($$$$$)
6802 3 ▶{
Subroutine schemaname3: called CC=7 SCAR=23.8
Pod undocumented
6803 3 my ($class,$xlat,$x,$y,$z)= @_;
6804 0 ▶ if (ref($x)) { croak_no_ref($x); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) 0 3 3
6805 0 ▶ if (ref($y)) { croak_no_ref($y); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $y) 0 3 3
6806 0 ▶ if (ref($z)) { croak_no_ref($z); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $z) 0 3 3
6807 3 ▶ croak "Error: Cannot use undef/NULL as an identifier"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $z 0 3 3
6808 unless defined $z;
6809  
6810 3 ▶ return $class->obj(
Branch: 2 branches
BranchTrueFalseTotal
defined $x ? : 3 0 3
defined $y ? : 3 0 3
6811 get_quote_id->(
6812 (defined $x ? $xlat_catalog->($x) : undef),
6813 (defined $y ? $xlat_schema->($y) : undef),
6814 $xlat->($z)));
6815 }
6816  
6817  
6818 # Table:
6819 sub table1($)
6820 124 ▶{
Subroutine table1: called CC=2 SCAR=6.9
Pod undocumented
6821 124 my ($x)= @_;
6822 124 ▶ return ref($x) ? $x->table1 : schemaname1('SQL::Yapp::Table', $xlat_table, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 5 119 124
6823 }
6824  
6825 sub table2($$)
6826 2 ▶{
Subroutine table2: called CC=1 SCAR=0.0
Pod undocumented
6827 2 my ($x,$y)= @_;
6828 2 return schemaname2('SQL::Yapp::Table', $xlat_table, $x, $y);
6829 }
6830  
6831 sub table3($$$)
6832 3 ▶{
Subroutine table3: called CC=1 SCAR=0.0
Pod undocumented
6833 3 my ($x,$y,$z)= @_;
6834 3 return schemaname3('SQL::Yapp::Table', $xlat_table, $x, $y, $z);
6835 }
6836  
6837  
6838 # Index:
6839 sub index1($)
6840 0 ▶{
Subroutine index1: not called CC=2 SCAR=17.9
Pod undocumented
6841 0 my ($x)= @_;
6842 0 ▶ return ref($x) ? $x->index1 : schemaname1('SQL::Yapp::Index', $xlat_index, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6843 }
6844  
6845 sub index2($$)
6846 0 ▶{
Subroutine index2: not called CC=1 SCAR=6.9
Pod undocumented
6847 0 my ($x,$y)= @_;
6848 0 return schemaname2('SQL::Yapp::Index', $xlat_index, $x, $y);
6849 }
6850  
6851 sub index3($$$)
6852 0 ▶{
Subroutine index3: not called CC=1 SCAR=6.9
Pod undocumented
6853 0 my ($x,$y,$z)= @_;
6854 0 return schemaname3('SQL::Yapp::Index', $xlat_index, $x, $y, $z);
6855 }
6856  
6857  
6858 # CharSet:
6859 sub charset1($)
6860 2 ▶{
Subroutine charset1: called CC=2 SCAR=7.2
Pod undocumented
6861 2 my ($x)= @_;
6862 2 ▶ return ref($x) ? $x->charset1 : schemaname1('SQL::Yapp::CharSet', $xlat_charset, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 2 2
6863 }
6864  
6865 sub charset2($$)
6866 0 ▶{
Subroutine charset2: not called CC=1 SCAR=6.9
Pod undocumented
6867 0 my ($x,$y)= @_;
6868 0 return schemaname2('SQL::Yapp::CharSet', $xlat_charset, $x, $y);
6869 }
6870  
6871 sub charset3($$$)
6872 0 ▶{
Subroutine charset3: not called CC=1 SCAR=6.9
Pod undocumented
6873 0 my ($x,$y,$z)= @_;
6874 0 return schemaname3('SQL::Yapp::CharSet', $xlat_charset, $x, $y, $z);
6875 }
6876  
6877  
6878 # Collate:
6879 sub collate1($)
6880 0 ▶{
Subroutine collate1: not called CC=2 SCAR=17.9
Pod undocumented
6881 0 my ($x)= @_;
6882 0 ▶ return ref($x) ? $x->collate1 : schemaname1('SQL::Yapp::Collate', $xlat_collate, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6883 }
6884  
6885 sub collate2($$)
6886 0 ▶{
Subroutine collate2: not called CC=1 SCAR=6.9
Pod undocumented
6887 0 my ($x,$y)= @_;
6888 0 return schemaname2('SQL::Yapp::Collate', $xlat_collate, $x, $y);
6889 }
6890  
6891 sub collate3($$$)
6892 0 ▶{
Subroutine collate3: not called CC=1 SCAR=6.9
Pod undocumented
6893 0 my ($x,$y,$z)= @_;
6894 0 return schemaname3('SQL::Yapp::Collate', $xlat_collate, $x, $y, $z);
6895 }
6896  
6897  
6898 # Constraint:
6899 sub constraint1($)
6900 0 ▶{
Subroutine constraint1: not called CC=2 SCAR=17.9
Pod undocumented
6901 0 my ($x)= @_;
6902 0 ▶ return ref($x) ? $x->constraint1 : schemaname1('SQL::Yapp::Constraint', $xlat_constraint, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6903 }
6904  
6905 sub constraint2($$)
6906 0 ▶{
Subroutine constraint2: not called CC=1 SCAR=6.9
Pod undocumented
6907 0 my ($x,$y)= @_;
6908 0 return schemaname2('SQL::Yapp::Constraint', $xlat_constraint, $x, $y);
6909 }
6910  
6911 sub constraint3($$$)
6912 0 ▶{
Subroutine constraint3: not called CC=1 SCAR=6.9
Pod undocumented
6913 0 my ($x,$y,$z)= @_;
6914 0 return schemaname3('SQL::Yapp::Constraint', $xlat_constraint, $x, $y, $z);
6915 }
6916  
6917  
6918 # Transliteration:
6919 sub transliteration1($)
6920 0 ▶{
Subroutine transliteration1: not called CC=2 SCAR=17.9
Pod undocumented
6921 0 my ($x)= @_;
6922 0 ▶ return ref($x) ? $x->transliteration1 : schemaname1('SQL::Yapp::Transliteration', $xlat_transliteration, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6923 }
6924  
6925 sub transliteration2($$)
6926 0 ▶{
Subroutine transliteration2: not called CC=1 SCAR=6.9
Pod undocumented
6927 0 my ($x,$y)= @_;
6928 0 return schemaname2('SQL::Yapp::Transliteration', $xlat_transliteration, $x, $y);
6929 }
6930  
6931 sub transliteration3($$$)
6932 0 ▶{
Subroutine transliteration3: not called CC=1 SCAR=6.9
Pod undocumented
6933 0 my ($x,$y,$z)= @_;
6934 0 return schemaname3('SQL::Yapp::Transliteration', $xlat_transliteration, $x, $y, $z);
6935 }
6936  
6937  
6938 # Transcoding:
6939 sub transcoding1($)
6940 0 ▶{
Subroutine transcoding1: not called CC=2 SCAR=17.9
Pod undocumented
6941 0 my ($x)= @_;
6942 0 ▶ return ref($x) ? $x->transcoding1 : schemaname1('SQL::Yapp::Transcoding', $xlat_transcoding, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6943 }
6944  
6945 sub transcoding2($$)
6946 0 ▶{
Subroutine transcoding2: not called CC=1 SCAR=6.9
Pod undocumented
6947 0 my ($x,$y)= @_;
6948 0 return schemaname2('SQL::Yapp::Transcoding', $xlat_transcoding, $x, $y);
6949 }
6950  
6951 sub transcoding3($$$)
6952 0 ▶{
Subroutine transcoding3: not called CC=1 SCAR=6.9
Pod undocumented
6953 0 my ($x,$y,$z)= @_;
6954 0 return schemaname3('SQL::Yapp::Transcoding', $xlat_transcoding, $x, $y, $z);
6955 }
6956  
6957  
6958 # Engine:
6959 sub engine1($)
6960 1 ▶{
Subroutine engine1: called CC=2 SCAR=7.2
Pod undocumented
6961 1 my ($x)= @_;
6962 1 ▶ return ref($x) ? $x->engine1 : schemaname1('SQL::Yapp::Engine', $xlat_engine, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 1 1
6963 }
6964  
6965 sub engine2($$)
6966 0 ▶{
Subroutine engine2: not called CC=1 SCAR=6.9
Pod undocumented
6967 0 my ($x,$y)= @_;
6968 0 return schemaname2('SQL::Yapp::Engine', $xlat_engine, $x, $y);
6969 }
6970  
6971 sub engine3($$$)
6972 0 ▶{
Subroutine engine3: not called CC=1 SCAR=6.9
Pod undocumented
6973 0 my ($x,$y,$z)= @_;
6974 0 return schemaname3('SQL::Yapp::Engine', $xlat_engine, $x, $y, $z);
6975 }
6976  
6977  
6978 # Columns:
6979 sub colname($)
6980 10 ▶{
Subroutine colname: called CC=3 SCAR=13.3
Pod undocumented
6981 10 my ($x)= @_;
6982 10 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 0 10 10
elsif (defined $x) { } 10 0 10
6983 0 return $x->colname;
6984 }
6985 elsif (defined $x) {
6986 10 return SQL::Yapp::ColumnName->obj(get_quote_id->($xlat_column->($x)));
6987 }
6988 else {
6989 0 croak "Error: Cannot use undef/NULL as a column name";
6990 }
6991 }
6992  
6993 sub column1($)
6994 209 ▶{
Subroutine column1: called CC=3 SCAR=11.3
Pod undocumented
6995 209 my ($x)= @_;
6996 209 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 4 205 209
elsif (defined $x) { } 205 0 205
6997 4 return $x->column1;
6998 }
6999 elsif (defined $x) {
7000 205 return SQL::Yapp::Column->obj(get_quote_id->($xlat_column->($x)));
7001 }
7002 else {
7003 0 croak "Error: Cannot use undef/NULL as an identifier";
7004 }
7005 }
7006  
7007 sub column1_single($) #internal
7008 25 ▶{
Subroutine column1_single: called CC=3 SCAR=11.3
Pod undocumented
7009 25 my ($x)= @_;
7010 25 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 1 24 25
elsif (defined $x) { } 24 0 24
7011 1 return $x->column1_single;
7012 }
7013 elsif (defined $x) {
7014 24 return get_quote_id->($xlat_column->($x));
7015 }
7016 else {
7017 0 croak "Error: Cannot use undef/NULL as an identifier";
7018 }
7019 }
7020  
7021 sub column2($$)
7022 25 ▶{
Subroutine column2: called CC=1 SCAR=0.0
Pod undocumented
7023 25 my ($x,$y)= @_;
7024 25 return SQL::Yapp::Column->obj(table1($x).'.'.column1_single($y));
7025 }
7026  
7027 sub column3($$$)
7028 0 ▶{
Subroutine column3: not called CC=1 SCAR=6.9
Pod undocumented
7029 0 my ($x,$y,$z)= @_;
7030 0 return SQL::Yapp::Column->obj(table2($x,$y).'.'.column1_single($z));
7031 }
7032  
7033 sub column4($$$$)
7034 0 ▶{
Subroutine column4: not called CC=1 SCAR=6.9
Pod undocumented
7035 0 my ($w,$x,$y,$z)= @_;
7036 0 return SQL::Yapp::Column->obj(table3($w,$x,$y).'.'.column1_single($z));
7037 }
7038  
7039 # Generated with mkidentn.pl:
7040 0 ▶sub table1_n($) { map { table1 ($_ ) } @{ $_[0] } }
Subroutine table1_n: not called CC=1 SCAR=6.9
Pod undocumented
7041 0 ▶sub table2_1n($$) { map { table2 ($_[0], $_ ) } @{ $_[1] } }
Subroutine table2_1n: not called CC=1 SCAR=6.9
Pod undocumented
7042 0 ▶sub table2_n1($$) { map { table2 ($_ , $_[1]) } @{ $_[0] } }
Subroutine table2_n1: not called CC=1 SCAR=6.9
Pod undocumented
7043 0 ▶sub table2_nn($$) { map { table2_1n ($_ , $_[1]) } @{ $_[0] } }
Subroutine table2_nn: not called CC=1 SCAR=6.9
Pod undocumented
7044 0 ▶sub table3_11n($$$) { map { table3 ($_[0], $_[1], $_ ) } @{ $_[2] } }
Subroutine table3_11n: not called CC=1 SCAR=6.9
Pod undocumented
7045 0 ▶sub table3_1n1($$$) { map { table3 ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine table3_1n1: not called CC=1 SCAR=6.9
Pod undocumented
7046 0 ▶sub table3_1nn($$$) { map { table3_11n ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine table3_1nn: not called CC=1 SCAR=6.9
Pod undocumented
7047 0 ▶sub table3_n11($$$) { map { table3 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_n11: not called CC=1 SCAR=6.9
Pod undocumented
7048 0 ▶sub table3_n1n($$$) { map { table3_11n ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_n1n: not called CC=1 SCAR=6.9
Pod undocumented
7049 0 ▶sub table3_nn1($$$) { map { table3_1n1 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_nn1: not called CC=1 SCAR=6.9
Pod undocumented
7050 0 ▶sub table3_nnn($$$) { map { table3_1nn ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_nnn: not called CC=1 SCAR=6.9
Pod undocumented
7051  
7052 0 ▶sub column1_n($) { map { column1 ($_ ) } @{ $_[0] } }
Subroutine column1_n: not called CC=1 SCAR=6.9
Pod undocumented
7053 4 ▶sub column2_1n($$) { map { column2 ($_[0], $_ ) } @{ $_[1] } }
Subroutine column2_1n: called CC=1 SCAR=0.0
Pod undocumented
7054 0 ▶sub column2_n1($$) { map { column2 ($_ , $_[1]) } @{ $_[0] } }
Subroutine column2_n1: not called CC=1 SCAR=6.9
Pod undocumented
7055 2 ▶sub column2_nn($$) { map { column2_1n ($_ , $_[1]) } @{ $_[0] } }
Subroutine column2_nn: called CC=1 SCAR=0.0
Pod undocumented
7056 0 ▶sub column3_11n($$$) { map { column3 ($_[0], $_[1], $_ ) } @{ $_[2] } }
Subroutine column3_11n: not called CC=1 SCAR=6.9
Pod undocumented
7057 0 ▶sub column3_1n1($$$) { map { column3 ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine column3_1n1: not called CC=1 SCAR=6.9
Pod undocumented
7058 0 ▶sub column3_1nn($$$) { map { column3_11n ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine column3_1nn: not called CC=1 SCAR=6.9
Pod undocumented
7059 0 ▶sub column3_n11($$$) { map { column3 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_n11: not called CC=1 SCAR=6.9
Pod undocumented
7060 0 ▶sub column3_n1n($$$) { map { column3_11n ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_n1n: not called CC=1 SCAR=6.9
Pod undocumented
7061 0 ▶sub column3_nn1($$$) { map { column3_1n1 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_nn1: not called CC=1 SCAR=6.9
Pod undocumented
7062 0 ▶sub column3_nnn($$$) { map { column3_1nn ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_nnn: not called CC=1 SCAR=6.9
Pod undocumented
7063 0 ▶sub column4_111n($$$$) { map { column4 ($_[0], $_[1], $_[2], $_ ) } @{ $_[3] } }
Subroutine column4_111n: not called CC=1 SCAR=6.9
Pod undocumented
7064 0 ▶sub column4_11n1($$$$) { map { column4 ($_[0], $_[1], $_ , $_[3]) } @{ $_[2] } }
Subroutine column4_11n1: not called CC=1 SCAR=6.9
Pod undocumented
7065 0 ▶sub column4_11nn($$$$) { map { column4_111n ($_[0], $_[1], $_ , $_[3]) } @{ $_[2] } }
Subroutine column4_11nn: not called CC=1 SCAR=6.9
Pod undocumented
7066 0 ▶sub column4_1n11($$$$) { map { column4 ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1n11: not called CC=1 SCAR=6.9
Pod undocumented
7067 0 ▶sub column4_1n1n($$$$) { map { column4_111n ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1n1n: not called CC=1 SCAR=6.9
Pod undocumented
7068 0 ▶sub column4_1nn1($$$$) { map { column4_11n1 ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1nn1: not called CC=1 SCAR=6.9
Pod undocumented
7069 0 ▶sub column4_1nnn($$$$) { map { column4_11nn ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1nnn: not called CC=1 SCAR=6.9
Pod undocumented
7070 0 ▶sub column4_n111($$$$) { map { column4 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n111: not called CC=1 SCAR=6.9
Pod undocumented
7071 0 ▶sub column4_n11n($$$$) { map { column4_111n ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n11n: not called CC=1 SCAR=6.9
Pod undocumented
7072 0 ▶sub column4_n1n1($$$$) { map { column4_11n1 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n1n1: not called CC=1 SCAR=6.9
Pod undocumented
7073 0 ▶sub column4_n1nn($$$$) { map { column4_11nn ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n1nn: not called CC=1 SCAR=6.9
Pod undocumented
7074 0 ▶sub column4_nn11($$$$) { map { column4_1n11 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nn11: not called CC=1 SCAR=6.9
Pod undocumented
7075 0 ▶sub column4_nn1n($$$$) { map { column4_1n1n ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nn1n: not called CC=1 SCAR=6.9
Pod undocumented
7076 0 ▶sub column4_nnn1($$$$) { map { column4_1nn1 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nnn1: not called CC=1 SCAR=6.9
Pod undocumented
7077 0 ▶sub column4_nnnn($$$$) { map { column4_1nnn ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nnnn: not called CC=1 SCAR=6.9
Pod undocumented
7078  
7079 ####################
7080 # stmt interpolation:
7081  
7082 sub stmt($)
7083 3 ▶{
Subroutine stmt: called CC=2 SCAR=7.6
Pod undocumented
7084 3 my ($x)= @_;
7085 3 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 3 0 3
7086 3 return $x->stmt;
7087 }
7088 else {
7089 0 croak "Error: Expected 'Stmt' object, but found: ".my_dumper($x);
7090 }
7091 }
7092  
7093 sub subquery($)
7094 1 ▶{
Subroutine subquery: called CC=1 SCAR=0.0
Pod undocumented
7095 1 my ($x1)= @_;
7096 1 my $x= SQL::Yapp::Stmt->obj($x1);
7097 1 return $x->subquery;
7098 }
7099  
7100 ####################
7101 # expr interpolation:
7102  
7103 sub exprparen($)
7104 70 ▶{
Subroutine exprparen: called CC=6 SCAR=18.6
Pod undocumented
7105 70 my ($x)= @_;
7106 70 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 5 65 70
7107 5 ▶ die Dumper($x) if ref($x) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "HASH" 0 5 5
7108 5 ▶ die Dumper($x) if ref($x) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "ARRAY" 0 5 5
7109 5 ▶ die Dumper($x) if ref($x) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "CODE" 0 5 5
7110 5 ▶ die Dumper($x) if ref($x) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "SCALAR" 0 5 5
7111 5 return $x->exprparen;
7112 }
7113 else {
7114 65 return SQL::Yapp::Expr->obj(get_quote_val->($x)); # raw perl scalar: quote as value, no parens
7115 }
7116 }
7117  
7118 sub expr($)
7119 153 ▶{
Subroutine expr: called CC=3 SCAR=11.0
Pod undocumented
7120 153 my ($x)= @_;
7121 153 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 21 132 153
7122 21 ▶ confess 'Error: Trying to invoke $x->expr() on unblessed reference $x ".
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($x) 0 21 21
7123 "(maybe missing nested sqlExpr{...} inside a block, or ".
7124 "additional () around {} interpolation?)'
7125 unless blessed($x);
7126 21 return $x->expr;
7127 }
7128 else {
7129 132 return SQL::Yapp::Expr->obj(get_quote_val->($x)); # raw perl scalar: quote as value
7130 }
7131 }
7132  
7133 sub expr_or_check($)
7134 5 ▶{
Subroutine expr_or_check: called CC=2 SCAR=6.9
Pod undocumented
7135 5 my ($x)= @_;
7136 5 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 3 2 5
7137 3 return $x->expr_or_check;
7138 }
7139 else {
7140 2 return SQL::Yapp::Expr->obj(get_quote_val->($x)); # raw perl scalar: quote as value
7141 }
7142 }
7143  
7144 sub exprparen_hash(\%)
7145 3 ▶{
Subroutine exprparen_hash: called CC=3 SCAR=11.0
Pod undocumented
7146 3 my ($x)= @_;
7147 return map {
7148 3 my $n= $_;
7149 6 my $e= $x->{$n};
7150 6 ▶ (blessed($e) && $e->isa('SQL::Yapp::Check') ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($e) && $e->isa('SQL::Yapp::Check') ? : 3 3 6
Condition66%2/3
builtin::blessed($e) and $e->isa("SQL::Yapp::Check")
!ll&&!rl&&r
303
MC/DC50%1/2
builtin::blessed($e) and $e->isa("SQL::Yapp::Check")
builtin::blessed($e) $e->isa("SQL::Yapp::Check")
Truth table66%2/3
A and B
A= builtin::blessed($e)B= $e->isa("SQL::Yapp::Check")
ABresult
0X0
100
111
7151 '('.get_quote_id->($n).' '.$e->check.')'
7152 : '('.get_quote_id->($n).' = '.exprparen($e).')'
7153 )
7154 }
7155 sort keys %$x;
7156 }
7157  
7158 sub expr_hash(\%)
7159 4 ▶{
Subroutine expr_hash: called CC=3 SCAR=11.8
Pod undocumented
7160 4 my ($x)= @_;
7161 return map {
7162 4 my $n= $_;
7163 7 my $e= $x->{$n};
7164 7 ▶ (blessed($e) && $e->isa('SQL::Yapp::Check') ?
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($e) && $e->isa('SQL::Yapp::Check') ? : 0 7 7
Condition33%1/3
builtin::blessed($e) and $e->isa("SQL::Yapp::Check")
!ll&&!rl&&r
700
MC/DC0%0/2
builtin::blessed($e) and $e->isa("SQL::Yapp::Check")
builtin::blessed($e) $e->isa("SQL::Yapp::Check")
Truth table33%1/3
A and B
A= builtin::blessed($e)B= $e->isa("SQL::Yapp::Check")
ABresult
0X0
100
111
7165 '('.get_quote_id->($n).' '.$e->check.')'
7166 : SQL::Yapp::Infix->obj('=', get_quote_id->($n), exprparen($e))
7167 )
7168 }
7169 sort keys %$x;
7170 }
7171  
7172 ####################
7173 # order interpolation:
7174  
7175 sub asc($)
7176 9 ▶{
Subroutine asc: called CC=3 SCAR=11.3
Pod undocumented
7177 9 my ($x)= @_;
7178 9 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 4 5 9
elsif (defined $x) { } 5 0 5
7179 4 return $x->asc;
7180 }
7181 elsif (defined $x) {
7182 5 return column1($x);
7183 }
7184 else {
7185 0 return NULL;
7186 }
7187 }
7188  
7189 sub desc($)
7190 10 ▶{
Subroutine desc: called CC=3 SCAR=11.3
Pod undocumented
7191 10 my ($x)= @_;
7192 10 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 6 4 10
elsif (defined $x) { } 4 0 4
7193 6 return $x->desc;
7194 }
7195 elsif (defined $x) {
7196 4 return SQL::Yapp::Desc->obj(column1($x));
7197 }
7198 else {
7199 0 return NULL;
7200 }
7201 }
7202  
7203 ####################
7204 # table option:
7205  
7206 sub tableopt($)
7207 2 ▶{
Subroutine tableopt: called CC=2 SCAR=7.6
Pod undocumented
7208 2 my ($x)= @_;
7209 2 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 2 0 2
7210 2 return $x->tableopt;
7211 }
7212 else {
7213 0 croak "Error: Expected 'TableOption' object, but found: ".my_dumper($x);
7214 }
7215 }
7216  
7217 ####################
7218 # join interpolation:
7219  
7220 sub joinclause($)
7221 4 ▶{
Subroutine joinclause: called CC=2 SCAR=7.6
Pod undocumented
7222 4 my ($x)= @_;
7223 4 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 4 0 4
7224 4 return $x->joinclause;
7225 }
7226 else {
7227 0 croak "Error: Expected 'Join' object, but found: ".my_dumper($x);
7228 }
7229 }
7230  
7231 ####################
7232 # limit interpolation:
7233  
7234 sub limit_number($)
7235 14 ▶{
Subroutine limit_number: called CC=3 SCAR=13.3
Pod undocumented
7236 14 my ($x)= @_;
7237 14 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 0 14 14
elsif (&looks_like_number($x)) { } 14 0 14
7238 0 return $x->limit_number;
7239 }
7240 elsif (looks_like_number $x) {
7241 14 return $x;
7242 }
7243 else {
7244 0 croak "Error: Expected number or ?, but found: ".my_dumper($x);
7245 }
7246 }
7247  
7248 sub limit($$)
7249 2 ▶{
Subroutine limit: called CC=5 SCAR=17.6
Pod undocumented
7250 2 my ($cnt, $offset)= @_;
7251  
7252 # FIXME: if dialect is 'std' (or maybe 'std2008'), produce OFFSET/FETCH
7253 # clause (SQL-2008).
7254 2 ▶ if (defined $cnt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cnt) { } 1 1 2
7255 1 ▶ if (defined $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) { } 1 0 1
7256 1 return " LIMIT ".limit_number($cnt)." OFFSET ".limit_number($offset);
7257 }
7258 else {
7259 0 return " LIMIT ".limit_number($cnt);
7260 }
7261 }
7262 else {
7263 1 ▶ if (defined $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) { } 1 0 1
7264 1 ▶ if ($write_dialect eq 'postgresql') {
Branch: 1 branch
BranchTrueFalseTotal
if ($write_dialect eq 'postgresql') { } 0 1 1
7265 0 return " LIMIT ALL OFFSET ".limit_number($offset);
7266 }
7267 else {
7268 1 return " LIMIT ${\LARGE_LIMIT_CNT} OFFSET ".limit_number($offset);
7269 }
7270 }
7271 else {
7272 0 return '';
7273 }
7274 }
7275 }
7276  
7277 ####################
7278 # case:
7279  
7280 sub whenthen($$)
7281 6 ▶{
Subroutine whenthen: called CC=1 SCAR=0.0
Pod undocumented
7282 6 my ($expr, $then)= @_;
7283 6 return 'WHEN '.$expr.' THEN '.$then;
7284 }
7285  
7286 sub caseswitch($$@)
7287 8 ▶{
Subroutine caseswitch: called CC=2 SCAR=6.9
Pod undocumented
7288 #my ($switchval, $default, @whenthen)
7289 8 ▶ if (scalar(@_) == 2) { # @whenthen is empty => always use default
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 2) 2 6 8
7290 2 return $_[1]; # return default
7291 }
7292 return
7293 6 join(' ',
7294 'CASE',
7295 $_[0],
7296 @_[2..$#_], # @whenthen
7297 'ELSE', # always generate default, it's easier.
7298 $_[1],
7299 'END'
7300 );
7301 }
7302  
7303 sub casecond($@)
7304 0 ▶{
Subroutine casecond: not called CC=2 SCAR=17.9
Pod undocumented
7305 #my ($default, @whenthen)
7306 0 ▶ if (scalar(@_) == 1) { # @whenthen is empty => always use default
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) 0 0 0
7307 0 return $_[0]; # return default
7308 }
7309 return
7310 0 join(' ',
7311 'CASE',
7312 @_[1..$#_], # @whenthen
7313 'ELSE', # always generate default, it's easier.
7314 $_[0],
7315 'END'
7316 );
7317 }
7318  
7319 5 1;
7320  
7321 ######################################################################
7322 ######################################################################
7323 ######################################################################
7324  
7325 __END__
↑ Summary