blib/lib/SQL/Yapp.pm

filter: Statementstmt 78.8% 2422 / 3071 Branchbran 62.5% 719 / 1150 Conditioncond 50.8% 158 / 311 MC/DCmcdc 22.6% 41 / 181 Subroutinesub 71.8% 585 / 814 Podpod 0.0% 0 / 298 totaltotal 67.3% 3925 / 5825 SCAR 93.0
CC
713
Cov
73%
shift_or_reduce_pure
94.5
value
33.0
__ANON__
30.0
CRAP 10950.6
↑ 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.000;
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 {
321 20 ▶ my $var= shift;
Subroutine get_set: called CC=2 SCAR=7.0
Pod undocumented
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 {
329 0 ▶ return $get_dbh->();
Subroutine get_dbh: not called CC=1 SCAR=6.9
Pod undocumented
330 }
331  
332 sub dbh(;&)
333 {
334 1 ▶ get_set (\$get_dbh, @_);
Subroutine dbh: called CC=2 SCAR=9.2
Pod undocumented
335 1 ▶ if ($get_dbh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($get_dbh) { } 1 0 1
336 1 ▶ $quote_id_default= sub(@) { $get_dbh->()->quote_identifier(@_); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
337 1 ▶ $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 {
374 0 ▶ my ($s)= @_;
Subroutine read_dialect1: not called CC=4 SCAR=30.0
Pod undocumented
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 {
388 0 ▶ my ($s)= @_;
Subroutine read_dialect: not called CC=4 SCAR=30.0
Pod undocumented
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 {
405 9 ▶ my ($s)= @_;
Subroutine write_dialect: called CC=2 SCAR=7.1
Pod undocumented
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 {
412 0 ▶ my ($s)= @_;
Subroutine dialect: not called CC=1 SCAR=6.9
Pod undocumented
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 {
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'
Subroutine type_spec: called CC=4 SCAR=16.6
Pod undocumented
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 {
628 5 ▶ my ($pack, @opt)= @_;
Subroutine import: called CC=9 SCAR=25.9
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 {
677 1 ▶ my ($x)= @_;
Subroutine my_dumper: called CC=2 SCAR=7.1
Pod undocumented
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 {
696 3 ▶ my $i= 2;
Subroutine my_longmess: called CC=2 SCAR=6.9
Pod undocumented
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 {
707 3 ▶ die my_longmess.'DIED: '.($_[0] || 'Error');
Subroutine my_confess: called CC=2 SCAR=7.6
Pod undocumented
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 {
715 return
716 $quote_val ||
717 $quote_val_default ||
718 205 ▶ do {
Subroutine get_quote_val: called CC=3 SCAR=16.5
Pod undocumented
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 {
726 return
727 $quote_id ||
728 $quote_id_default ||
729 379 ▶ do {
Subroutine get_quote_id: called CC=3 SCAR=16.5
Pod undocumented
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 {
766 454 ▶ my ($value, $type, %opt)= @_;
Subroutine make_op: called CC=6 SCAR=18.2
Pod undocumented
767 454 ▶ my $read_value= $opt{read_value} || $value;
Condition66%2/3
$opt{'read_value'} || $value
l!l&&r!l&&!r
154390
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 454 ▶ my $read_type= $opt{read_type} || $type;
Condition66%2/3
$opt{'read_type'} || $type
l!l&&r!l&&!r
354190
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 454 ▶ };
Condition83%5/6
$opt{'rhs'} || 'expr'
l!l
70384
$opt{'rhs_map'} || {}
l!l
0454
$opt{'dialect'} || {}
l!l
60394
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 454 lock_hash %$result;
787 454 return $result;
788 }
789  
790 sub declare_op($$;%)
791 {
792 380 ▶ my ($value, $type, %opt)= @_;
Subroutine declare_op: called CC=1 SCAR=0.0
Pod undocumented
793 380 my $result= make_op($value, $type, %opt);
794 380 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('DEFAULT', 'funcall', accept => [ 'mysql' ], read_type => 'funcall1col'),
1079 # Special functor because it collides with DEFAULT pseudo
1080 # constant, so it needs extra care during parsing.
1081 );
1082  
1083 # Reserved words from SQL-2003 spec:
1084 5 my @reserved= qw(
1085 ADD ALL ALLOCATE ALTER AND ANY ARE ARRAY AS ASENSITIVE ASYMMETRIC
1086 AT ATOMIC AUTHORIZATION BEGIN BETWEEN BIGINT BINARY BLOB BOOLEAN
1087 BOTH BY CALL CALLED CASCADED CASE CAST CHAR CHARACTER CHECK CLOB
1088 CLOSE COLLATE COLUMN COMMIT CONNECT CONSTRAINT CONTINUE
1089 CORRESPONDING CREATE CROSS CUBE CURRENT CURRENT_DATE
1090 CURRENT_DEFAULT_TRANSFORM_GROUP CURRENT_PATH CURRENT_ROLE
1091 CURRENT_TIME CURRENT_TIMESTAMP CURRENT_TRANSFORM_GROUP_FOR_TYPE
1092 CURRENT_USER CURSOR CYCLE DATE DAY DEALLOCATE DEC DECIMAL DECLARE
1093 DEFAULT DELETE DEREF DESCRIBE DETERMINISTIC DISCONNECT DISTINCT
1094 DOUBLE DROP DYNAMIC EACH ELEMENT ELSE END END-EXEC ESCAPE EXCEPT
1095 EXEC EXECUTE EXISTS EXTERNAL FALSE FETCH FILTER FLOAT FOR FOREIGN
1096 FREE FROM FULL FUNCTION GET GLOBAL GRANT GROUP GROUPING HAVING
1097 HOLD HOUR IDENTITY IMMEDIATE IN INDICATOR INNER INOUT INPUT
1098 INSENSITIVE INSERT INT INTEGER INTERSECT INTERVAL INTO IS
1099 ISOLATION JOIN LANGUAGE LARGE LATERAL LEADING LEFT LIKE LOCAL
1100 LOCALTIME LOCALTIMESTAMP MATCH MEMBER MERGE METHOD MINUTE MODIFIES
1101 MODULE MONTH MULTISET NATIONAL NATURAL NCHAR NCLOB NEW NO NONE NOT
1102 NULL NUMERIC OF OLD ON ONLY OPEN OR ORDER OUT OUTER OUTPUT OVER
1103 OVERLAPS PARAMETER PARTITION PRECISION PREPARE PRIMARY PROCEDURE
1104 RANGE READS REAL RECURSIVE REF REFERENCES REFERENCING RELEASE
1105 RETURN RETURNS REVOKE RIGHT ROLLBACK ROLLUP ROW ROWS SAVEPOINT
1106 SCROLL SEARCH SECOND SELECT SENSITIVE SESSION_USER SET SIMILAR
1107 SMALLINT SOME SPECIFIC SPECIFICTYPE SQL SQLEXCEPTION SQLSTATE
1108 SQLWARNING START STATIC SUBMULTISET SYMMETRIC SYSTEM SYSTEM_USER
1109 TABLE THEN TIME TIMESTAMP TIMEZONE_HOUR TIMEZONE_MINUTE TO
1110 TRAILING TRANSLATION TREAT TRIGGER TRUE UNION UNIQUE UNKNOWN
1111 UNNEST UPDATE USER USING VALUE VALUES VARCHAR VARYING WHEN
1112 WHENEVER WHERE WINDOW WITH WITHIN WITHOUT YEAR
1113 );
1114 5 my %reserved= ( map { $_ => 1 } @reserved );
1115  
1116 sub double_quote_perl($)
1117 {
1118 0 ▶ my ($s)= @_;
Subroutine double_quote_perl: not called CC=1 SCAR=6.9
Pod undocumented
1119 0 $s =~ s/([\\\"\$\@])/\\$1/g;
1120 0 $s =~ s/\t/\\t/g;
1121 0 $s =~ s/\n/\\n/g;
1122 0 $s =~ s/\r/\\r/g;
1123 0 $s =~ s/([\x00-\x1f\x7f])/sprintf("\\x%02x", ord($1))/gsex;
1124 0 return "\"$s\"";
1125 }
1126  
1127 sub single_quote_perl($)
1128 {
1129 2824 ▶ my ($s)= @_;
Subroutine single_quote_perl: called CC=1 SCAR=0.0
Pod undocumented
1130 2824 $s =~ s/([\\\'])/\\$1/g;
1131 2824 return "'$s'";
1132 }
1133  
1134 sub quote_perl($)
1135 {
1136 3185 ▶ my ($s)= @_;
Subroutine quote_perl: called CC=3 SCAR=11.1
Pod undocumented
1137 3185 ▶ return 'undef' unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 361 2824 3185
1138 2824 ▶ return ($s =~ /[\x00-\x1f\x7f\']/) ? double_quote_perl($s) : single_quote_perl($s);
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /[\x00-\x1f\x7f\']/ ? : 0 2824 2824
1139 }
1140  
1141 sub skip_ws($)
1142 {
1143 3517 ▶ my ($lx)= @_;
Subroutine skip_ws: called CC=4 SCAR=13.9
Pod undocumented
1144 3517 my $s= $lx->{text_p};
1145  
1146 3517 for(;;) {
1147 6215 ▶ if ($$s =~ /\G\n/gc) { # count lines
Branch: 1 branch
BranchTrueFalseTotal
if ($$s =~ /\G\n/cg) 427 5788 6215
1148 427 $lx->{line}++;
1149 427 next;
1150 }
1151 5788 ▶ next if $$s =~ /\G[^\n\S]+/gc; # other space but newline
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G[^\n\S]+/cg 2252 3536 5788
1152 3536 ▶ next if $$s =~ /\G\#[^\n]*/gc; # comments
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G\#[^\n]*/cg 19 3517 3536
1153 3517 last;
1154 }
1155 }
1156  
1157 sub token_new($$;$%)
1158 {
1159 3182 ▶ my ($lx, $kind, $value, %opt)= @_;
Subroutine token_new: called CC=2 SCAR=7.0
Pod undocumented
1160 3182 ▶ my_confess unless $kind;
Branch: 1 branch
BranchTrueFalseTotal
unless $kind 0 3182 3182
1161 my $t= {
1162 lx => $lx,
1163 line => $lx->{line_before}, # start of token: rel. line num. in $lx->{text_p}
1164 line_after => $lx->{line},
1165 pos => $lx->{pos_before}, # start of token: string position in $lx->{text_p}
1166 3182 pos_after => pos(${ $lx->{text_p} }), # end of token: string position in $lx->{text_p}
1167 kind => $kind,
1168 value => $value,
1169 str => $opt{str},
1170 type => $opt{type}, # interproc: 'variable', 'block', 'num', etc.
1171 perltype => $opt{perltype}, # interproc: 'array', 'scalar', 'hash', 'list'
1172 prec => $opt{prec},
1173 error => $opt{error},
1174 3182 };
1175 3182 lock_keys %$t;
1176 3182 return $t;
1177 }
1178  
1179 sub token_describe($)
1180 {
1181 1 ▶ my ($t)= @_;
Subroutine token_describe: called CC=6 SCAR=18.0
Pod undocumented
1182  
1183 1 my %opt= ();
1184 1 for my $key(qw(value str prec)) {
1185 3 ▶ if (defined $t->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t->{$key}) 1 2 3
1186 1 $opt{$key}= $t->{$key};
1187 }
1188 }
1189 1 for my $key(qw(perltype type)) {
1190 2 ▶ if ($t->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{$key}) 1 1 2
1191 1 $opt{$key}= $t->{$key};
1192 }
1193 }
1194  
1195 1 ▶ if (scalar(keys %opt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %opt) { } 1 0 1
1196 return "$t->{kind} (".
1197 join(", ",
1198 map {
1199 1 my $k= $_;
1200 2 "$k=".quote_perl($opt{$k})
1201 }
1202 sort keys %opt
1203 ).
1204 ")";
1205 }
1206 else {
1207 0 return quote_perl($t->{kind});
1208 }
1209 }
1210  
1211 sub error_new($$$)
1212 {
1213 1 ▶ my ($lx, $value, $expl)= @_;
Subroutine error_new: called CC=1 SCAR=0.0
Pod undocumented
1214 1 return token_new ($lx, 'error', $value, str => $expl, error => 1);
1215 }
1216  
1217 sub syn_new($$$)
1218 {
1219 2135 ▶ my ($lx, $type, $name)= @_;
Subroutine syn_new: called CC=1 SCAR=0.0
Pod undocumented
1220 2135 return token_new ($lx, $name, undef, perltype => '', type => $type);
1221 # perltype and type are for * and ?, which can occur as
1222 # syntactic values in expressions.
1223 }
1224  
1225 sub interpol_new($$$$$)
1226 {
1227 517 ▶ my ($lx, $interpol, $value, $type, $perltype)= @_;
Subroutine interpol_new: called CC=1 SCAR=0.0
Pod undocumented
1228 517 return token_new ($lx, "interpol$interpol", $value,
1229 type => $type,
1230 perltype => $perltype
1231 );
1232 }
1233  
1234 sub token_scan_codeblock($$)
1235 {
1236 62 ▶ my ($lx, $interpol)= @_;
Subroutine token_scan_codeblock: called CC=2 SCAR=7.0
Pod undocumented
1237 62 my $s= $lx->{text_p};
1238  
1239 # Text::Balanced actually honours and updates pos($$s), so we can
1240 # interface directly:
1241 62 my ($ex)= Text::Balanced::extract_codeblock($$s, '{}()[]');
1242 return error_new($lx, 'codeblock', $@->{error})
1243 62 ▶ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 62 62
1244  
1245 62 $lx->{line}+= ($ex =~ tr/\n//);
1246 62 return interpol_new ($lx, $interpol, "do$ex", 'block', 'list');
1247 # $ex contains {}, so do$ex is sound.
1248 }
1249  
1250 sub token_scan_variable($$$)
1251 {
1252 170 ▶ my ($lx, $interpol, $perltype)= @_;
Subroutine token_scan_variable: called CC=2 SCAR=7.0
Pod undocumented
1253 170 my $s= $lx->{text_p};
1254  
1255 170 my ($ex)= Text::Balanced::extract_variable($$s);
1256 return error_new($lx, 'variable', $@->{error})
1257 170 ▶ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 170 170
1258  
1259 170 $lx->{line}+= ($ex =~ tr/\n//);
1260 170 return interpol_new ($lx, $interpol, $ex, 'variable', $perltype);
1261 }
1262  
1263 sub token_scan_delimited($$$)
1264 {
1265 50 ▶ my ($lx, $interpol, $delim)= @_;
Subroutine token_scan_delimited: called CC=2 SCAR=7.0
Pod undocumented
1266 50 my $s= $lx->{text_p};
1267  
1268 50 my ($ex)= Text::Balanced::extract_delimited($$s, $delim);
1269 return error_new($lx, 'delimited', $@->{error})
1270 50 ▶ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 50 50
1271  
1272 50 $lx->{line}+= ($ex =~ tr/\n//);
1273 50 return interpol_new ($lx, $interpol, $ex, 'string', 'scalar');
1274 }
1275  
1276 sub token_num_new($$$)
1277 {
1278 235 ▶ my ($lx, $interpol, $value)= @_;
Subroutine token_num_new: called CC=2 SCAR=7.2
Pod undocumented
1279 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
1280 }
1281  
1282 sub ident_new($$)
1283 {
1284 529 ▶ my ($lx, $value)= @_;
Subroutine ident_new: called CC=1 SCAR=0.0
Pod undocumented
1285 529 return token_new ($lx, 'ident', $value, perltype => 'scalar');
1286 }
1287  
1288 sub keyword_new($$) # either syn or function
1289 {
1290 737 ▶ my ($lx, $name)= @_;
Subroutine keyword_new: called CC=2 SCAR=6.9
Pod undocumented
1291 737 ▶ if ($reserved{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reserved{$name}) { } 666 71 737
1292 666 return syn_new($lx, 'reserved', $name);
1293 }
1294 else {
1295 71 return syn_new($lx, 'keyword', $name);
1296 }
1297 }
1298  
1299 sub replace_synonym($)
1300 {
1301 1251 ▶ my ($name)= @_;
Subroutine replace_synonym: called CC=2 SCAR=6.9
Pod undocumented
1302 1251 ▶ while (my $syn= $synonym{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $syn = $synonym{$name}) 7 1251 1258
1303 7 $name= $syn;
1304 }
1305 1251 return $name;
1306 }
1307  
1308 sub multi_token_new($$)
1309 {
1310 909 ▶ my ($lx, $name)= @_;
Subroutine multi_token_new: called CC=4 SCAR=13.9
Pod undocumented
1311 909 my $s= $lx->{text_p};
1312  
1313 909 $name= replace_synonym($name);
1314 909 ▶ if (my $tree= $multi_token{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tree = $multi_token{$name}) { } 172 737 909
1315 172 SUB_TOKEN: for (;;) {
1316 327 skip_ws($lx);
1317  
1318 327 my $p= pos($$s);
1319 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
1320 187 my $sub_name= $1;
1321  
1322 187 $sub_name= replace_synonym($sub_name);
1323 187 $tree= $tree->{$sub_name};
1324 187 ▶ unless ($tree) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tree) 32 155 187
1325 32 pos($$s)= $p; # unscan rejected keyword
1326 32 last SUB_TOKEN;
1327 }
1328  
1329 155 $name.= " $sub_name";
1330 155 $name= replace_synonym($name);
1331 }
1332 172 return syn_new ($lx, 'keyword', $name); # never a function, always a keyword
1333 }
1334 else {
1335 737 return keyword_new ($lx, $name);
1336 }
1337 }
1338  
1339 sub good_interpol_type($);
1340  
1341 sub token_scan_rec($$);
1342 sub token_scan_rec($$)
1343 {
1344 3190 ▶ my ($lx, $interpol)= @_;
Subroutine token_scan_rec: called CC=24 SCAR=32.1
Pod undocumented
1345 3190 my $s= $lx->{text_p};
1346  
1347 3190 skip_ws($lx);
1348  
1349 3190 $lx->{pos_before}= pos($$s);
1350 3190 $lx->{line_before}= $lx->{line}; # strings may contain \n, so this may change.
1351  
1352 # idents: distinguished by case:
1353 3190 ▶ 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 909 2281 3190
1354 2281 ▶ 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 529 1752 2281
1355 1752 ▶ return ident_new ($lx, $1) if $$s =~ /\G \`([^\n\\\`]+)\` /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G \`([^\n\\\`]+)\` /cgsx 0 1752 1752
1356  
1357 1752 ▶ 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 1744 1752
1358 # type specifiers change the token context itself, so we recurse here.
1359 8 my $interpol_new= $1;
1360 8 ▶ return error_new ($lx, $interpol_new, 'unknown type cast')
Branch: 1 branch
BranchTrueFalseTotal
unless &good_interpol_type($interpol_new) 0 8 8
1361 unless good_interpol_type($interpol_new);
1362  
1363 8 ▶ return error_new ($lx, $interpol_new, 'duplicate type case')
Branch: 1 branch
BranchTrueFalseTotal
if $interpol 0 8 8
1364 if $interpol;
1365  
1366 8 my $tok= token_scan_rec ($lx, $interpol_new);
1367 8 ▶ return $tok if $tok->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $tok->{"error"} 0 8 8
1368  
1369 return error_new ($lx, $tok->{kind},
1370 "Expected Perl interpolation after type cast to '$interpol_new'")
1371 8 ▶ unless $tok->{kind} =~ /^interpol/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tok->{"kind"} =~ /^interpol/ 0 8 8
1372  
1373 8 return $tok;
1374 }
1375  
1376 1744 ▶ 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 1744 1744
1377 if $$s =~ /\G ([A-Za-z_][A-Za-z_0-9]*) /gcsx;
1378  
1379 # Numbers, strings, and embedded Perl code are handled alike: they will be
1380 # extracted as is and evaluated as is. This way, much of the embedded SQL
1381 # syntax is just like in Perl, and you don't face surprises. The uniform
1382 # kind of this token is 'interpol'. The precise type is stored in the
1383 # str attribute, in case anyone wants to know later.
1384  
1385 # numbers:
1386 ## ints:
1387 1744 ▶ 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 1743 1744
1388 1743 ▶ 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 1742 1743
1389 1742 ▶ 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 1526 1742
1390 1526 ▶ 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 1509 1526
1391 # Note: oct() interprets 0b as binary, and there's not bin().
1392  
1393 1509 ▶ 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 1509 1509
1394 # special case for <large object length token>, which we split in two.
1395  
1396 ## floats:
1397 1509 ▶ 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 1509 1509
1398 if $$s =~ /\G( (?= [1-9] # not empty, but numeric
1399 | [.][0-9]
1400 )
1401 (?: [1-9] [0-9_]* )?
1402 (?: [.] [0-9_]+ )?
1403 (?: e[-+] [0-9_]+ )?\b )/gcsix;
1404  
1405 1509 ▶ return error_new ($lx, $1, 'not a number')
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G ([0-9][a-z_0-9]*) /cgisx 0 1509 1509
1406 if $$s =~ /\G ([0-9][a-z_0-9]*) /gcsix;
1407  
1408 # embedded Perl:
1409 1509 ▶ return token_scan_variable ($lx, $interpol, 'scalar') if $$s =~ /\G (?= \$\S ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \$\S ) /cgsx 71 1438 1509
1410 1438 ▶ return token_scan_variable ($lx, $interpol, 'array') if $$s =~ /\G (?= \@\S ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \@\S ) /cgsx 71 1367 1438
1411 1367 ▶ return token_scan_variable ($lx, $interpol, 'hash') if $$s =~ /\G (?= \%[^\s\d] ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \%[^\s\d] ) /cgsx 28 1339 1367
1412 1339 ▶ return token_scan_codeblock ($lx, $interpol) if $$s =~ /\G (?= \{ ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= \{ ) /cgsx 62 1277 1339
1413 1277 ▶ return token_scan_delimited ($lx, $interpol, $1) if $$s =~ /\G (?= [\'\"] ) /gcsx;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G (?= [\'\"] ) /cgsx 50 1227 1277
1414  
1415 # symbols:
1416 1227 ▶ return syn_new ($lx, 'symbol', $1)
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ m(\G( == | != | <= | >= | \&\& | \|\| | \! | \^\^ | \*\* | \^ | [-+*/;:,.()\[\]{}<=>?\%\&\|] ))cgsx 1186 41 1227
1417 if $$s =~ /\G(
1418 == | != | <= | >=
1419 | \&\& | \|\| | \! | \^\^
1420 | \*\* | \^
1421 | [-+*\/;:,.()\[\]{}<=>?\%\&\|]
1422 )/gcsx;
1423  
1424 # specials:
1425 41 ▶ return error_new ($lx, $1, 'Unexpected character') if $$s =~ /\G(.)/gcs;
Branch: 1 branch
BranchTrueFalseTotal
if $$s =~ /\G(.)/cgs 1 40 41
1426 40 return syn_new ($lx, 'special', '<EOF>');
1427 }
1428  
1429 sub token_scan($)
1430 {
1431 3182 ▶ my ($lx)= @_;
Subroutine token_scan: called CC=1 SCAR=0.0
Pod undocumented
1432 3182 my $t= token_scan_rec($lx, '');
1433 #print STDERR "DEBUG: scanned: ".token_describe($t)."\n";
1434 3182 return $t;
1435 }
1436  
1437 sub lexer_shift($)
1438 # returns the old token kind
1439 {
1440 3182 ▶ my ($lx)= @_;
Subroutine lexer_shift: called CC=1 SCAR=0.0
Pod undocumented
1441 3182 my $r= $lx->{token}{kind};
1442 3182 $lx->{token}= token_scan($lx);
1443 3182 return $r;
1444 }
1445  
1446 sub lexer_new($$$)
1447 {
1448 280 ▶ my ($s, $file, $line_start)= \(@_);
Subroutine lexer_new: called CC=1 SCAR=0.0
Pod undocumented
1449 280 my $lx= {
1450 text_p => $s,
1451 token => undef,
1452 file => $$file,
1453 line_start => $$line_start, # relative start line of text in file
1454 line => 1, # current line (after current token)
1455 prev_line => 1, # end line of previous token (before white space)
1456 line_before => 1, # start line of current token (after white space)
1457 pos_before => 0, # pos($$s) at start of current token
1458 error => undef,
1459 };
1460 280 lock_keys %$lx;
1461 280 lexer_shift($lx);
1462 280 return $lx;
1463 }
1464  
1465 sub flatten($);
1466 sub flatten($)
1467 {
1468 11771 ▶ my ($x)= @_;
Subroutine flatten: called CC=4 SCAR=16.4
Pod undocumented
1469 11771 ▶ return $x
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x 10897 874 11771
1470 unless ref($x);
1471  
1472 874 ▶ return map { flatten($_) } @$x
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "ARRAY" 874 0 874
1473 if ref($x) eq 'ARRAY';
1474  
1475 0 ▶ return flatten([ sort keys %$x ])
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "HASH" 0 0 0
1476 if ref($x) eq 'HASH';
1477  
1478 0 my_confess "No idea how to flatten $x";
1479 }
1480  
1481 sub flatten_hash($);
1482 sub flatten_hash($)
1483 {
1484 8106 ▶ my ($x)= @_;
Subroutine flatten_hash: called CC=1 SCAR=0.0
Pod undocumented
1485 8106 return map {$_ => 1} flatten $x;
1486 }
1487  
1488 sub looking_at_raw($$)
1489 {
1490 9214 ▶ my ($lx, $kind)= @_;
Subroutine looking_at_raw: called CC=3 SCAR=11.0
Pod undocumented
1491 9214 ▶ return unless $kind;
Branch: 1 branch
BranchTrueFalseTotal
unless $kind 1108 8106 9214
1492  
1493 8106 my %kind= flatten_hash $kind;
1494 return $lx->{token}{kind}
1495 8106 ▶ if $kind{$lx->{token}{kind}};
Branch: 1 branch
BranchTrueFalseTotal
if $kind{$lx->{"token"}{"kind"}} 1416 6690 8106
1496  
1497 6690 return; # Don't return undef, but an empty list, so in array context, we get 0 results
1498 # This principle is used everywhere in this file. In scalar context, we still
1499 # get undef from am empty list.
1500 }
1501  
1502 sub looking_at($$;$)
1503 {
1504 9214 ▶ my ($lx, $kind, $do_shift)= @_;
Subroutine looking_at: called CC=3 SCAR=11.0
Pod undocumented
1505 9214 ▶ if (my $x= looking_at_raw($lx,$kind)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = &looking_at_raw($lx, $kind)) 1416 7798 9214
1506 1416 ▶ lexer_shift($lx) if $do_shift;
Branch: 1 branch
BranchTrueFalseTotal
if $do_shift 1324 92 1416
1507 1416 return $x;
1508 }
1509 7798 return;
1510 }
1511  
1512 sub english_or(@)
1513 {
1514 1 ▶ my $map= undef;
Subroutine english_or: called CC=6 SCAR=21.6
Pod undocumented
1515 1 ▶ $map= shift
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "CODE" 1 0 1
1516 if ref($_[0]) eq 'CODE';
1517  
1518 1 my @l= sort map flatten($_), @_;
1519  
1520 1 ▶ @l= map { $map->($_) } @l
Branch: 1 branch
BranchTrueFalseTotal
if $map 1 0 1
1521 if $map;
1522  
1523 1 ▶ return 'nothing' if scalar(@l) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @l == 0 0 1 1
1524 1 ▶ return $l[0] if scalar(@l) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @l == 1 1 0 1
1525 0 ▶ return "$l[0] or $l[1]" if scalar(@l) == 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @l == 2 0 0 0
1526  
1527 0 return join(", ", @l[0..$#l-1], "or $l[-1]");
1528 }
1529  
1530 sub expect($$;$)
1531 {
1532 779 ▶ my ($lx, $kind, $do_shift)= @_;
Subroutine expect: called CC=3 SCAR=11.2
Pod undocumented
1533 779 ▶ if (my $x= looking_at($lx, $kind, $do_shift)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $x = &looking_at($lx, $kind, $do_shift)) { } 778 1 779
elsif (my $err = &lx_token_error($lx)) { } 0 1 1
1534 778 return $x;
1535 }
1536 elsif (my $err= lx_token_error($lx)) {
1537 0 $lx->{error}= $err;
1538 }
1539 else {
1540 $lx->{error}= 'Expected '.(english_or \&quote_perl, $kind).
1541 1 ', but found '.token_describe($lx->{token});
1542 }
1543 1 return;
1544 }
1545  
1546 # Parse Functions
1547 # ---------------
1548 # These functions return either:
1549 #
1550 # undef - in case of a syntax error
1551 # $lx->{error} will contain more information
1552 #
1553 # [...] - In case of a sequence of things (parse_list)
1554 #
1555 # {...} - In case of a successfully parsed item.
1556 # The hash contains a 'type' plus additional
1557 # slots depending on what was parsed.
1558 #
1559 # These things can be created with create().
1560 #
1561 # Note that tokens may be used here, too.
1562 #
1563 # Note: you cannot *try* to parse something and in case of a
1564 # failure, do something else, because pos() and the $lx->{token}
1565 # will have changed. E.g. when calling parse_list, you *must*
1566 # pass all things that might end a list instead of reading up
1567 # to an error. That's what the look-ahead token is for!
1568  
1569 sub create($$@)
1570 {
1571 2577 ▶ my ($lx, $kind, @more)= @_;
Subroutine create: called CC=2 SCAR=6.9
Pod undocumented
1572 my $r= {
1573 (ref($kind) ?
1574 (
1575 kind => $kind->[0],
1576 type => $kind->[1]
1577 )
1578 : (
1579 kind => $kind,
1580 type => ''
1581 )
1582 ),
1583 line => $lx->{token}{line},
1584 2577 ▶ map { $_ => undef } @more,
Branch: 1 branch
BranchTrueFalseTotal
ref $kind ? : 244 2333 2577
1585 };
1586 2577 lock_keys %$r;
1587 2577 return $r;
1588 }
1589  
1590 # special creates that occur frequently:
1591 sub create_Expr($)
1592 {
1593 1023 ▶ my ($lx)= @_;
Subroutine create_Expr: called CC=1 SCAR=0.0
Pod undocumented
1594 1023 return create ($lx, 'Expr', qw(maybe_check token functor arg switchval otherwise));
1595 }
1596  
1597 sub parse_list($$$$;$)
1598 # We allow multiple separators and also lists beginning with
1599 # separators, but we do not allow them to end with the same separator.
1600 # If a separator is encountered, we assume that the list continues.
1601  
1602 # There is one exception: if you specify an $end, then before the
1603 # $end, there may be too many separators. This is handy for
1604 # statements that often end in ; just before the closing }.
1605  
1606 # <EOF> is implicit treated as an $end in all invocations.
1607  
1608 # A token matching $end is not shifted.
1609 #
1610 # If $end is given, lists may be empty. Otherwise, they may
1611 # not be.
1612  
1613 # The result is either a list reference or undef in case
1614 # of an error. $lx->{error} will then be set accordingly.
1615 {
1616 1210 ▶ my ($result, $lx, $parse_elem, $list_sep, $end)= @_;
Subroutine parse_list: called CC=7 SCAR=19.5
Pod undocumented
1617  
1618 1210 my %pos= ();
1619 1210 ▶ 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 } } 265 1198 1463
1620 1475 ▶ 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 1465 1474
1621 # check that we have no infinite loop:
1622 1484 my $p= pos(${ $lx->{text_p} });
1623 1484 ▶ die "BUG: pos() not shifted in list" if $pos{$p}++;
Branch: 1 branch
BranchTrueFalseTotal
if $pos{$p}++ 0 1484 1484
1624  
1625 # check for end:
1626 1484 ▶ last ELEMENT if looking_at($lx, $end);
Branch: 1 branch
BranchTrueFalseTotal
if &looking_at($lx, $end) 9 1475 1484
1627 1475 ▶ last ELEMENT if looking_at($lx, '<EOF>');
Branch: 1 branch
BranchTrueFalseTotal
if &looking_at($lx, "<EOF>") 1 1474 1475
1628  
1629 # allow too many separators:
1630 } while (looking_at($lx, $list_sep, SHIFT));
1631  
1632 # parse one element:
1633 return unless
1634 1465 ▶ my @result1= $parse_elem->($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my(@result1) = &$parse_elem($lx) 2 1463 1465
1635  
1636 # append that element to result:
1637 1463 push @$result, @result1;
1638  
1639 # check whether the list continues:
1640 } while (looking_at($lx, $list_sep, SHIFT))};
1641  
1642 1208 return $result;
1643 }
1644  
1645 sub parse_try_list($$$)
1646 # List without delimiter, but sequenced prefix-marked elements.
1647 # For example: a list of JOIN clauses.
1648 #
1649 # The parsers for such elements must handle try-parsing, i.e.,
1650 # returning undef while not setting $lx->{error} to indicate
1651 # that they are not looking at a prefix-marked element.
1652 {
1653 154 ▶ my ($result, $lx, $parse_elem)= @_;
Subroutine parse_try_list: called CC=3 SCAR=11.0
Pod undocumented
1654  
1655 154 ▶ while (my @result1= $parse_elem->($lx)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@result1) = &$parse_elem($lx)) 54 154 208
1656 54 push @$result, @result1;
1657 }
1658  
1659 154 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 154 154
1660 154 return $result;
1661 }
1662  
1663 sub find_ref(\%$)
1664 # Finds a ref-valued value in a hash table, allowing redirections.
1665 # If nothing is found, '' is returned (which would never be returned
1666 # otherwise, because it is neither a ref(), nor undef).
1667 {
1668 9535 ▶ my ($hash, $key)= @_;
Subroutine find_ref: called CC=6 SCAR=17.9
Pod undocumented
1669 9535 my $result= undef;
1670 9535 local $SIG{__DIE__}= \&my_confess;
1671 9535 ▶ if (exists $hash->{$key}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $hash->{$key}) { } 7487 2048 9535
elsif (exists $hash->{'-default'}) { } 1086 962 2048
1672 7487 $result= $hash->{$key}
1673 }
1674 elsif (exists $hash->{-default}) {
1675 $result= $hash->{-default}
1676 1086 }
1677 else {
1678 962 return '';
1679 }
1680  
1681 8573 ▶ until (ref($result) || !defined $result) { # No infinite loop protection!
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $result or not defined $result) 392 8573 8965
Condition100%3/3
ref $result or not defined $result
l!l&&r!l&&!r
85712392
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
1682 die "'$result' key not in hash table"
1683 392 ▶ unless exists $hash->{$result};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$result} 0 392 392
1684 392 $result= $hash->{$result};
1685 }
1686  
1687 8573 return $result;
1688 }
1689  
1690 sub switch($%) # waiting for Perl 5.10: given/when/default
1691 {
1692 8243 ▶ my ($value, %case)= @_;
Subroutine switch: called CC=2 SCAR=7.6
Pod undocumented
1693 8243 ▶ if (my $code= find_ref(%case, $value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = &find_ref(\%case, $value)) 8243 0 8243
1694 8243 return $code->();
1695 }
1696  
1697 0 my_confess "Expected ".(english_or \&quote_perl, \%case).", but found '$value'";
1698 }
1699  
1700 sub lx_token_error($)
1701 {
1702 2 ▶ my ($lx)= @_;
Subroutine lx_token_error: called CC=2 SCAR=6.9
Pod undocumented
1703 2 ▶ if ($lx->{token}{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{"token"}{"error"}) 1 1 2
1704 return 'Found '.
1705 quote_perl($lx->{token}{value}).': '.
1706 1 $lx->{token}{str};
1707 }
1708 1 return;
1709 }
1710  
1711 sub parse_choice($%)
1712 {
1713 2266 ▶ my ($lx, %opt)= @_;
Subroutine parse_choice: called CC=1 SCAR=4.4
Pod undocumented
1714 return switch ($lx->{token}{kind},
1715 -default => sub {
1716 0 ▶ if (my $err= lx_token_error($lx)) { # already have an error message.
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if (my $err = &lx_token_error($lx)) { } 0 0 0
elsif (scalar keys %opt > 10) { } 0 0 0
1717 0 $lx->{error}= 'In '.(caller(3))[3].": $err";
1718 }
1719 elsif (scalar(keys %opt) > 10) {
1720 $lx->{error}= 'In '.(caller(3))[3].': '.
1721 0 ' Unexpected '.token_describe($lx->{token});
1722 }
1723 else {
1724 $lx->{error}= 'In '.(caller(3))[3].': Expected '.
1725 (english_or \&quote_perl, \%opt).
1726 ', but found '.
1727 0 token_describe($lx->{token});
1728 }
1729 0 return;
1730 },
1731 2266 %opt, # may override -default
1732 );
1733 }
1734  
1735 sub parse_plain_ident($)
1736 {
1737 543 ▶ my ($lx)= @_;
Subroutine parse_plain_ident: called CC=1 SCAR=0.1
Pod undocumented
1738 return parse_choice($lx,
1739 'interpol' => sub {
1740 49 ▶ my $r= $lx->{token};
Subroutine __ANON__: called CC=2 SCAR=7.9
1741  
1742 # If it is unambiguous, even "..." interpolation is intepreted as
1743 # a column name.
1744 #if (FORCE_STRING && $r->{type} eq 'string') {
1745 # $lx->{error}=
1746 # 'Expected identifier, but found string: '.token_describe($r).
1747 # "\n\t".
1748 # "If you want to construct an identifier name, use {$r->{value}}.";
1749 # return;
1750 #}
1751 #els
1752 49 ▶ if ($r->{type} eq 'num') {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"type"} eq "num") 0 49 49
1753 $lx->{error}=
1754 0 'Expected identifier, but found number: '.token_describe($r).
1755 "\n\t".
1756 "If you want to construct an identifier name, use {$r->{value}}.";
1757 0 return;
1758 }
1759  
1760 49 lexer_shift($lx);
1761 49 return $r;
1762 },
1763  
1764 'interpolColumn' => 'ident',
1765 'interpolTable' => 'ident',
1766 'interpolCharSet' => 'ident',
1767 'interpolEngine' => 'ident',
1768 'interpolCollate' => 'ident',
1769 'interpolConstraint' => 'ident',
1770 'interpolIndex' => 'ident',
1771 'interpolTranscoding' => 'ident',
1772 'interpolTransliteration' => 'ident',
1773 '*' => 'ident',
1774 'ident' => sub {
1775 494 ▶ my $r= $lx->{token};
Subroutine __ANON__: called CC=1 SCAR=0.0
1776 494 lexer_shift($lx);
1777 494 return $r;
1778 },
1779 543 );
1780 }
1781  
1782 sub parse_ident_chain($$)
1783 {
1784 510 ▶ my ($lx, $arr)= @_;
Subroutine parse_ident_chain: called CC=1 SCAR=0.0
Pod undocumented
1785 510 return parse_list($arr, $lx, \&parse_plain_ident, '.');
1786 }
1787  
1788 sub check_column(@)
1789 {
1790 324 ▶ while (scalar(@_) < 4) { unshift @_, undef; }
Subroutine check_column: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ < 4) 942 324 1266
1791 324 my ($cat,$sch,$tab,$col)= @_;
1792  
1793 #return unless !defined $cat || my $cat= $cat->{
1794 #check_ident ('Column', $cat, $sch, $tab, $col);
1795 }
1796  
1797 sub parse_column($;$)
1798 # The interpretation of the identifier chain is left to the column{1,2,3,4}
1799 # family of functions. It is as follows:
1800 #
1801 # Depending on the number of elements in the chain, the following types
1802 # are allowed:
1803 #
1804 # 1 Element:
1805 # - Column: a fully qualified column object, maybe including
1806 # a table specification
1807 # - ColumnName: a single identifier object with a column name
1808 # - string: a single identifier, too, will be quoted accordingly.
1809 #
1810 # 2 Elements:
1811 # - First element: Table or string
1812 # Last element: ColumnName or string
1813 #
1814 # more Elements:
1815 # - All but last element: string only
1816 # - Last element: ColumnName or string
1817 {
1818 324 ▶ my ($lx, $arr)= @_;
Subroutine parse_column: called CC=5 SCAR=16.8
Pod undocumented
1819 324 my $r= create ($lx, 'Column', qw(ident_chain));
1820 324 ▶ $arr||= [];
Condition100%2/2
$arr ||= []
l!l
9315
MC/DC100%1/1
$arr ||= []
$arr
Truth table100%2/2
A
A= $arr
Aresult
11
00
1821 return
1822 324 ▶ unless parse_ident_chain($lx, $arr);
Branch: 1 branch
BranchTrueFalseTotal
unless &parse_ident_chain($lx, $arr) 0 324 324
1823  
1824 324 ▶ my_confess if scalar(@$arr) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$arr < 1 0 324 324
1825 324 ▶ if (scalar(@$arr) > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arr > 4) 0 324 324
1826 0 $lx->{error}= 'Too many parts of column identifier chain. '.
1827 'Maximum is 4, found '.scalar(@$arr);
1828 0 return;
1829 }
1830  
1831 324 check_column(@$arr);
1832  
1833 324 $r->{ident_chain}= $arr;
1834  
1835 324 lock_keys %$r;
1836 324 return $r;
1837 }
1838  
1839 sub parse_schema_qualified($$)
1840 {
1841 186 ▶ my ($lx, $kind)= @_;
Subroutine parse_schema_qualified: called CC=4 SCAR=14.8
Pod undocumented
1842  
1843 186 my $r= create ($lx, $kind, qw(ident_chain));
1844 186 my $arr= [];
1845 return
1846 186 ▶ unless parse_ident_chain($lx, $arr);
Branch: 1 branch
BranchTrueFalseTotal
unless &parse_ident_chain($lx, $arr) 0 186 186
1847  
1848 186 ▶ my_confess if scalar(@$arr) < 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$arr < 1 0 186 186
1849 186 ▶ if (scalar(@$arr) > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$arr > 3) 0 186 186
1850 0 $lx->{error}= 'Too many identifiers in $kind. '.
1851 'Maximum is 3, found '.scalar(@$arr);
1852 0 return;
1853 }
1854  
1855 186 $r->{ident_chain}= $arr;
1856  
1857 186 lock_keys %$r;
1858 186 return $r;
1859 }
1860  
1861 sub parse_table($)
1862 # The interpretation of the identifier chain is left to the table{1,2,3}
1863 # family of functions. It is as follows:
1864 #
1865 # Depending on the number of elements in the chain, the following types
1866 # are allowed:
1867 #
1868 # 1 Element:
1869 # - Table: a fully qualified table object
1870 # - string: a single identifier, too, will be quoted accordingly.
1871 #
1872 # more Elements:
1873 # - all elements: string
1874 {
1875 168 ▶ my ($lx)= @_;
Subroutine parse_table: called CC=1 SCAR=0.0
Pod undocumented
1876 168 return parse_schema_qualified($lx, 'Table');
1877 }
1878  
1879 sub parse_charset($)
1880 {
1881 7 ▶ my ($lx)= @_;
Subroutine parse_charset: called CC=1 SCAR=0.0
Pod undocumented
1882 7 return parse_schema_qualified($lx, 'CharSet');
1883 }
1884  
1885 sub parse_constraint($)
1886 {
1887 7 ▶ my ($lx)= @_;
Subroutine parse_constraint: called CC=1 SCAR=0.0
Pod undocumented
1888 7 return parse_schema_qualified($lx, 'Constraint');
1889 }
1890  
1891 sub parse_index($)
1892 {
1893 1 ▶ my ($lx)= @_;
Subroutine parse_index: called CC=1 SCAR=0.0
Pod undocumented
1894 1 return parse_schema_qualified($lx, 'Index');
1895 }
1896  
1897 sub parse_collate($)
1898 {
1899 1 ▶ my ($lx)= @_;
Subroutine parse_collate: called CC=1 SCAR=0.0
Pod undocumented
1900 1 return parse_schema_qualified($lx, 'Collate');
1901 }
1902  
1903 sub parse_transliteration($)
1904 {
1905 0 ▶ my ($lx)= @_;
Subroutine parse_transliteration: not called CC=1 SCAR=6.9
Pod undocumented
1906 0 return parse_schema_qualified($lx, 'Transliteration');
1907 }
1908  
1909 sub parse_transcoding($)
1910 {
1911 0 ▶ my ($lx)= @_;
Subroutine parse_transcoding: not called CC=1 SCAR=6.9
Pod undocumented
1912 0 return parse_schema_qualified($lx, 'Transcoding');
1913 }
1914  
1915 sub parse_engine($)
1916 {
1917 2 ▶ my ($lx)= @_;
Subroutine parse_engine: called CC=1 SCAR=0.0
Pod undocumented
1918 2 return parse_schema_qualified($lx, 'Engine');
1919 }
1920  
1921  
1922 sub parse_column_name($)
1923 {
1924 49 ▶ my ($lx)= @_;
Subroutine parse_column_name: called CC=2 SCAR=6.9
Pod undocumented
1925 49 my $r= create ($lx, 'ColumnName', qw(token));
1926  
1927 parse_choice($lx,
1928 'ident' => sub {
1929 44 ▶ $r->{type}= 'ident';
Subroutine __ANON__: called CC=1 SCAR=0.0
1930 44 $r->{token}= $lx->{token};
1931 44 lexer_shift($lx);
1932 },
1933  
1934 'interpolColumn' => 'interpol',
1935 'interpol' => sub {
1936 5 ▶ $r->{type}= 'interpol';
Subroutine __ANON__: called CC=1 SCAR=0.0
1937 5 $r->{token}= $lx->{token};
1938 5 lexer_shift($lx);
1939 },
1940 49 );
1941 49 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 49 49
1942  
1943 49 lock_keys %$r;
1944 49 return $r;
1945 }
1946  
1947 sub parse_column_index($)
1948 {
1949 2 ▶ my ($lx)= @_;
Subroutine parse_column_index: called CC=7 SCAR=20.2
Pod undocumented
1950 2 my $r= create ($lx, 'ColumnIndex', qw(name length desc));
1951  
1952 return unless
1953 2 ▶ $r->{name}= parse_column_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"name"} = &parse_column_name($lx) 0 2 2
1954  
1955 2 ▶ if (looking_at($lx, '(', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "(", 1)) 1 1 2
1956 return unless
1957 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
1958 and expect ($lx, ')', SHIFT);
1959 }
1960  
1961 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
1962 1 $r->{desc}= 1;
1963 }
1964 elsif (looking_at($lx, 'ASC', SHIFT)) {
1965 #ignore
1966 }
1967  
1968 2 lock_hash %$r;
1969 2 return $r;
1970 }
1971  
1972 sub parse_table_name($)
1973 {
1974 3 ▶ my ($lx)= @_;
Subroutine parse_table_name: called CC=2 SCAR=7.4
Pod undocumented
1975 3 my $r= create ($lx, 'TableName', qw(token));
1976  
1977 parse_choice($lx,
1978 'ident' => sub {
1979 3 ▶ $r->{type}= 'ident';
Subroutine __ANON__: called CC=1 SCAR=0.0
1980 3 $r->{token}= $lx->{token};
1981 3 lexer_shift($lx);
1982 },
1983  
1984 'interpolTable' => 'interpol',
1985 'interpol' => sub {
1986 0 ▶ $r->{type}= 'interpol';
Subroutine __ANON__: not called CC=1 SCAR=6.9
1987 0 $r->{token}= $lx->{token};
1988 0 lexer_shift($lx);
1989 },
1990 3 );
1991 3 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 3 3
1992  
1993 3 lock_keys %$r;
1994 3 return $r;
1995 }
1996  
1997 sub parse_table_as($)
1998 {
1999 122 ▶ my ($lx)= @_;
Subroutine parse_table_as: called CC=4 SCAR=14.0
Pod undocumented
2000 122 my $r= create ($lx, 'TableAs', qw(table as));
2001  
2002 return unless
2003 122 ▶ $r->{table}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_table($lx) 0 122 122
2004  
2005 122 ▶ if (looking_at($lx, 'AS', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "AS", 1)) 3 119 122
2006 return unless
2007 3 ▶ $r->{as}= parse_table_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"as"} = &parse_table_name($lx) 0 3 3
2008 }
2009  
2010 122 lock_hash %$r;
2011 122 return $r;
2012 }
2013  
2014 sub parse_value_or_column_into($$$)
2015 {
2016 173 ▶ my ($lx, $r, $type)= @_;
Subroutine parse_value_or_column_into: called CC=2 SCAR=6.9
Pod undocumented
2017  
2018 173 my $token= $lx->{token};
2019 173 lexer_shift($lx);
2020  
2021 173 ▶ if (looking_at($lx, '.')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '.')) { } 9 164 173
2022 9 $r->{type}= 'column';
2023 9 $r->{arg}= parse_column($lx, [ $token ]);
2024 }
2025 else {
2026 164 $r->{type}= $type;
2027 164 $r->{token}= $token;
2028 }
2029 }
2030  
2031 sub parse_expr($;$$);
2032 sub parse_select_stmt($);
2033 sub parse_funcsep($$$);
2034 sub parse_expr_post($$$$);
2035  
2036 5 ▶use constant ACTION_AMBIGUOUS => undef;
Subroutine BEGIN: called CC=1 SCAR=0.0
2037 5 ▶use constant ACTION_REDUCE => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2038 5 ▶use constant ACTION_SHIFT => +1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2039  
2040 sub plural($;$$)
2041 {
2042 0 ▶ my ($cnt, $sg, $pl)= @_;
Subroutine plural: not called CC=4 SCAR=30.0
Pod undocumented
2043 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
2044 }
2045  
2046 sub parse_limit_expr($)
2047 {
2048 24 ▶ my ($lx)= @_;
Subroutine parse_limit_expr: called CC=2 SCAR=7.0
Pod undocumented
2049 return unless
2050 24 ▶ my $limit= parse_limit_num($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $limit = &parse_limit_num($lx) 0 24 24
2051 24 my $r= create_Expr ($lx);
2052 24 $r->{type}= 'limit';
2053 24 $r->{arg}= $limit;
2054 24 lock_hash %$r;
2055 24 return $r;
2056 }
2057  
2058 sub parse_char_unit($)
2059 {
2060 1 ▶ my ($lx)= @_;
Subroutine parse_char_unit: called CC=1 SCAR=0.0
Pod undocumented
2061 1 my $r= create($lx, 'CharUnit', qw(name));
2062 1 $r->{name}= expect($lx, ['CHARACTERS', 'CODE_UNITS', 'OCTETS'], SHIFT);
2063 1 lock_hash %$r;
2064 1 return $r;
2065 }
2066  
2067 sub parse_list_delim($$)
2068 {
2069 57 ▶ my ($lx, $func)= @_;
Subroutine parse_list_delim: called CC=4 SCAR=17.1
Pod undocumented
2070 return unless
2071 57 ▶ expect($lx, '(', SHIFT)
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "(", 1) and my $list = &parse_list(scalar [], $lx, $func, ",", ")") and &expect($lx, ")", 1) 0 57 57
Condition33%2/6
&expect($lx, "(", 1) and my $list = &parse_list(scalar [], $lx, $func, ",", ")") and &expect($lx, ")", 1)
!ll&&!rl&&r
0057
&expect($lx, "(", 1) and my $list = &parse_list(scalar [], $lx, $func, ",", ")")
!ll&&!rl&&r
0057
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
2072 and my $list= parse_list([], $lx, $func, ',', ')')
2073 and expect($lx, ')', SHIFT);
2074 57 return $list;
2075 }
2076  
2077 sub parse_type_post_inner($)
2078 {
2079 106 ▶ my ($lx)= @_;
Subroutine parse_type_post_inner: called CC=1 SCAR=0.9
Pod undocumented
2080  
2081 106 my $functor= undef;
2082 106 my @arg= ();
2083 parse_choice ($lx,
2084 -default => sub {
2085 73 ▶ if (my $spec= find_ref(%type_spec, $lx->{token}{kind})) {
Subroutine __ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $spec = &find_ref(\%type_spec, $lx->{"token"}{"kind"})) 27 46 73
2086 27 ▶ if ($spec->{value_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'value_list'}) { } 1 26 27
2087 1 $functor= 'basewlist',
2088 push @arg, lexer_shift($lx);
2089 return unless
2090 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
2091 1 push @arg, @$value_list;
2092 }
2093 else {
2094 26 $functor= 'base';
2095 26 push @arg, lexer_shift($lx);
2096 }
2097 }
2098 },
2099  
2100 'UNSIGNED' => 'SIGNED',
2101 'SIGNED' => sub {
2102 1 ▶ $functor= 'property';
Subroutine __ANON__: called CC=1 SCAR=0.0
2103 1 push @arg, 'sign', lexer_shift($lx);
2104 },
2105 'DROP SIGN' => sub {
2106 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2107 0 push @arg, 'sign', '';
2108 0 lexer_shift($lx);
2109 },
2110  
2111 'ZEROFILL' => sub {
2112 1 ▶ $functor= 'property';
Subroutine __ANON__: called CC=1 SCAR=0.0
2113 1 push @arg, 'zerofill', lexer_shift($lx);
2114 },
2115  
2116 'DROP ZEROFILL' => sub {
2117 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2118 0 push @arg, 'zerofill', '';
2119 0 lexer_shift($lx);
2120 },
2121  
2122 'ASCII' => sub {
2123 0 ▶ my $cs= create($lx, 'CharSet', qw(token));
Subroutine __ANON__: not called CC=1 SCAR=6.9
2124 0 $cs->{token}= ident_new($lx, 'latin1');
2125 0 $functor= 'property';
2126 0 push @arg, 'charset', $cs;
2127 0 lexer_shift($lx);
2128 },
2129 'UNICODE' => sub {
2130 0 ▶ my $cs= create($lx, 'CharSet', qw(token));
Subroutine __ANON__: not called CC=1 SCAR=6.9
2131 0 $cs->{token}= ident_new($lx, 'ucs2');
2132 0 $functor= 'property';
2133 0 push @arg, 'charset', $cs;
2134 0 lexer_shift($lx);
2135 },
2136 'CHARACTER SET' => sub {
2137 4 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.0
2138 return unless
2139 4 ▶ my $arg= parse_charset($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_charset($lx) 0 4 4
2140 4 $functor= 'property';
2141 4 push @arg, 'charset', $arg;
2142 },
2143 'DROP CHARACTER SET' => sub {
2144 3 ▶ $functor= 'property';
Subroutine __ANON__: called CC=1 SCAR=0.0
2145 3 push @arg, 'charset', '';
2146 3 lexer_shift($lx);
2147 },
2148  
2149 'COLLATE' => sub {
2150 1 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.0
2151 return unless
2152 1 ▶ my $arg= parse_collate($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_collate($lx) 0 1 1
2153 1 $functor= 'property';
2154 1 push @arg, 'collate', $arg;
2155 },
2156 'DROP COLLATE' => sub {
2157 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2158 0 push @arg, 'collate', '';
2159 0 lexer_shift($lx);
2160 },
2161  
2162 'WITH LOCAL TIME ZONE' => 'WITH TIME ZONE',
2163 'WITHOUT TIME ZONE' => 'WITH TIME ZONE',
2164 'WITH TIME ZONE' => sub {
2165 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2166 0 push @arg, 'timezone', lexer_shift($lx);
2167 },
2168  
2169 'DROP TIME ZONE' => sub {
2170 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2171 0 push @arg, 'timezone', '';
2172 0 lexer_shift($lx);
2173 },
2174  
2175 '(' => sub {
2176 23 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=4 SCAR=17.2
2177 return unless
2178 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
2179  
2180 parse_choice($lx,
2181 'K' => 'G',
2182 'M' => 'G',
2183 'G' => sub {
2184 1 ▶ if (scalar(@$list) > 1) {
Subroutine __ANON__: called CC=4 SCAR=15.8
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 1) 0 1 1
2185 0 $lx->{error}= "At most one value in () expected, but found ".scalar($list);
2186 0 return;
2187 }
2188  
2189 1 $functor= 'largelength';
2190 1 push @arg, $list->[0];
2191  
2192 1 push @arg, lexer_shift($lx);
2193  
2194 1 ▶ if (looking_at($lx, ')')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ')')) { } 0 1 1
2195 0 push @arg, '';
2196 }
2197 else {
2198 return unless
2199 1 ▶ my $unit= parse_char_unit($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $unit = &parse_char_unit($lx) 0 1 1
2200  
2201 1 push @arg, $unit;
2202 }
2203 },
2204  
2205 'ident' => sub {
2206 0 ▶ if (scalar(@$list) > 1) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 1) 0 0 0
2207 0 $lx->{error}= "At most one value in () expected, but found ".scalar($list);
2208 0 return;
2209 }
2210  
2211 0 $functor= 'largelength';
2212 0 push @arg, '';
2213  
2214 },
2215  
2216 -default => sub {
2217 22 ▶ if (scalar(@$list) > 2) {
Subroutine __ANON__: called CC=2 SCAR=8.4
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list > 2) 0 22 22
2218 0 $lx->{error}= "At most two values in () expected, but found ".scalar($list);
2219 0 return;
2220 }
2221  
2222 22 $functor= 'length';
2223 22 push @arg, @$list;
2224 }
2225 23 );
2226 23 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 23 23
2227 23 ▶ return unless expect($lx, ')', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, ")", 1) 0 23 23
2228 },
2229 106 );
2230  
2231 106 return ($functor, \@arg);
2232 }
2233  
2234 sub parse_type_post($$);
2235 sub parse_type_post($$)
2236 {
2237 86 ▶ my ($lx, $base)= @_;
Subroutine parse_type_post: called CC=3 SCAR=11.0
Pod undocumented
2238 86 my $r= create($lx, 'TypePost', qw(base functor arg));
2239 86 $r->{base}= $base;
2240  
2241 86 ($r->{functor}, $r->{arg})= parse_type_post_inner($lx);
2242 return
2243 86 ▶ if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 86 86
2244  
2245 return $base
2246 86 ▶ unless defined $r->{functor};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"functor"} 30 56 86
2247  
2248 56 return parse_type_post ($lx, $r);
2249 }
2250  
2251 sub parse_type($)
2252 {
2253 30 ▶ my ($lx)= @_;
Subroutine parse_type: called CC=3 SCAR=11.1
Pod undocumented
2254 30 my $r= create($lx, 'Type', qw(base token));
2255  
2256 30 ▶ if (looking_at($lx, ['interpol', 'interpolType'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ['interpol', 'interpolType'])) { } 8 22 30
2257 8 $r->{type}= 'interpol';
2258 8 $r->{token}= $lx->{token};
2259 8 lexer_shift($lx);
2260 }
2261 else {
2262 22 ▶ unless ($type_spec{$lx->{token}{kind}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type_spec{$lx->{"token"}{"kind"}}) 0 22 22
2263 0 $lx->{error}= 'Expected type name, but found '.token_describe($lx->{token});
2264 0 return;
2265 }
2266 22 $r->{type}= 'base';
2267 22 $r->{base}= $lx->{token}{kind};
2268 }
2269  
2270 30 lock_hash %$r;
2271 30 return parse_type_post ($lx, $r);
2272 }
2273  
2274 sub parse_type_list($) # without enclosing (...)
2275 {
2276 1 ▶ my ($lx)= @_;
Subroutine parse_type_list: called CC=2 SCAR=7.0
Pod undocumented
2277 return unless
2278 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
2279  
2280 1 my $r= create ($lx, ['TypeList','explicit'], qw(arg));
2281 1 $r->{arg}= $arg;
2282 1 lock_hash %$r;
2283 1 return $r;
2284 }
2285  
2286 sub parse_type_list_delim($) # with enclosing (...)
2287 {
2288 1 ▶ my ($lx)= @_;
Subroutine parse_type_list_delim: called CC=1 SCAR=1.4
Pod undocumented
2289  
2290 return parse_choice($lx,
2291 '(' => sub {
2292 1 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=3 SCAR=12.5
2293 return unless
2294 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
2295 and expect ($lx, ')', SHIFT);
2296 1 return $r;
2297 },
2298  
2299 'interpol' => sub { # Perl array reference:
2300 0 ▶ my $r= create ($lx, ['TypeList','interpol'], qw(token));
Subroutine __ANON__: not called CC=1 SCAR=6.9
2301 0 $r->{token}= $lx->{token};
2302 0 lexer_shift($lx);
2303 0 lock_hash %$r;
2304 0 return $r;
2305 },
2306 1 );
2307 }
2308  
2309 sub parse_on_action($)
2310 {
2311 1 ▶ my ($lx)= @_;
Subroutine parse_on_action: called CC=1 SCAR=0.0
Pod undocumented
2312 1 return looking_at($lx, ['RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT', 'NO ACTION'], SHIFT);
2313 }
2314  
2315 sub parse_references($)
2316 {
2317 3 ▶ my ($lx)= @_;
Subroutine parse_references: called CC=5 SCAR=17.6
Pod undocumented
2318 3 my $r= create($lx, 'References', qw(table column match on_delete on_update));
2319  
2320 3 lexer_shift($lx);
2321  
2322 return unless
2323 $r->{table}= parse_table($lx)
2324 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
2325  
2326 3 ▶ if (looking_at($lx, 'MATCH', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "MATCH", 1)) 1 2 3
2327 1 $r->{match}= expect ($lx, ['FULL','PARTIAL','SINGLE'], SHIFT);
2328 }
2329  
2330 parse_try_list([], $lx, sub {
2331 parse_choice($lx,
2332 'ON DELETE' => sub {
2333 1 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.2
2334 return unless
2335 1 ▶ $r->{on_delete}= parse_on_action($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"on_delete"} = &parse_on_action($lx) 0 1 1
2336 },
2337 'ON UPDATE' => sub {
2338 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=2 SCAR=17.9
2339 return unless
2340 0 ▶ $r->{on_update}= parse_on_action($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"on_update"} = &parse_on_action($lx) 0 0 0
2341 },
2342 ▶ -default => sub {}
Subroutine __ANON__: called CC=1 SCAR=0.0
2343 4 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
2344 3 });
2345 3 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 3 3
2346  
2347 3 lock_hash %$r;
2348 3 return $r;
2349 }
2350  
2351 sub parse_column_spec_post_inner($)
2352 {
2353 38 ▶ my ($lx)= @_;
Subroutine parse_column_spec_post_inner: called CC=4 SCAR=20.9
Pod undocumented
2354 38 my $functor= undef;
2355 38 my @arg= ();
2356  
2357 38 my $constraint= undef;
2358 38 ▶ if (looking_at($lx, 'CONSTRAINT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "CONSTRAINT", 1)) 2 36 38
2359 return unless
2360 2 ▶ $constraint= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $constraint = &parse_constraint($lx) 0 2 2
2361 }
2362  
2363 parse_choice($lx,
2364 -default => sub {
2365 20 ▶ if ($constraint) {
Subroutine __ANON__: called CC=3 SCAR=11.2
Branch: 1 branch
BranchTrueFalseTotal
if ($constraint) { } 0 20 20
2366 0 $lx->{error}= 'Constraint expected';
2367 }
2368 else {
2369 20 my ($func, $arg)= parse_type_post_inner($lx); # inherit column type post
2370 20 ▶ if ($func) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func) 4 16 20
2371 4 $functor= "type_$func";
2372 4 @arg= @$arg;
2373 }
2374 }
2375 },
2376 'NOT NULL' => sub {
2377 10 ▶ $functor= 'property';
Subroutine __ANON__: called CC=1 SCAR=0.0
2378 10 push @arg, $constraint, 'notnull', lexer_shift($lx);
2379 },
2380 'NULL' => sub {
2381 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2382 0 push @arg, $constraint, 'notnull', '';
2383 0 lexer_shift($lx);
2384 },
2385  
2386 'AUTO_INCREMENT' => sub {
2387 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2388 0 push @arg, $constraint, 'autoinc', lexer_shift($lx);
2389 },
2390 'DROP AUTO_INCREMENT' => sub {
2391 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2392 0 push @arg, $constraint, 'autoinc', '';
2393 0 lexer_shift($lx);
2394 },
2395  
2396 'UNIQUE' => sub {
2397 1 ▶ $functor= 'property';
Subroutine __ANON__: called CC=1 SCAR=0.0
2398 1 push @arg, $constraint, 'unique', lexer_shift($lx);
2399 },
2400 'DROP UNIQUE' => sub {
2401 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2402 0 push @arg, $constraint, 'unique', '';
2403 0 lexer_shift($lx);
2404 },
2405  
2406 'PRIMARY KEY' => sub {
2407 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2408 0 push @arg, $constraint, 'primary', lexer_shift($lx);
2409 },
2410 'DROP PRIMARY KEY' => sub {
2411 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2412 0 push @arg, $constraint, 'primary', '';
2413 0 lexer_shift($lx);
2414 },
2415  
2416 'KEY' => sub {
2417 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2418 0 push @arg, $constraint, 'key', lexer_shift($lx);
2419 },
2420 'DROP KEY' => sub {
2421 0 ▶ $functor= 'property';
Subroutine __ANON__: not called CC=1 SCAR=6.9
2422 0 push @arg, $constraint, 'key', '';
2423 0 lexer_shift($lx);
2424 },
2425  
2426 'DEFAULT' => sub {
2427 6 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.0
2428 return unless
2429 6 ▶ my $val= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $val = &parse_expr($lx) 0 6 6
2430 6 $functor= 'property';
2431 6 push @arg, $constraint, 'default', $val;
2432 },
2433 'DROP DEFAULT' => sub {
2434 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2435 0 $functor= 'property';
2436 0 push @arg, $constraint, 'default', '';
2437 },
2438  
2439 'CHECK' => sub {
2440 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=2 SCAR=17.9
2441 return unless
2442 0 ▶ my $val= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $val = &parse_expr($lx) 0 0 0
2443 0 $functor= 'property';
2444 0 push @arg, $constraint, 'check', $val;
2445 },
2446 'DROP CHECK' => sub {
2447 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2448 0 $functor= 'property';
2449 0 push @arg, $constraint, 'check', '';
2450 },
2451  
2452 ($read_dialect{mysql} ?
2453 (
2454 'COMMENT' => sub {
2455 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=2 SCAR=17.9
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, 'comment', $val;
2460 },
2461 'DROP COMMENT' => sub {
2462 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2463 0 $functor= 'property';
2464 0 push @arg, $constraint, 'comment', '';
2465 },
2466 'COLUMN_FORMAT' => sub {
2467 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2468 0 $functor= 'property';
2469 0 push @arg, $constraint, 'column_format',
2470 expect($lx, ['FIXED','DYNAMIC','DEFAULT'], SHIFT);
2471 },
2472 'STORAGE' => sub {
2473 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2474 0 $functor= 'property';
2475 0 push @arg, $constraint, 'storage',
2476 expect($lx, ['DISK','MEMORY','DEFAULT'], SHIFT);
2477 }
2478 )
2479 : ()
2480 ),
2481  
2482 'REFERENCES' => sub {
2483 return unless
2484 1 ▶ my $ref= parse_references($lx);
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
unless my $ref = &parse_references($lx) 0 1 1
2485 1 $functor= 'property';
2486 1 push @arg, $constraint, 'references', $ref;
2487 },
2488 'DROP REFERENCES' => sub {
2489 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
2490 0 $functor= 'property';
2491 0 push @arg, $constraint, 'references', '';
2492 },
2493 38 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 38 0 38
2494  
2495 38 return ($functor, \@arg);
2496 }
2497  
2498 sub parse_column_spec_post($$);
2499 sub parse_column_spec_post($$)
2500 {
2501 38 ▶ my ($lx, $base)= @_;
Subroutine parse_column_spec_post: called CC=3 SCAR=11.0
Pod undocumented
2502  
2503 38 my $r= create($lx, 'ColumnSpecPost', qw(base functor arg));
2504 38 $r->{base}= $base;
2505 38 $r->{arg}= [];
2506  
2507 38 ($r->{functor}, $r->{arg})= parse_column_spec_post_inner($lx);
2508 return
2509 38 ▶ if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 38 38
2510  
2511 return $base
2512 38 ▶ unless defined $r->{functor};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"functor"} 16 22 38
2513  
2514 22 return parse_column_spec_post ($lx, $r);
2515 }
2516  
2517 sub parse_column_spec($)
2518 {
2519 16 ▶ my ($lx)= @_;
Subroutine parse_column_spec: called CC=2 SCAR=7.0
Pod undocumented
2520  
2521 16 my $r= create($lx, 'ColumnSpec', qw(datatype name token));
2522  
2523 parse_choice($lx,
2524 'interpolColumnSpec' => 'interpol',
2525 'interpol' => sub {
2526 7 ▶ $r->{type}= 'interpol';
Subroutine __ANON__: called CC=1 SCAR=0.0
2527 7 $r->{token}= $lx->{token};
2528 7 lexer_shift($lx);
2529 },
2530  
2531 -default => sub {
2532 9 ▶ $r->{type}= 'base';
Subroutine __ANON__: called CC=2 SCAR=7.2
2533 return unless
2534 9 ▶ $r->{datatype}= parse_type($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"datatype"} = &parse_type($lx) 0 9 9
2535 }
2536 16 );
2537 16 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 16 16
2538  
2539 16 lock_hash %$r;
2540 16 return parse_column_spec_post($lx, $r);
2541  
2542 }
2543  
2544 sub parse_expr_list($) # without enclosing (...)
2545 {
2546 9 ▶ my ($lx)= @_;
Subroutine parse_expr_list: called CC=4 SCAR=13.9
Pod undocumented
2547 9 ▶ if (looking_at($lx, [@SELECT_INITIAL,'interpolStmt'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, [@SELECT_INITIAL, 'interpolStmt'])) { } 3 6 9
2548 return unless
2549 3 ▶ my $q= parse_select_stmt($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $q = &parse_select_stmt($lx) 0 3 3
2550  
2551 3 my $r= create_Expr ($lx);
2552 3 $r->{type}= 'subquery';
2553 3 $r->{arg}= $q;
2554 3 return $r;
2555 }
2556 else {
2557 6 my $r= create ($lx, ['ExprList','explicit'], qw(arg));
2558  
2559 return unless
2560 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
2561  
2562 6 $r->{arg}= $arg;
2563 6 lock_hash %$r;
2564 6 return $r;
2565 }
2566 }
2567  
2568 sub parse_expr_list_delim($) # with enclosing (...)
2569 {
2570 15 ▶ my ($lx)= @_;
Subroutine parse_expr_list_delim: called CC=1 SCAR=0.1
Pod undocumented
2571  
2572 return parse_choice($lx,
2573 '(' => sub {
2574 9 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=3 SCAR=12.5
2575 return unless
2576 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
2577 and expect ($lx, ')', SHIFT);
2578 9 return $r;
2579 },
2580  
2581 'interpol' => sub { # Perl array reference:
2582 5 ▶ my $r= create ($lx, ['ExprList','interpol'], qw(token));
Subroutine __ANON__: called CC=1 SCAR=0.0
2583 5 $r->{token}= $lx->{token};
2584 5 lexer_shift($lx);
2585 5 lock_hash %$r;
2586 5 return $r;
2587 },
2588 15 );
2589 }
2590  
2591 sub get_rhs($$)
2592 {
2593 190 ▶ my ($left, $arg_i)= @_;
Subroutine get_rhs: called CC=2 SCAR=8.1
Pod undocumented
2594 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
2595 }
2596  
2597 sub parse_thing($$;$$)
2598 {
2599 203 ▶ my ($lx, $thing_name, $left, $right_mark)= @_;
Subroutine parse_thing: called CC=1 SCAR=0.0
Pod undocumented
2600 return switch ($thing_name,
2601 'expr' => sub {
2602 191 ▶ return parse_expr ($lx, $left, $right_mark)
Subroutine __ANON__: called CC=1 SCAR=0.0
2603 },
2604 'type' => sub {
2605 1 ▶ return parse_type ($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
2606 },
2607 'string_expr' => sub {
2608 1 ▶ return parse_expr ($lx, $left, 'string')
Subroutine __ANON__: called CC=1 SCAR=0.0
2609 },
2610 'expr_list' => sub {
2611 9 ▶ return parse_expr_list_delim($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
2612 },
2613 'type_list' => sub {
2614 1 ▶ return parse_type_list_delim($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
2615 },
2616 203 );
2617 }
2618  
2619 sub parse_funcsep($$$)
2620 {
2621 8 ▶ my ($lx, $r, $pattern)= @_;
Subroutine parse_funcsep: called CC=9 SCAR=22.5
Pod undocumented
2622 8 for my $e (@$pattern) {
2623 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
2624 return unless
2625 14 ▶ expect($lx, $e, SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, $e, 1) 0 14 14
2626 14 push @{ $r->{arg} }, $e; # no ref()
2627 }
2628 elsif (ref($e) eq 'SCALAR') {
2629 return unless
2630 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
2631 13 push @{ $r->{arg} }, $arg;
2632 }
2633 elsif (ref($e) eq 'ARRAY') {
2634 7 ▶ if (looking_at($lx, $e->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, $e->[0])) 2 5 7
2635 return unless
2636 2 ▶ parse_funcsep($lx, $r, $e);
Branch: 1 branch
BranchTrueFalseTotal
unless &parse_funcsep($lx, $r, $e) 0 2 2
2637 }
2638 }
2639 else {
2640 0 die "Unrecognised pattern piece, ref()=".ref($e);
2641 }
2642 }
2643 8 return $r;
2644 }
2645  
2646 sub parse_check($)
2647 {
2648 9 ▶ my ($lx)= @_;
Subroutine parse_check: called CC=2 SCAR=7.0
Pod undocumented
2649 9 my $r= create ($lx, 'Check', qw(expr));
2650  
2651 9 my $cond= parse_expr_post($lx, undef, undef, create($lx, 'ExprEmpty'));
2652 9 ▶ return unless $cond;
Branch: 1 branch
BranchTrueFalseTotal
unless $cond 0 9 9
2653  
2654 9 $r->{expr}= $cond;
2655 9 return $r;
2656 }
2657  
2658 sub parse_when_post($)
2659 {
2660 42 ▶ my ($lx)= @_;
Subroutine parse_when_post: called CC=7 SCAR=20.4
Pod undocumented
2661  
2662 return unless
2663 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
2664  
2665 20 my $cond;
2666  
2667 20 my $functor= find_functor(\%functor_suffix, $lx->{token}{kind});
2668 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
2669 9 $cond= parse_expr_post($lx, undef, undef, create($lx, 'ExprEmpty'));
2670 }
2671 else {
2672 11 $cond= parse_expr($lx);
2673 }
2674  
2675 return unless
2676 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
2677 and expect($lx, 'THEN', SHIFT)
2678 and my $expr= parse_expr($lx);
2679  
2680 20 $cond->{maybe_check}= 1; # allow Check interpolation if this is an Expr
2681  
2682 20 return [ $cond, $expr ];
2683 }
2684  
2685 sub parse_when($)
2686 {
2687 22 ▶ my ($lx)= @_;
Subroutine parse_when: called CC=5 SCAR=17.2
Pod undocumented
2688  
2689 return unless
2690 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) 0 10 10
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
2691 and my $cond= parse_expr($lx)
2692 and expect($lx, 'THEN', SHIFT)
2693 and my $expr= parse_expr($lx);
2694  
2695 10 return [ $cond, $expr ];
2696 }
2697  
2698 sub shift_or_reduce_pure($$$)
2699 # $right_mark is either 0/undef, 1, or 'string', see parse_expr().
2700 {
2701 183 ▶ my ($left, $right, $right_mark)= @_;
Subroutine shift_or_reduce_pure: called CC=18 SCAR=45.5
Pod undocumented
2702  
2703 # hack for 'IN':
2704 return ACTION_REDUCE
2705 if ($right_mark || '') eq 'string' &&
2706 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
2707  
2708 # currently, this is very simple, because we don't use precedences:
2709 182 ▶ return ACTION_SHIFT
Branch: 1 branch
BranchTrueFalseTotal
unless $left 178 4 182
2710 unless $left;
2711  
2712 # special rule to allow sequencing even for operators without precedence:
2713 return ACTION_REDUCE
2714 if $left->{value} eq $right->{value} &&
2715 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
2716  
2717 # parse with precedences?
2718 3 ▶ if ($do_prec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_prec) { } 0 3 3
2719 # if both have a precedence:
2720 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
2721 return ACTION_REDUCE
2722 0 ▶ if $left->{prec} > $right->{prec};
Branch: 1 branch
BranchTrueFalseTotal
if $left->{"prec"} > $right->{"prec"} 0 0 0
2723  
2724 return ACTION_SHIFT
2725 0 ▶ if $left->{prec} < $right->{prec};
Branch: 1 branch
BranchTrueFalseTotal
if $left->{"prec"} < $right->{"prec"} 0 0 0
2726  
2727 # if both have an associativity and the associativity is the same:
2728 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
2729 $left->{assoc} == $right->{assoc})
2730 {
2731 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
2732 0 return ACTION_REDUCE;
2733 }
2734 else {
2735 0 return ACTION_SHIFT;
2736 }
2737 }
2738 }
2739 }
2740 else {
2741 # no precedences at all:
2742 # For infix23 and infix3, we need to reduce, instead of failing:
2743 3 ▶ if (defined $left->{value2}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $left->{"value2"}) 3 0 3
2744 3 return ACTION_REDUCE;
2745 }
2746 }
2747  
2748 # otherwise: ambiguous
2749 0 return ACTION_AMBIGUOUS;
2750 }
2751  
2752 sub shift_or_reduce($$$$)
2753 {
2754 183 ▶ my ($lx, $left, $right, $right_mark)= @_;
Subroutine shift_or_reduce: called CC=2 SCAR=7.4
Pod undocumented
2755 183 my $result= shift_or_reduce_pure ($left, $right, $right_mark);
2756 183 ▶ unless ($result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 0 183 183
2757 0 $lx->{error}= "Use of operators '$left->{value}' vs. '$right->{value}' ".
2758 "requires parentheses.";
2759 }
2760 183 return $result;
2761 }
2762  
2763 sub find_functor($$)
2764 {
2765 1111 ▶ my ($map, $kind)= @_;
Subroutine find_functor: called CC=5 SCAR=16.2
Pod undocumented
2766  
2767 return unless
2768 1111 ▶ my $functor= find_ref(%$map, $kind);
Branch: 1 branch
BranchTrueFalseTotal
unless my $functor = &find_ref(\%$map, $kind) 849 262 1111
2769  
2770 262 ▶ if (my $accept= $functor->{accept}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $accept = $functor->{"accept"}) 3 259 262
2771 3 for my $a (@$accept) {
2772 3 ▶ if ($read_dialect{$a}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read_dialect{$a}) 3 0 3
2773 3 return $functor;
2774 }
2775 }
2776 0 return;
2777 }
2778  
2779 259 return $functor;
2780 }
2781  
2782 sub set_expr_functor($$@)
2783 {
2784 257 ▶ my ($r, $functor, @arg)= @_;
Subroutine set_expr_functor: called CC=2 SCAR=7.0
Pod undocumented
2785 257 ▶ my_confess if $r->{arg};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"arg"} 0 257 257
2786  
2787 257 $r->{type}= $functor->{type};
2788 257 $r->{functor}= $functor;
2789 257 $r->{arg}= [ @arg ];
2790 }
2791  
2792 sub parse_expr_post($$$$)
2793 # $right_mark is either 0/undef, 1, or 'string', see parse_expr().
2794 {
2795 1012 ▶ my ($lx, $left, $right_mark, $arg1)= @_;
Subroutine parse_expr_post: called CC=5 SCAR=16.7
Pod undocumented
2796  
2797 # infix:
2798 1012 my $kind= $lx->{token}{kind};
2799  
2800 1012 ▶ if (my $right= find_functor(\%functor_suffix, $kind)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $right = &find_functor(\%functor_suffix, $kind)) 183 829 1012
2801 return unless
2802 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
2803  
2804 183 ▶ if ($action == ACTION_SHIFT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action == 1) 178 5 183
2805 178 lexer_shift ($lx);
2806  
2807 178 my $r= create_Expr ($lx);
2808 178 set_expr_functor ($r, $right, $arg1);
2809  
2810 switch ($right->{read_type},
2811 'infix2' => sub {
2812 # parse second arg:
2813 return unless
2814 91 ▶ my $arg2= parse_thing ($lx, get_rhs($right,0), $right, 1);
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) 1 90 91
2815 90 push @{ $r->{arg} }, $arg2;
2816 },
2817 'infix()' => sub {
2818 # parse sequence:
2819 63 ▶ my $i=0;
Subroutine __ANON__: called CC=3 SCAR=11.0
2820 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
2821 return unless
2822 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
2823 64 push @{ $r->{arg} }, $argi;
2824 } while (looking_at($lx, $kind, SHIFT)); # same operator?
2825 },
2826 'infix23' => sub {
2827 # parse second arg:
2828 return unless
2829 2 ▶ my $arg2= parse_thing ($lx, get_rhs($right,0), $right, 1);
Subroutine __ANON__: called CC=4 SCAR=18.7
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg2 = &parse_thing($lx, scalar &get_rhs($right, 0), $right, 1) 0 2 2
2830 2 push @{ $r->{arg} }, $arg2;
2831  
2832 # maybe parse third arg:
2833 2 ▶ if (looking_at ($lx, $right->{value2}, SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, $right->{"value2"}, 1)) 0 2 2
2834 return unless
2835 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
2836 0 push @{ $r->{arg} }, $arg3;
2837 }
2838 },
2839 'infix3' => sub {
2840 # parse second arg:
2841 return unless
2842 my $arg2= parse_thing ($lx, get_rhs($right,0), $right, 1)
2843 2 ▶ and expect ($lx, $right->{value2}, SHIFT)
Subroutine __ANON__: called CC=4 SCAR=17.1
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
2844 and my $arg3= parse_thing ($lx, get_rhs($right,1), $right, 1); # descend
2845  
2846 2 push @{ $r->{arg} }, $arg2, $arg3;
2847 },
2848 ▶ 'suffix' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2849 # nothing more to do
2850 }
2851 178 );
2852 178 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 1 177 178
2853  
2854 177 lock_keys %$r; # {maybe_check} may be modified if we parse WHEN clauses.
2855  
2856 177 return parse_expr_post ($lx, $left, $right_mark, $r); # descend
2857 }
2858 }
2859  
2860 834 return $arg1;
2861 }
2862  
2863 sub parse_expr($;$$)
2864 # $right_mark is either 0/undef, 1, or 'string'.
2865 # 'string' is a hack for POSITION(a IN b) and keeps parse_expr
2866 # from shifting IN. It's one of these typical design complications
2867 # in SQL grammar that prevents you from writing a straight-forward
2868 # recursive parser. If $right_mark eq 'string', then $functor
2869 # is undef. Otherwise $functor is defined if $right_mark is true.
2870 {
2871 817 ▶ my ($lx, $functor, $right_mark)= @_;
Subroutine parse_expr: called CC=3 SCAR=11.7
Pod undocumented
2872 817 my $r= create_Expr ($lx);
2873  
2874 parse_choice($lx,
2875 '.' => sub {
2876 23 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
2877 23 $r->{type}= 'column';
2878 23 $r->{arg}= parse_column ($lx);
2879 },
2880  
2881 'interpolColumn' => 'ident',
2882 'interpolTable' => 'ident',
2883 '*' => 'ident',
2884 'ident' => sub {
2885 283 ▶ $r->{type}= 'column';
Subroutine __ANON__: called CC=1 SCAR=0.0
2886 283 $r->{arg}= parse_column ($lx);
2887 },
2888  
2889 'interpolExpr' => sub {
2890 206 ▶ $r->{type}= 'interpol';
Subroutine __ANON__: called CC=1 SCAR=0.0
2891 206 $r->{token}= $lx->{token};
2892 206 lexer_shift($lx);
2893 },
2894  
2895 'interpol' => sub {
2896 173 ▶ parse_value_or_column_into ($lx, $r, 'interpol');
Subroutine __ANON__: called CC=1 SCAR=0.0
2897 },
2898  
2899 'TRUE' => '?',
2900 'FALSE' => '?',
2901 'NULL' => '?',
2902 'UNKNOWN' => '?',
2903 'DEFAULT' => '?',
2904 '?' => sub {
2905 7 ▶ $r->{type}= 'interpol';
Subroutine __ANON__: called CC=3 SCAR=11.4
2906 7 $r->{token}= $lx->{token};
2907 7 lexer_shift($lx);
2908  
2909 # special care for functors like MySQL's DEFAULT(...). Since
2910 # there's both DEFAULT and DEFAULT(...), we need to check. We
2911 # use find_functor() in order to support read_dialect properly.
2912 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
2913 my $functor= find_functor(\%functor_special, $r->{token}{kind}))
2914 {
2915 switch ($functor->{read_type},
2916 'funcall1col' => sub {
2917 return unless
2918 1 ▶ my $arg= parse_column_name($lx)
Subroutine __ANON__: called CC=3 SCAR=13.1
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
2919 and expect ($lx, ')', SHIFT);
2920 1 set_expr_functor ($r, $functor, $arg);
2921 }
2922 1 );
2923 }
2924 },
2925  
2926 'CASE' => sub {
2927 34 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=8 SCAR=22.1
2928 34 $r->{type}= 'case';
2929 34 ▶ if (looking_at($lx, ['WHEN','ELSE','END'])) { # without 'switchval'
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ['WHEN', 'ELSE', 'END'])) { } 12 22 34
2930 return unless
2931 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
2932 }
2933 else { # with switchval
2934 return unless
2935 $r->{switchval}= parse_expr($lx)
2936 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
2937 }
2938  
2939 34 ▶ if (looking_at($lx, 'ELSE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ELSE", 1)) 24 10 34
2940 return unless
2941 24 ▶ $r->{otherwise}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"otherwise"} = &parse_expr($lx) 0 24 24
2942 }
2943  
2944 return unless
2945 34 ▶ expect($lx, 'END', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "END", 1) 0 34 34
2946 },
2947  
2948 'ALL' => 'SOME',
2949 'ANY' => 'SOME',
2950 'SOME' => sub {
2951 1 ▶ if (!$functor || !$functor->{comparison} || !$right_mark) {
Subroutine __ANON__: called CC=8 SCAR=27.2
Branch: 1 branch
BranchTrueFalseTotal
unless ($functor and $functor->{"comparison"} and $right_mark) 0 1 1
Condition33%2/6
$functor and $functor->{"comparison"} and $right_mark
!ll&&!rl&&r
001
$functor and $functor->{"comparison"}
!ll&&!rl&&r
001
MC/DC0%0/3
$functor and $functor->{"comparison"} and $right_mark
$functor $functor->{"comparison"} $right_mark
Truth table25%1/4
A and B and C
A= $functorB= $functor->{"comparison"}C= $right_mark
ABCresult
0XX0
10X0
1100
1111
2952 0 $lx->{error}= "$lx->{token}{kind} can only be used directly after a comparison.";
2953 0 return;
2954 }
2955 1 my $functor2= find_functor(\%functor_special, $lx->{token}{kind});
2956 1 ▶ unless ($functor2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($functor2) 0 1 1
2957 0 $lx->{error}= "Unexpected $lx->{token}{kind} in expression.";
2958 0 return;
2959 }
2960 1 lexer_shift($lx);
2961  
2962 return unless
2963 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
2964 and my $q= parse_select_stmt ($lx)
2965 and expect($lx, ')', SHIFT);
2966  
2967 1 my $r2= create_Expr($lx);
2968 1 $r2->{type}= 'subquery';
2969 1 $r2->{arg}= $q;
2970  
2971 1 set_expr_functor ($r, $functor2, $r2);
2972 },
2973  
2974 '(' => sub {
2975 13 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=5 SCAR=16.4
2976 13 ▶ if (looking_at($lx, [@SELECT_INITIAL,'interpolStmt'])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, [@SELECT_INITIAL, 'interpolStmt'])) { } 2 11 13
2977 return unless
2978 2 ▶ my $q= parse_select_stmt ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $q = &parse_select_stmt($lx) 0 2 2
2979 2 $r->{type}= 'subquery';
2980 2 $r->{arg}= $q;
2981 }
2982 else {
2983 return unless
2984 11 ▶ my $arg= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $arg = &parse_expr($lx) 0 11 11
2985 11 $r->{type}= '()';
2986 11 $r->{arg}= $arg;
2987 }
2988 return unless
2989 13 ▶ expect($lx, ')', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, ")", 1) 0 13 13
2990 },
2991  
2992 -default => sub {
2993 77 ▶ my $functor2= find_functor(\%functor_prefix, $lx->{token}{kind});
Subroutine __ANON__: called CC=6 SCAR=19.9
2994 77 ▶ if (!$functor2 && $lx->{token}{type} eq 'keyword') { # generic funcall
Branch: 1 branch
BranchTrueFalseTotal
if (not $functor2 and $lx->{"token"}{"type"} eq "keyword") 9 68 77
Condition66%2/3
not $functor2 and $lx->{"token"}{"type"} eq "keyword"
!ll&&!rl&&r
6809
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
2995 9 $functor2= make_op($lx->{token}{kind}, 'funcall');
2996 }
2997  
2998 # prefix / funcall:
2999 77 ▶ if ($functor2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($functor2) { } 77 0 77
elsif (not $lx->{'error'}) { } 0 0 0
3000 77 set_expr_functor ($r, $functor2);
3001 77 lexer_shift($lx);
3002  
3003 switch ($functor2->{read_type},
3004 'prefix' => sub {
3005 45 ▶ my $arg;
Subroutine __ANON__: called CC=4 SCAR=14.1
3006 45 ▶ if (looking_at($lx, '(', NO_SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '(', 0)) { } 16 29 45
3007 return unless
3008 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
3009 }
3010 else {
3011 return unless
3012 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
3013 29 $r->{arg}= [ $arg ];
3014 }
3015 },
3016 'funcall' => sub {
3017 return unless
3018 25 ▶ $r->{arg}= parse_list_delim ($lx, \&parse_expr);
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"arg"} = &parse_list_delim($lx, \&SQL::Yapp::parse_expr) 0 25 25
3019 },
3020 'funcall1col' => sub {
3021 return unless
3022 1 ▶ expect ($lx, '(', SHIFT)
Subroutine __ANON__: called CC=4 SCAR=17.9
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
3023 and my $arg1= parse_column_name($lx)
3024 and expect ($lx, ')', SHIFT);
3025 1 $r->{arg}= [ $arg1 ];
3026 },
3027 'funcsep' => sub {
3028 return unless
3029 expect ($lx, '(', SHIFT)
3030 6 ▶ and parse_funcsep ($lx, $r, $functor2->{rhs});
Subroutine __ANON__: called CC=3 SCAR=14.2
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
3031 },
3032 77 );
3033 77 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 77 77
3034 }
3035 # error:
3036 elsif (! $lx->{error}) {
3037 0 $lx->{error}= "Unexpected ".token_describe($lx->{token})." in expression";
3038 }
3039  
3040 77 return;
3041 },
3042 817 );
3043 817 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 817 817
3044  
3045 817 ▶ die unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 817 817
3046 817 lock_keys %$r; # {arg} may be modified when parsing sequenced infix operators
3047 # and {maybe_check} may be modified when parsing WHEN clauses
3048  
3049 # And now parse the suffix:
3050 817 return parse_expr_post ($lx, $functor, $right_mark, $r);
3051 }
3052  
3053 sub parse_limit_num($) # Simply returns the single token if it is appropriate.
3054 {
3055 32 ▶ my ($lx)= @_;
Subroutine parse_limit_num: called CC=1 SCAR=0.0
Pod undocumented
3056 return parse_choice($lx,
3057 'interpolExpr' => 'interpol',
3058 '?' => 'interpol',
3059 'interpol' => sub {
3060 32 ▶ my $r= $lx->{token};
Subroutine __ANON__: called CC=1 SCAR=0.0
3061 32 lexer_shift($lx);
3062 32 return $r;
3063 },
3064 32 );
3065 }
3066  
3067 sub parse_expr_as($)
3068 {
3069 226 ▶ my ($lx)= @_;
Subroutine parse_expr_as: called CC=4 SCAR=13.9
Pod undocumented
3070 226 my $r= create ($lx, 'ExprAs', qw(expr as));
3071  
3072 return unless
3073 226 ▶ $r->{expr}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"expr"} = &parse_expr($lx) 1 225 226
3074  
3075 225 ▶ if (looking_at($lx, 'AS', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "AS", 1)) 4 221 225
3076 return unless
3077 4 ▶ $r->{as}= parse_column_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"as"} = &parse_column_name($lx) 0 4 4
3078 }
3079  
3080 225 lock_hash %$r;
3081 225 return $r;
3082 }
3083  
3084 sub parse_order($)
3085 {
3086 35 ▶ my ($lx)= @_;
Subroutine parse_order: called CC=2 SCAR=7.0
Pod undocumented
3087 35 my $r= create ($lx, 'Order', qw(type expr token desc));
3088 35 $r->{desc}= 0;
3089  
3090 parse_choice($lx,
3091 -default => sub {
3092 14 ▶ $r->{type}= 'expr';
Subroutine __ANON__: called CC=2 SCAR=7.2
3093 return unless
3094 14 ▶ $r->{expr}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"expr"} = &parse_expr($lx) 0 14 14
3095 },
3096  
3097 'interpolOrder' => 'interpol',
3098 'interpol' => sub {
3099 21 ▶ if ($lx->{token}{type} eq 'string') {
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{'token'}{'type'} eq 'string') { } 3 18 21
3100 # Strings are still expressions, not column names. There is no
3101 # other way of forcing Perl interpolation to String type, so
3102 # we assume a string here.
3103 3 $r->{type}= 'expr';
3104 return unless
3105 3 ▶ $r->{expr}= parse_expr($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"expr"} = &parse_expr($lx) 0 3 3
3106 }
3107 else {
3108 18 $r->{type}= 'interpol';
3109 18 $r->{token}= $lx->{token};
3110 18 lexer_shift($lx);
3111 }
3112 },
3113 35 );
3114 35 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 35 35
3115  
3116 parse_choice($lx,
3117 ▶ -default => sub {}, # no error
Subroutine __ANON__: called CC=1 SCAR=0.0
3118 2 ▶ 'ASC' => sub { lexer_shift($lx); $r->{desc}= 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
3119 10 ▶ 'DESC' => sub { lexer_shift($lx); $r->{desc}= 1; },
Subroutine __ANON__: called CC=1 SCAR=0.0
3120 35 );
3121  
3122 35 lock_hash %$r;
3123 35 return $r;
3124 }
3125  
3126 sub parse_join($)
3127 {
3128 127 ▶ my ($lx)= @_;
Subroutine parse_join: called CC=3 SCAR=11.1
Pod undocumented
3129 127 my $r= create ($lx, 'Join', qw(token table qual on using natural));
3130  
3131 #print STDERR "parse join: ".token_describe($lx->{token})."\n";
3132 parse_choice($lx,
3133 'interpolJoin' => 'interpol',
3134 'interpol' => sub {
3135 $r->{type}= 'interpol',
3136 5 ▶ $r->{token}= $lx->{token};
Subroutine __ANON__: called CC=1 SCAR=0.0
3137 5 lexer_shift($lx);
3138 },
3139  
3140 -default => sub {
3141 122 ▶ my $shifted= 0;
Subroutine __ANON__: called CC=7 SCAR=19.8
3142  
3143 122 my $want_condition= 1;
3144 122 ▶ if (looking_at($lx, 'NATURAL', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "NATURAL", 1)) 3 119 122
3145 3 $r->{natural}= 1;
3146 3 $shifted= 1;
3147 3 $want_condition= 0;
3148 }
3149  
3150 parse_choice($lx,
3151 -default => sub {
3152 113 ▶ $r->{type}= 'INNER';
Subroutine __ANON__: called CC=1 SCAR=0.0
3153 },
3154  
3155 'INNER' => sub{
3156 4 ▶ $r->{type}= 'INNER';
Subroutine __ANON__: called CC=1 SCAR=0.0
3157 4 lexer_shift($lx);
3158 4 $shifted= 1;
3159 },
3160  
3161 'UNION' => 'CROSS',
3162 'CROSS' => sub {
3163 2 ▶ if ($r->{natural}) {
Subroutine __ANON__: called CC=2 SCAR=7.9
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"natural"}) 0 2 2
3164 0 $lx->{error}= "NATURAL cannot be used with CROSS or UNION JOIN";
3165 0 return;
3166 }
3167  
3168 2 $r->{type}= lexer_shift($lx);
3169 2 $want_condition= 0;
3170 2 $shifted= 1;
3171 },
3172  
3173 'LEFT' => 'FULL',
3174 'RIGHT' => 'FULL',
3175 'FULL' => sub {
3176 3 ▶ $r->{type}= lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3177 3 looking_at($lx, 'OUTER', SHIFT);
3178 3 $shifted= 1;
3179 },
3180 122 );
3181 122 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 122 122
3182  
3183 122 ▶ unless (looking_at ($lx, 'JOIN', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looking_at($lx, "JOIN", 1)) 112 10 122
3184 112 ▶ if ($shifted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shifted) 0 112 112
3185 0 $lx->{error}= "Expected JOIN, but found ".token_describe($lx->{token});
3186 }
3187 112 $r= undef;
3188 112 return;
3189 }
3190  
3191 return unless
3192 10 ▶ $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 10 10
3193  
3194 10 ▶ if ($want_condition) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_condition) 5 5 10
3195 parse_choice($lx,
3196 'ON' => sub {
3197 3 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3198 3 $r->{on}= parse_expr($lx);
3199 },
3200 'USING' => sub {
3201 2 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.2
3202 return unless
3203 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
3204 },
3205 5 );
3206 }
3207 }
3208 127 );
3209 127 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 127 127
3210 127 ▶ return unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 112 15 127
3211  
3212 15 lock_hash %$r;
3213 15 return $r;
3214 }
3215  
3216 sub push_option($$$)
3217 {
3218 488 ▶ my ($lx, $list, $words)= @_;
Subroutine push_option: called CC=2 SCAR=6.9
Pod undocumented
3219 488 ▶ if (my $x= looking_at($lx, $words, SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = &looking_at($lx, $words, 1)) 5 483 488
3220 5 push @$list, $x;
3221 5 return $x;
3222 }
3223 483 return 0;
3224 }
3225  
3226 sub push_option_list($$$)
3227 {
3228 300 ▶ my ($lx, $list, $words)= @_;
Subroutine push_option_list: called CC=2 SCAR=6.9
Pod undocumented
3229 300 ▶ while (push_option($lx, $list, $words)) {}
Branch: 1 branch
BranchTrueFalseTotal
if (&push_option($lx, $list, $words)) 4 300 304
3230 }
3231  
3232 sub parse_where($) # WHERE is supposed to haveing been parsed already here
3233 {
3234 56 ▶ my ($lx)= @_;
Subroutine parse_where: called CC=1 SCAR=0.0
Pod undocumented
3235 # FIXME: MISSING:
3236 # - WHERE CURRENT OF (i.e., cursor support)
3237 56 return parse_expr($lx);
3238 }
3239  
3240 sub parse_select($)
3241 {
3242 180 ▶ my ($lx)= @_;
Subroutine parse_select: called CC=25 SCAR=33.9
Pod undocumented
3243 180 my $r= create ($lx, ['Stmt','Select'],
3244 qw(
3245 opt_front
3246 opt_back
3247 expr_list
3248 from
3249 join
3250 where
3251 group_by
3252 group_by_with_rollup
3253 having
3254 order_by
3255 limit_cnt
3256 limit_offset
3257 )
3258 );
3259  
3260 180 ▶ return unless expect($lx, 'SELECT', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "SELECT", 1) 0 180 180
3261  
3262 # Missing:
3263 # PostgresQL:
3264 # - DISTINCT **ON** <expr>
3265 # - WITH
3266 # - WINDOW
3267 # - FETCH
3268 # - FOR UPDATE|SHARE **OF** ( <Table> , ... )
3269 #
3270 # All:
3271 # - UNION
3272 # - INTERSECT
3273 # - EXCEPT
3274 # - FETCH [ FIRST | NEXT ] count [ ROW | ROWS ] ONLY (same as LIMIT in SQL:2008)
3275  
3276 180 $r->{opt_front}= [];
3277 push_option ($lx, $r->{opt_front}, [
3278 'DISTINCT', 'ALL',
3279 ($read_dialect{mysql} ?
3280 180 ▶ ('DISTINCTROW')
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 180 0 180
3281 : ()
3282 )
3283 ]);
3284  
3285 push_option_list ($lx, $r->{opt_front}, [
3286 ($read_dialect{mysql} ?
3287 (
3288 180 ▶ 'HIGH_PRIORITY', 'STRAIGHT_JOIN',
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 180 0 180
3289 'SQL_SMALL_RESULT', 'SQL_BIG_RESULT', 'SQL_BUFFER_RESULT',
3290 'SQL_CACHE', 'SQL_NO_CACHE', 'SQL_CALC_FOUND_ROWS'
3291 )
3292 : ()
3293 )
3294 ]);
3295  
3296 return unless
3297 180 ▶ $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 179 180
3298  
3299 179 ▶ if (looking_at($lx, 'FROM', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "FROM", 1)) 94 85 179
3300 return unless
3301 $r->{from}= parse_list([], $lx, \&parse_table_as, ',')
3302 94 ▶ 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 94 94
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
0094
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
3303  
3304 94 ▶ if (looking_at($lx, 'WHERE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "WHERE", 1)) 44 50 94
3305 return unless
3306 44 ▶ $r->{where}= parse_where ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"where"} = &parse_where($lx) 0 44 44
3307 }
3308 94 ▶ if (looking_at($lx, 'GROUP BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "GROUP BY", 1)) 6 88 94
3309 return unless
3310 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
3311  
3312 6 $r->{group_by_with_rollup}= looking_at($lx, 'WITH ROLLUP', SHIFT);
3313 }
3314 94 ▶ if (looking_at($lx, 'HAVING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "HAVING", 1)) 1 93 94
3315 return unless
3316 1 ▶ $r->{having}= parse_expr ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"having"} = &parse_expr($lx) 0 1 1
3317 }
3318 94 ▶ if (looking_at($lx, 'ORDER BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ORDER BY", 1)) 8 86 94
3319 return unless
3320 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
3321 }
3322  
3323 94 ▶ if (looking_at($lx, 'LIMIT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "LIMIT", 1)) 4 90 94
3324 4 ▶ unless (looking_at($lx, 'ALL', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&looking_at($lx, "ALL", 1)) 4 0 4
3325 4 my $first_num= parse_limit_num ($lx);
3326 4 ▶ if (looking_at($lx, ',', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ',', 1)) { } 2 2 4
3327 2 $r->{limit_offset}= $first_num;
3328 2 $r->{limit_cnt}= parse_limit_num($lx);
3329 }
3330 else {
3331 2 $r->{limit_cnt}= $first_num;
3332 }
3333 }
3334 }
3335 94 ▶ if (!$r->{limit_offset} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not $r->{"limit_offset"} and &looking_at($lx, "OFFSET", 1)) 1 93 94
Condition100%3/3
not $r->{"limit_offset"} and &looking_at($lx, "OFFSET", 1)
!ll&&!rl&&r
2911
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
3336 looking_at ($lx, 'OFFSET', SHIFT))
3337 {
3338 1 $r->{limit_offset}= parse_limit_num ($lx);
3339 }
3340  
3341 94 $r->{opt_back}= [];
3342 push_option_list ($lx, $r->{opt_back}, [
3343 ($read_dialect{mysql} || $read_dialect{postgresql} ?
3344 ('FOR UPDATE')
3345 : ()
3346 ),
3347 ($read_dialect{mysql} ?
3348 (
3349 'LOCK IN SHARE MODE' # FIXME: normalise: PostgreSQL: FOR SHARE
3350 )
3351 : ()
3352 ),
3353 ($read_dialect{postgresql} ?
3354 (
3355 94 ▶ 'FOR SHARE', # FIXME: normalise: MySQL: LOCK IN SHARE MODE
Branch: 3 branches
BranchTrueFalseTotal
$read_dialect{'mysql'} || $read_dialect{'postgresql'} ? : 94 0 94
$read_dialect{'mysql'} ? : 94 0 94
$read_dialect{'postgresql'} ? : 94 0 94
Condition33%1/3
$read_dialect{"mysql"} or $read_dialect{"postgresql"}
l!l&&r!l&&!r
9400
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
3356 'NOWAIT'
3357 )
3358 : ()
3359 ),
3360 ]);
3361 }
3362  
3363 179 lock_hash %$r;
3364 179 return $r;
3365 }
3366  
3367 sub parse_insert($)
3368 {
3369 13 ▶ my ($lx)= @_;
Subroutine parse_insert: called CC=10 SCAR=24.9
Pod undocumented
3370 13 my $r= create ($lx, ['Stmt','Insert'],
3371 qw(
3372 opt_front
3373 into
3374 column
3375 default_values
3376 value
3377 value_interpol
3378 set
3379 select
3380 duplicate_update
3381 )
3382 );
3383  
3384 13 ▶ return unless expect($lx, 'INSERT', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "INSERT", 1) 0 13 13
3385  
3386 # PostgreSQL:
3387 # - RETURNING ...
3388  
3389 13 $r->{opt_front}= [];
3390 push_option_list ($lx, $r->{opt_front}, [
3391 ($read_dialect{mysql} ?
3392 (
3393 13 ▶ 'IGNORE',
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 13 0 13
3394 'LOW_PRIORITY',
3395 'HIGH_PRIORITY',
3396 'DELAYED',
3397 )
3398 : ()
3399 )
3400 ]);
3401  
3402 13 looking_at($lx, 'INTO', SHIFT); # optional in MySQL
3403  
3404 return unless
3405 13 ▶ $r->{into}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"into"} = &parse_table($lx) 0 13 13
3406  
3407 13 ▶ if (looking_at($lx, '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "(")) 5 8 13
3408 return unless
3409 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
3410 }
3411  
3412 parse_choice($lx,
3413 'DEFAULT VALUES' => sub {
3414 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3415 0 $r->{default_values}= 1;
3416 },
3417  
3418 'VALUE' => 'VALUES',
3419 'VALUES' => sub {
3420 5 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3421 5 $r->{value}= parse_list([], $lx, \&parse_expr_list_delim, ',');
3422 },
3423  
3424 'SET' => sub {
3425 # MySQL extension, but will be normalised to VALUES clause, so we
3426 # always accept this even with !$read_dialect{mysql}.
3427 8 ▶ if ($r->{column}) {
Subroutine __ANON__: called CC=2 SCAR=8.4
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"column"}) 0 8 8
3428 0 $lx->{error}= "Either column list or 'SET' expected, but found both.";
3429 0 return;
3430 }
3431 8 lexer_shift($lx);
3432 8 $r->{set}= parse_list([], $lx, \&parse_expr, ',');
3433 },
3434  
3435 13 (map { $_ => 'interpolStmt' } @SELECT_INITIAL),
3436 'interpol' => 'interpolStmt',
3437 'interpolStmt' => sub {
3438 0 ▶ $r->{select}= parse_select_stmt($lx);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3439 },
3440 13 );
3441 13 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 13 13
3442  
3443 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
3444 looking_at ($lx, 'ON DUPLICATE KEY UPDATE', SHIFT))
3445 {
3446 return unless
3447 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
3448 }
3449  
3450 13 lock_hash %$r;
3451 13 return $r;
3452 }
3453  
3454 sub parse_update($)
3455 {
3456 9 ▶ my ($lx)= @_;
Subroutine parse_update: called CC=15 SCAR=29.8
Pod undocumented
3457 9 my $r= create ($lx, ['Stmt','Update'],
3458 qw(
3459 opt_front
3460 table
3461 set
3462 from
3463 join
3464 where
3465 order_by
3466 limit_cnt
3467 limit_offset
3468 )
3469 );
3470  
3471 9 ▶ return unless expect($lx, 'UPDATE', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "UPDATE", 1) 0 9 9
3472  
3473 # PostgreSQL:
3474 # - RETURNING ...
3475  
3476 9 $r->{opt_front}= [];
3477 push_option_list ($lx, $r->{opt_front}, [
3478 ($read_dialect{mysql} ?
3479 (
3480 'IGNORE',
3481 'LOW_PRIORITY',
3482 )
3483 : ()
3484 ),
3485 ($read_dialect{postgresql} ?
3486 (
3487 9 ▶ 'ONLY',
Branch: 2 branches
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 9 0 9
$read_dialect{'postgresql'} ? : 9 0 9
3488 )
3489 : ()
3490 )
3491 ]);
3492  
3493 return unless
3494 $r->{table}= parse_list([], $lx, \&parse_table_as, ',')
3495 and expect($lx, 'SET', SHIFT)
3496 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
3497  
3498 9 ▶ if (looking_at($lx, 'FROM', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "FROM", 1)) 1 8 9
3499 return unless
3500 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
3501 }
3502 return unless
3503 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
3504  
3505 9 ▶ if (looking_at($lx, 'WHERE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "WHERE", 1)) 9 0 9
3506 return unless
3507 9 ▶ $r->{where}= parse_where ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"where"} = &parse_where($lx) 0 9 9
3508 }
3509 9 ▶ if (looking_at($lx, 'ORDER BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ORDER BY", 1)) 1 8 9
3510 return unless
3511 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
3512 }
3513 9 ▶ if (looking_at($lx, 'LIMIT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "LIMIT", 1)) 1 8 9
3514 1 $r->{limit_cnt}= parse_limit_num($lx);
3515 }
3516  
3517 9 lock_hash %$r;
3518 9 return $r;
3519 }
3520  
3521 sub parse_delete($)
3522 {
3523 4 ▶ my ($lx)= @_;
Subroutine parse_delete: called CC=14 SCAR=29.7
Pod undocumented
3524 4 my $r= create ($lx, ['Stmt','Delete'],
3525 qw(
3526 opt_front
3527 from
3528 from_opt_front
3529 join
3530 using
3531 where
3532 order_by
3533 limit_cnt
3534 limit_offset
3535 )
3536 );
3537  
3538 4 ▶ return unless expect($lx, 'DELETE', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "DELETE", 1) 0 4 4
3539  
3540 # PostgreSQL:
3541 # - RETURNING ...
3542  
3543 4 $r->{opt_front}= [];
3544 push_option_list ($lx, $r->{opt_front}, [
3545 ($read_dialect{mysql} ?
3546 (
3547 4 ▶ 'IGNORE',
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 4 0 4
3548 'LOW_PRIORITY',
3549 'QUICK'
3550 )
3551 : ()
3552 )
3553 ]);
3554  
3555 4 ▶ return unless expect($lx, 'FROM', SHIFT);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, "FROM", 1) 0 4 4
3556  
3557 4 $r->{from_opt_front}= [];
3558 push_option ($lx, $r->{from_opt_front}, [
3559 ($read_dialect{postgresql} ?
3560 4 ▶ ('ONLY')
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'postgresql'} ? : 4 0 4
3561 : ()
3562 )
3563 ]);
3564  
3565 return unless
3566 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
3567  
3568 4 ▶ if (looking_at($lx, 'USING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "USING", 1)) 2 2 4
3569 return unless
3570 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
3571 }
3572  
3573 return unless
3574 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
3575  
3576 4 ▶ if (looking_at($lx, 'WHERE', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "WHERE", 1)) 3 1 4
3577 return unless
3578 3 ▶ $r->{where}= parse_where ($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"where"} = &parse_where($lx) 0 3 3
3579 }
3580 4 ▶ if (looking_at($lx, 'ORDER BY', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "ORDER BY", 1)) 0 4 4
3581 return unless
3582 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
3583 }
3584 4 ▶ if (looking_at($lx, 'LIMIT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "LIMIT", 1)) 0 4 4
3585 0 $r->{limit_cnt}= parse_limit_num($lx);
3586 }
3587  
3588 4 lock_hash %$r;
3589 4 return $r;
3590 }
3591  
3592 sub keyword($$)
3593 {
3594 1 ▶ my ($lx, $keyword)= @_;
Subroutine keyword: called CC=3 SCAR=11.2
Pod undocumented
3595 return
3596 1 ▶ unless $keyword;
Branch: 1 branch
BranchTrueFalseTotal
unless $keyword 0 1 1
3597  
3598 1 ▶ return $keyword
Branch: 1 branch
BranchTrueFalseTotal
if ref $keyword 0 1 1
3599 if ref($keyword);
3600
3601 1 my $r= create($lx, 'Keyword', qw(keyword));
3602 1 $r->{keyword}= $keyword;
3603 1 lock_hash %$r;
3604 1 return $r;
3605 }
3606  
3607 sub parse_index_option($)
3608 {
3609 1 ▶ my ($lx)= @_;
Subroutine parse_index_option: called CC=3 SCAR=14.2
Pod undocumented
3610 1 my $r= create($lx, 'IndexOption', qw(arg));
3611  
3612 parse_choice($lx,
3613 -default => sub {
3614 1 ▶ $r= undef;
Subroutine __ANON__: called CC=1 SCAR=0.0
3615 },
3616  
3617 # MySQL does not like it here, but only accepts it in front of the
3618 # column list, which is against the manual's description.
3619 #'USING' => sub {
3620 # lexer_shift($lx);
3621 # return unless
3622 # my $t= expect($lx, ['BTREE','HASH','RTREE'], SHIFT);
3623 # $r->{type}= 'using';
3624 # $r->{arg}= $t;
3625 #},
3626 1 );
3627 1 ▶ return unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 1 0 1
3628 0 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 0 0
3629  
3630 0 lock_hash %$r;
3631 0 return $r;
3632 }
3633  
3634 sub parse_index_type ($)
3635 {
3636 3 ▶ my ($lx)= @_;
Subroutine parse_index_type: called CC=2 SCAR=6.9
Pod undocumented
3637 3 ▶ if (looking_at($lx, 'USING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "USING", 1)) 1 2 3
3638 1 return expect($lx, ['BTREE','HASH','RTREE'], SHIFT);
3639 }
3640 2 return;
3641 }
3642  
3643 sub parse_table_constraint($)
3644 {
3645 3 ▶ my ($lx)= @_;
Subroutine parse_table_constraint: called CC=5 SCAR=24.3
Pod undocumented
3646 3 my $r= create($lx, "TableConstraint", qw(constraint index_type column index_option reference));
3647 3 $r->{index_option}= [];
3648  
3649 3 ▶ if (looking_at($lx, 'CONSTRAINT', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "CONSTRAINT", 1)) 3 0 3
3650 return unless
3651 3 ▶ $r->{constraint}= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"constraint"} = &parse_constraint($lx) 0 3 3
3652 }
3653  
3654 parse_choice($lx,
3655 'PRIMARY KEY' => sub {
3656 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=3 SCAR=24.8
3657 0 $r->{type}= 'primary_key';
3658 0 $r->{index_type}= parse_index_type($lx);
3659 return unless
3660 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3661 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
3662 },
3663 'UNIQUE' => sub {
3664 1 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=3 SCAR=12.0
3665 1 $r->{type}= 'unique';
3666 1 $r->{index_type}= parse_index_type($lx);
3667 return unless
3668 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3669 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
3670 },
3671 'FULLTEXT' => sub {
3672 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=3 SCAR=24.8
3673 0 $r->{type}= 'fulltext';
3674 0 $r->{index_type}= parse_index_type($lx);
3675 return unless
3676 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3677 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
3678 },
3679 'SPATIAL' => sub {
3680 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=3 SCAR=24.8
3681 0 $r->{type}= 'spatial';
3682 0 $r->{index_type}= parse_index_type($lx);
3683 return unless
3684 $r->{column}= parse_list_delim($lx, \&parse_column_index)
3685 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
3686 },
3687 'FOREIGN KEY' => sub {
3688 2 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=3 SCAR=12.0
3689 2 $r->{type}= 'foreign_key';
3690 2 $r->{index_type}= parse_index_type($lx);
3691 return unless
3692 $r->{column}= parse_list_delim($lx, \&parse_column_name)
3693 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
3694 },
3695 # 'CHECK' => sub {
3696 # },
3697 ($read_dialect{mysql} ?
3698 (
3699 'INDEX' => sub {
3700 0 ▶ lexer_shift($lx);
Subroutine __ANON__: not called CC=2 SCAR=17.9
3701 0 $r->{type}= 'index';
3702 # FIXME: mysql allows an index name here
3703 return unless
3704 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
3705 0 $r->{index_option}= parse_try_list([], $lx, \&parse_index_option);
3706 }
3707 )
3708 3 ▶ : ()
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 3 0 3
3709 ),
3710 );
3711 3 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 3 3
3712  
3713 3 lock_hash %$r;
3714 3 return $r;
3715 }
3716  
3717 sub parse_table_option1($$$$)
3718 {
3719 6 ▶ my ($lx, $r, $name, $parse)= @_;
Subroutine parse_table_option1: called CC=3 SCAR=11.0
Pod undocumented
3720 6 $r->{type}= 'literal';
3721 6 $r->{name}= $name;
3722 6 lexer_shift($lx);
3723 6 looking_at($lx, '=', SHIFT); # optional =
3724 return unless
3725 6 ▶ $r->{value}= $parse->($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"value"} = &$parse($lx) 0 6 6
3726 6 ▶ while (looking_at($lx, ',', SHIFT)) {} # optional ,
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ",", 1)) 1 6 7
3727 6 return $r;
3728 }
3729  
3730 sub parse_on_commit_action($)
3731 {
3732 1 ▶ my ($lx)= @_;
Subroutine parse_on_commit_action: called CC=2 SCAR=7.2
Pod undocumented
3733 return keyword ($lx,
3734 expect($lx,
3735 [
3736 'PRESERVE ROWS',
3737 'DELETE ROWS',
3738 ($read_dialect{postgresql} ?
3739 (
3740 1 ▶ 'DROP'
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'postgresql'} ? : 1 0 1
3741 )
3742 : ()
3743 )
3744 ],
3745 SHIFT
3746 )
3747 );
3748 }
3749  
3750 sub parse_table_option($)
3751 {
3752 12 ▶ my ($lx)= @_;
Subroutine parse_table_option: called CC=4 SCAR=14.0
Pod undocumented
3753 12 my $r= create($lx, 'TableOption', qw(name value token));
3754  
3755 parse_choice($lx,
3756 -default => sub {
3757 4 ▶ $r= undef;
Subroutine __ANON__: called CC=1 SCAR=0.0
3758 },
3759  
3760 ($read_dialect{mysql} ?
3761 (
3762 'ENGINE' => sub {
3763 2 ▶ return parse_table_option1($lx, $r, 'ENGINE', \&parse_engine);
Subroutine __ANON__: called CC=1 SCAR=0.0
3764 },
3765
3766 'CHARACTER SET' => 'DEFAULT CHARACTER SET',
3767 'DEFAULT CHARACTER SET' => sub {
3768 2 ▶ return parse_table_option1($lx, $r, 'DEFAULT CHARACTER SET', \&parse_charset);
Subroutine __ANON__: called CC=1 SCAR=0.0
3769 },
3770  
3771 'COLLATE' => 'DEFAULT COLLATE',
3772 'DEFAULT COLLATE' => sub {
3773 0 ▶ return parse_table_option1($lx, $r, 'DEFAULT COLLATE', \&parse_collate);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3774 },
3775  
3776 'AUTO_INCREMENT' => sub {
3777 0 ▶ return parse_table_option1($lx, $r, 'AUTO_INCREMENT', \&parse_expr);
Subroutine __ANON__: not called CC=1 SCAR=6.9
3778 },
3779  
3780 'COMMENT' => sub {
3781 1 ▶ return parse_table_option1($lx, $r, 'COMMENT', \&parse_expr);
Subroutine __ANON__: called CC=1 SCAR=0.0
3782 },
3783 )
3784 : ()
3785 ),
3786  
3787 'ON COMMIT' => sub {
3788 1 ▶ return parse_table_option1($lx, $r, 'ON COMMIT', \&parse_on_commit_action);
Subroutine __ANON__: called CC=1 SCAR=0.0
3789 },
3790  
3791 'interpolTableOption' => 'interpol',
3792 'interpol' => sub {
3793 2 ▶ $r->{type}= 'interpol';
Subroutine __ANON__: called CC=2 SCAR=6.9
3794 2 $r->{token}= $lx->{token};
3795 2 lexer_shift($lx);
3796 2 ▶ while (looking_at($lx, ',', SHIFT)) {} # optional ,
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, ",", 1)) 1 2 3
3797 2 return $r;
3798 },
3799 12 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 12 0 12
3800 12 ▶ return unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 4 8 12
3801 8 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 8 8
3802 8 lock_hash %$r;
3803 8 return $r;
3804 }
3805  
3806 sub parse_column_def($)
3807 {
3808 6 ▶ my ($lx)= @_;
Subroutine parse_column_def: called CC=3 SCAR=11.8
Pod undocumented
3809 6 my $r= create($lx, 'ColumnDef', qw(name column_spec));
3810 return unless
3811 $r->{name}= parse_column_name($lx)
3812 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
3813 6 lock_hash %$r;
3814 6 return $r;
3815 }
3816  
3817 sub parse_column_def_or_option($)
3818 {
3819 6 ▶ my ($lx)= @_;
Subroutine parse_column_def_or_option: called CC=1 SCAR=0.0
Pod undocumented
3820 return parse_choice($lx,
3821 'interpol' => 'ident',
3822 'ident' => sub {
3823 4 ▶ return parse_column_def($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3824 },
3825 -default => sub {
3826 2 ▶ return parse_table_constraint($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3827 },
3828 6 );
3829 }
3830  
3831 sub parse_create_table($)
3832 {
3833 2 ▶ my ($lx)= @_;
Subroutine parse_create_table: called CC=13 SCAR=27.6
Pod undocumented
3834 return unless
3835 2 ▶ expect($lx, \@CREATE_TABLE_INITIAL);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, \@CREATE_TABLE_INITIAL) 0 2 2
3836  
3837 2 my $r= create($lx, ['Stmt','CreateTable'],
3838 qw(subtype if_not_exists table column_def tabconstr tableopt select));
3839 2 $r->{subtype}= lexer_shift($lx);
3840  
3841 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
3842 looking_at($lx, 'IF NOT EXISTS', SHIFT))
3843 {
3844 1 $r->{if_not_exists}= 1;
3845 }
3846  
3847 return unless
3848 2 ▶ $r->{table}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_table($lx) 0 2 2
3849  
3850 2 $r->{column_def}= [];
3851 2 $r->{tabconstr}= [];
3852 2 ▶ if (looking_at($lx, '(')) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, "(")) 2 0 2
3853 return unless
3854 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
3855  
3856 2 $r->{column_def}= [ grep { $_->{kind} eq 'ColumnDef' } @$spec ];
3857 2 $r->{tabconstr}= [ grep { $_->{kind} ne 'ColumnDef' } @$spec ];
3858 }
3859  
3860 return unless
3861 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
3862  
3863 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
3864 looking_at($lx, \@SELECT_INITIAL))
3865 {
3866 return unless
3867 1 ▶ $r->{select}= parse_select($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"select"} = &parse_select($lx) 0 1 1
3868 }
3869  
3870 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
3871 0 $lx->{error}= 'Either query or at least one column expected';
3872 0 return;
3873 }
3874  
3875 2 lock_hash %$r;
3876 2 return $r;
3877 }
3878  
3879 sub parse_drop_table($)
3880 {
3881 1 ▶ my ($lx)= @_;
Subroutine parse_drop_table: called CC=5 SCAR=17.0
Pod undocumented
3882 return unless
3883 1 ▶ expect($lx, \@DROP_TABLE_INITIAL);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, \@DROP_TABLE_INITIAL) 0 1 1
3884  
3885 1 my $r= create($lx, ['Stmt','DropTable'],
3886 qw(subtype if_exists table cascade));
3887 1 $r->{subtype}= lexer_shift($lx);
3888  
3889 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
3890 looking_at($lx, 'IF EXISTS', SHIFT))
3891 {
3892 1 $r->{if_exists}= 1;
3893 }
3894  
3895 return unless
3896 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
3897  
3898 1 $r->{cascade}= looking_at($lx, ['RESTRICT','CASCADE'], SHIFT);
3899  
3900 1 lock_hash %$r;
3901 1 return $r;
3902 }
3903  
3904 sub parse_column_pos_perhaps($)
3905 {
3906 3 ▶ my ($lx)= @_;
Subroutine parse_column_pos_perhaps: called CC=1 SCAR=0.0
Pod undocumented
3907 return parse_choice($lx,
3908 -default => sub {
3909 1 ▶ return;
Subroutine __ANON__: called CC=1 SCAR=0.0
3910 },
3911 'FIRST' => sub {
3912 1 ▶ return lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3913 },
3914 'AFTER' => sub {
3915 1 ▶ lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3916 1 return ('AFTER', parse_column_name($lx));
3917 },
3918 3 );
3919 }
3920  
3921 sub parse_alter_table($)
3922 {
3923 20 ▶ my ($lx)= @_;
Subroutine parse_alter_table: called CC=5 SCAR=16.6
Pod undocumented
3924 return unless
3925 20 ▶ expect($lx, \@ALTER_TABLE_INITIAL);
Branch: 1 branch
BranchTrueFalseTotal
unless &expect($lx, \@ALTER_TABLE_INITIAL) 0 20 20
3926  
3927 20 my $r= create($lx, ['Stmt','AlterTable'],
3928 qw(subtype functor subfunctor arg online ignore table only));
3929 20 $r->{subtype}= lexer_shift($lx);
3930 20 $r->{arg}= [];
3931  
3932 return unless
3933 20 ▶ $r->{table}= parse_table($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"table"} = &parse_table($lx) 0 20 20
3934  
3935 20 $r->{only}= looking_at($lx, 'ONLY', SHIFT);
3936  
3937 parse_choice($lx,
3938 'DROP CONSTRAINT' => sub {
3939 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.0
3940 return unless
3941 1 ▶ my $constraint= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $constraint = &parse_constraint($lx) 0 1 1
3942 1 push @{ $r->{arg} }, $constraint, looking_at($lx, ['RESTRICT','CASCADE'], SHIFT);
3943 },
3944  
3945 'DROP COLUMN' => sub {
3946 3 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.0
3947 return unless
3948 3 ▶ my $column= parse_column_name($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $column = &parse_column_name($lx) 0 3 3
3949 3 push @{ $r->{arg} }, $column, looking_at($lx, ['RESTRICT','CASCADE'], SHIFT);
3950 },
3951  
3952 'RENAME COLUMN' => sub {
3953 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=4 SCAR=16.4
3954  
3955 return unless
3956 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
3957 and expect($lx, 'TO', SHIFT)
3958 and my $column2= parse_column_name($lx);
3959  
3960 1 push @{ $r->{arg} }, $column, 'TO', $column2;
3961 },
3962  
3963 'DROP PRIMARY KEY' => sub {
3964 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3965 },
3966  
3967 'ALTER COLUMN' => sub {
3968 6 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=3 SCAR=11.0
3969 6 push @{ $r->{arg} }, parse_column_name($lx);
3970 6 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 6 6
3971  
3972 parse_choice($lx,
3973 'DROP DEFAULT' => 'SET NOT NULL',
3974 'DROP NOT NULL' => 'SET NOT NULL',
3975 'SET NOT NULL' => sub {
3976 3 ▶ push @{ $r->{arg} }, lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3977 },
3978  
3979 'SET DEFAULT' => sub {
3980 1 ▶ push @{ $r->{arg} }, lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
3981 1 push @{ $r->{arg} }, parse_expr($lx);
3982 },
3983  
3984 ($read_dialect{postgresql} ?
3985 (
3986 'TYPE' => sub {
3987 2 ▶ push @{ $r->{arg} }, lexer_shift($lx);
Subroutine __ANON__: called CC=3 SCAR=11.0
3988 2 push @{ $r->{arg} }, parse_type($lx);
3989 2 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 2 2
3990 2 ▶ if (my $x= looking_at($lx, 'USING', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = &looking_at($lx, "USING", 1)) 1 1 2
3991 1 push @{ $r->{arg} }, $x, parse_expr($lx);
3992 }
3993 }
3994 )
3995 6 ▶ : ()
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'postgresql'} ? : 6 0 6
3996 ),
3997 );
3998 },
3999  
4000 'RENAME TO' => sub {
4001 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
4002 1 push @{ $r->{arg} }, parse_table($lx);
4003 },
4004  
4005 'ADD COLUMN' => sub {
4006 2 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=5 SCAR=16.6
4007 2 ▶ if (looking_at($lx, '(', SHIFT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looking_at($lx, '(', 1)) { } 1 1 2
4008 1 push @{ $r->{arg} }, parse_list([], $lx, \&parse_column_def, ',');
4009 1 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 1 1
4010 1 expect($lx, ')', SHIFT);
4011 }
4012 else {
4013 return unless
4014 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
4015 and my $spec= parse_column_spec($lx);
4016 1 push @{ $r->{arg} }, $col1, $spec, parse_column_pos_perhaps($lx);
4017 }
4018 },
4019  
4020 'ADD' => sub {
4021 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=1 SCAR=0.0
4022 1 push @{ $r->{arg} }, parse_table_constraint($lx);
4023 },
4024  
4025 ($read_dialect{mysql} ?
4026 (
4027 'MODIFY COLUMN' => sub {
4028 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=3 SCAR=12.0
4029 return unless
4030 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
4031 and my $spec= parse_column_spec($lx);
4032 1 push @{ $r->{arg} }, $col1, $spec, parse_column_pos_perhaps($lx);
4033 },
4034 'CHANGE COLUMN' => sub {
4035 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=4 SCAR=16.4
4036 return unless
4037 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
4038 and my $col2= parse_column_name($lx)
4039 and my $spec= parse_column_spec($lx);
4040 1 push @{ $r->{arg} }, $col1, $col2, $spec, parse_column_pos_perhaps($lx);
4041 },
4042 'DROP FOREIGN KEY' => sub { # standard SQL: DROP CONSTRAINT
4043 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.0
4044 return unless
4045 1 ▶ my $constraint= parse_constraint($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $constraint = &parse_constraint($lx) 0 1 1
4046 1 push @{ $r->{arg} }, $constraint;
4047 },
4048 'DROP INDEX' => sub {
4049 1 ▶ $r->{functor}= lexer_shift($lx);
Subroutine __ANON__: called CC=2 SCAR=7.0
4050 return unless
4051 1 ▶ my $index= parse_index($lx);
Branch: 1 branch
BranchTrueFalseTotal
unless my $index = &parse_index($lx) 0 1 1
4052 1 push @{ $r->{arg} }, $index;
4053 },
4054 )
4055 20 ▶ : ()
Branch: 1 branch
BranchTrueFalseTotal
$read_dialect{'mysql'} ? : 20 0 20
4056 ),
4057 );
4058 20 ▶ return if $lx->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $lx->{"error"} 0 20 20
4059  
4060 20 lock_hash %$r;
4061 20 return $r;
4062 }
4063  
4064 sub parse_stmt_interpol($)
4065 {
4066 3 ▶ my ($lx)= @_;
Subroutine parse_stmt_interpol: called CC=5 SCAR=20.0
Pod undocumented
4067  
4068 # Some interpols will never be good statements, so issue an error as early
4069 # as possible (i.e., at compile time instead of at runtime):
4070 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
4071 $lx->{token}{type} eq 'string')
4072 {
4073 0 $lx->{error}= "Expected 'Stmt', but found $lx->{token}{type}";
4074 0 return;
4075 }
4076  
4077 3 ▶ if (! $lx->{token}{type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lx->{"token"}{"type"}) 0 3 3
4078 0 $lx->{error}= "Expected 'Stmt', but found $lx->{token}{kind}";
4079 0 return;
4080 }
4081  
4082 3 ▶ if ($lx->{token}{perltype} eq 'hash') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{"token"}{"perltype"} eq "hash") 0 3 3
4083 0 $lx->{error}= "Expected scalar or array, but found $lx->{token}{perltype}.";
4084 0 return;
4085 }
4086  
4087 # But some may be:
4088 3 my $r= create ($lx, ['Stmt','Interpol'], qw(token));
4089 3 $r->{token}= $lx->{token};
4090 3 lexer_shift($lx);
4091  
4092 3 lock_hash %$r;
4093 3 return $r;
4094 }
4095  
4096 sub parse_select_stmt($)
4097 {
4098 6 ▶ my ($lx)= @_;
Subroutine parse_select_stmt: called CC=1 SCAR=0.2
Pod undocumented
4099 return parse_choice($lx,
4100 6 ▶ 'SELECT' => sub { parse_select ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4101  
4102 'interpolStmt' => 'interpol',
4103 0 ▶ 'interpol' => sub { parse_stmt_interpol ($lx) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4104 6 );
4105 }
4106  
4107 sub parse_stmt($)
4108 {
4109 225 ▶ my ($lx)= @_;
Subroutine parse_stmt: called CC=1 SCAR=0.0
Pod undocumented
4110 return parse_choice($lx,
4111 173 ▶ 'SELECT' => sub { parse_select ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4112 13 ▶ 'INSERT' => sub { parse_insert ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4113 9 ▶ 'UPDATE' => sub { parse_update ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4114 4 ▶ 'DELETE' => sub { parse_delete ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4115  
4116 1350 (map { $_ => 'CREATE TABLE' } @CREATE_TABLE_INITIAL),
4117 2 ▶ 'CREATE TABLE' => sub { parse_create_table($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4118  
4119 450 (map { $_ => 'DROP TABLE' } @DROP_TABLE_INITIAL),
4120 1 ▶ 'DROP TABLE' => sub { parse_drop_table($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4121  
4122 1350 (map { $_ => 'ALTER TABLE' } @ALTER_TABLE_INITIAL),
4123 20 ▶ 'ALTER TABLE' => sub { parse_alter_table($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4124  
4125 'interpolStmt' => 'interpol',
4126 3 ▶ 'interpol' => sub { parse_stmt_interpol ($lx) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4127 225 );
4128 }
4129  
4130 ######################################################################
4131 # Perl generation:
4132  
4133  
4134 ## First: creating a list of strings.
4135 #
4136 # The str_ family implements a simple concatenator for strings. The goal
4137 # is to generate a list of literal strings and Perl code generating strings,
4138 # separated by commas. For appending such things to the list, there is
4139 # str_append_str() and str_append_perl(), resp. E.g.:
4140 #
4141 # my $s= str_new();
4142 # str_append_str ($s, "a");
4143 # str_append_perl ($s, "b");
4144 #
4145 # This would result in the following string:
4146 #
4147 # 'a',b
4148 #
4149 # Appending the comma separator is done automatically.
4150 #
4151 # Further, we need to keep track of the line number. So there is a function
4152 # str_target_line() for setting the target line number for the next string
4153 # or raw perl code that is appended. Appending the necessary newline
4154 # characters is done automatically by the str_ functions.
4155 #
4156 # Finally, we need to generate substrings by joining them. This is done
4157 # with the str_append_join() and str_append_end() functions. E.g.
4158 #
4159 # my $s= str_new();
4160 # str_append_str ($s, 'a');
4161 # str_append_join ($s, sep => ':');
4162 # str_append_perl ($s, 'b');
4163 # str_target_line ($s, 2);
4164 # str_append_str ($s, 'c');
4165 # str_append_end ($s);
4166 # str_append_perl ($s, 'd');
4167 #
4168 # This results in the following string in $s:
4169 #
4170 # 'a',join(':',b,
4171 # 'c'),d
4172 #
4173 # Another possible sub-list structure is a map, which can be added with
4174 # str_append_map() ... str_append_en() functions. E.g.:
4175 #
4176 # str_append_str ($s, 'a');
4177 # str_append_map ($s, '$_." DESC"');
4178 # str_append_perl ($s, 'b');
4179 # str_append_str ($s, 'c');
4180 # str_append_end ($s);
4181 # str_append_perl ($s, 'd');
4182 #
4183 # This results in:
4184 #
4185 # 'a',(map{$_." DESC"} b,'c'),d
4186 #
4187 # A str_append_min1() ... str_append_end() block checks that there
4188 # is at least one result in the enclosed list. This, together with
4189 # _max1_if_scalar, are slightly inefficient and should later be eliminated
4190 # if possible.
4191 #
4192 # str_get_string() returns the current string as composed so far. If the
4193 # string is empty, an empty list () is returned instead, because the
4194 # empty string is not a valid syntactic empty list in Perl, so it causes
4195 # problems, e.g. after map:
4196 #
4197 # (map {...} -->HERE<--)
4198 #
4199 # If we insert an empty string -->HERE<--, then we get a syntax error.
4200 #
4201 # The implementation of the str_ family is very straightforward: we have a
4202 # current state that is updated and a string that is appended to accordingly.
4203 sub str_new($)
4204 {
4205 278 ▶ my ($line_start)= @_;
Subroutine str_new: called CC=1 SCAR=0.0
Pod undocumented
4206 278 my $text= [];
4207 278 my $s= {
4208 buff => '',
4209 need_comma => 0,
4210 line_is => 1,
4211 line_target => 1,
4212 line_start => $line_start,
4213 end_str => [], # final str to push, if defined
4214 };
4215 278 lock_keys %$s; # poor-man's bless()
4216 278 return $s;
4217 }
4218  
4219 sub str_append_raw($$)
4220 {
4221 11636 ▶ my ($s, $text)= @_;
Subroutine str_append_raw: called CC=1 SCAR=0.0
Pod undocumented
4222 11636 $s->{buff}.= $text;
4223 11636 $s->{line_is}+= ($text =~ tr/\n//);
4224 }
4225  
4226 sub str_sync_line($)
4227 {
4228 5808 ▶ my ($s)= @_;
Subroutine str_sync_line: called CC=2 SCAR=6.9
Pod undocumented
4229 5808 ▶ while ($s->{line_is} < $s->{line_target}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"line_is"} < $s->{"line_target"}) 309 5808 6117
4230 309 str_append_raw ($s, "\n");
4231 }
4232 }
4233 sub str_target_line($$)
4234 {
4235 2834 ▶ my ($s, $n)= @_;
Subroutine str_target_line: called CC=2 SCAR=7.1
Pod undocumented
4236 2834 ▶ my_confess "undefined line number" unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 2834 2834
4237 2834 $s->{line_target}= $n;
4238 }
4239  
4240 sub str_append_comma($)
4241 {
4242 7388 ▶ my ($s)= @_;
Subroutine str_append_comma: called CC=2 SCAR=6.9
Pod undocumented
4243 7388 ▶ if ($s->{need_comma}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{"need_comma"}) 3792 3596 7388
4244 3792 str_append_raw ($s, COMMA_STR);
4245 3792 $s->{need_comma}= 0;
4246 }
4247 }
4248  
4249 sub str_append_perl($$)
4250 {
4251 4347 ▶ my ($s, $perl)= @_;
Subroutine str_append_perl: called CC=2 SCAR=7.0
Pod undocumented
4252 4347 ▶ if ($perl ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($perl ne "") 4347 0 4347
4253 4347 str_append_comma($s);
4254 4347 str_sync_line ($s);
4255 4347 str_append_raw ($s, $perl);
4256 4347 $s->{need_comma}= 1;
4257 }
4258 }
4259  
4260 sub str_append_str($$)
4261 {
4262 2628 ▶ my ($s, $contents)= @_;
Subroutine str_append_str: called CC=1 SCAR=0.0
Pod undocumented
4263 2628 str_append_perl ($s, quote_perl($contents));
4264 }
4265  
4266 sub str_append_join($%)
4267 {
4268 764 ▶ my ($s, %opt)= @_;
Subroutine str_append_join: called CC=16 SCAR=27.8
Pod undocumented
4269 764 ▶ $opt{prefix}||= '';
Condition100%2/2
$opt{"prefix"} ||= ""
l!l
380384
MC/DC100%1/1
$opt{"prefix"} ||= ""
$opt{"prefix"}
Truth table100%2/2
A
A= $opt{"prefix"}
Aresult
11
00
4270 764 ▶ $opt{suffix}||= '';
Condition100%2/2
$opt{"suffix"} ||= ""
l!l
42722
MC/DC100%1/1
$opt{"suffix"} ||= ""
$opt{"suffix"}
Truth table100%2/2
A
A= $opt{"suffix"}
Aresult
11
00
4271 764 ▶ $opt{sep}||= '';
Condition100%2/2
$opt{"sep"} ||= ""
l!l
407357
MC/DC100%1/1
$opt{"sep"} ||= ""
$opt{"sep"}
Truth table100%2/2
A
A= $opt{"sep"}
Aresult
11
00
4272  
4273 764 str_append_comma($s);
4274 764 str_sync_line ($s);
4275 764 ▶ if ($opt{joinfunc}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($opt{'joinfunc'}) { } 94 670 764
elsif ($opt{'prefix'} eq '' and $opt{'suffix'} eq '' and $opt{'never_empty'} || defined $opt{'result0'} && $opt{'result0'} eq '') { } 254 416 670
elsif ($opt{'sep'} eq '' and $opt{'never_empty'} || defined $opt{'result0'} && $opt{'result0'} eq $opt{'prefix'} . $opt{'suffix'}) { } 21 395 416
4276 # special case: ignore all other settings
4277 94 str_append_raw ($s, "$opt{joinfunc}(");
4278 94 $s->{need_comma}= 0;
4279 94 push @{ $s->{end_str} }, undef;
4280 }
4281 ▶ 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
38036254
$opt{"prefix"} eq "" and $opt{"suffix"} eq ""
!ll&&!rl&&r
3800290
$opt{"never_empty"} or defined $opt{"result0"} and $opt{"result0"} eq ""
l!l&&r!l&&!r
2441036
defined $opt{"result0"} and $opt{"result0"} eq ""
!ll&&!rl&&r
36010
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
4282 $opt{suffix} eq '' &&
4283 (
4284 $opt{never_empty} ||
4285 (defined $opt{result0} && $opt{result0} eq '')
4286 ))
4287 {
4288 # simple case 1
4289 254 str_append_raw ($s, 'join(');
4290 254 str_append_str ($s, $opt{sep});
4291 254 $s->{need_comma}= 1;
4292 254 push @{ $s->{end_str} }, undef;
4293 }
4294 ▶ 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
394121
$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
4295 (
4296 $opt{never_empty} ||
4297 (defined $opt{result0} && $opt{result0} eq $opt{prefix}.$opt{suffix})
4298 ))
4299 {
4300 # simple case 2
4301 21 str_append_raw ($s, 'join(');
4302 21 str_append_str ($s, '');
4303  
4304 21 ▶ if($opt{prefix} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"prefix"} ne "") 21 0 21
4305 21 str_append_str ($s, $opt{prefix});
4306 }
4307  
4308 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
4309 }
4310 else {
4311 # complex case:
4312 395 str_append_raw ($s, __PACKAGE__.'::joinlist(');
4313 395 str_append_perl ($s, $s->{line_target} + $s->{line_start});
4314 # Unfortunately, Perl's caller() is often imprecise for the
4315 # generated code, and I couldn't find a cause for that to avoid
4316 # that. So the original line number is passed long for
4317 # nicer error messages if necessary.
4318 395 str_append_comma($s);
4319 395 str_append_str ($s, $opt{result0});
4320 395 str_append_comma($s);
4321 395 str_append_str ($s, $opt{prefix});
4322 395 str_append_comma($s);
4323 395 str_append_str ($s, $opt{sep});
4324 395 str_append_comma($s);
4325 395 str_append_str ($s, $opt{suffix});
4326 395 $s->{need_comma}= 1;
4327 395 push @{ $s->{end_str} }, undef;
4328 }
4329 }
4330  
4331 sub str_append_map($$)
4332 {
4333 173 ▶ my ($s,$code)= @_;
Subroutine str_append_map: called CC=1 SCAR=0.0
Pod undocumented
4334 173 str_append_comma($s);
4335 173 str_sync_line ($s);
4336 173 str_append_raw ($s, "(map{ $code } ");
4337 173 $s->{need_comma}= 0;
4338 173 push @{ $s->{end_str} }, undef;
4339 }
4340  
4341 sub str_append_funcall_begin($$$)
4342 {
4343 523 ▶ my ($s, $func, $in_list)= @_;
Subroutine str_append_funcall_begin: called CC=2 SCAR=6.9
Pod undocumented
4344 523 str_append_comma($s);
4345 523 str_sync_line ($s);
4346 523 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 277 246 523
4347 277 str_append_raw ($s, "(map { $func(");
4348 }
4349 else {
4350 246 str_append_raw ($s, "$func(");
4351 }
4352 523 $s->{need_comma}= 0;
4353 523 push @{ $s->{end_str} }, undef;
4354 }
4355  
4356 sub str_append_funcall_end($$)
4357 {
4358 523 ▶ my ($s, $in_list)= @_;
Subroutine str_append_funcall_end: called CC=2 SCAR=6.9
Pod undocumented
4359 523 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) 277 246 523
4360 277 str_append_perl ($s, '$_');
4361 277 str_append_raw ($s, ') }');
4362 277 $s->{need_comma}= 0;
4363 }
4364 }
4365  
4366 sub str_append_funcall($$$)
4367 {
4368 445 ▶ my ($s, $code, $in_list)= @_;
Subroutine str_append_funcall: called CC=1 SCAR=0.0
Pod undocumented
4369 445 str_append_funcall_begin ($s, $code, $in_list);
4370 445 str_append_funcall_end ($s, $in_list);
4371 }
4372  
4373 sub str_append_end($)
4374 # Terminator for:
4375 # str_append_map
4376 # str_append_funcall
4377 # str_append_join
4378 {
4379 1450 ▶ my ($s)= @_;
Subroutine str_append_end: called CC=2 SCAR=6.9
Pod undocumented
4380 1450 my $end_str= pop @{ $s->{end_str} };
4381 1450 ▶ if (defined $end_str) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $end_str) 18 1432 1450
4382 18 str_append_str($s, $end_str);
4383 }
4384 1450 str_append_raw ($s, ')');
4385 1450 $s->{need_comma}= 1;
4386 }
4387  
4388 sub str_get_string($)
4389 {
4390 275 ▶ my ($s)= @_;
Subroutine str_get_string: called CC=2 SCAR=7.1
Pod undocumented
4391 275 ▶ return '()' if $s->{buff} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"buff"} eq "" 0 275 275
4392 275 return $s->{buff};
4393 }
4394  
4395 # Now start appending more complex things:
4396  
4397 sub str_append_thing($$$$);
4398  
4399 sub str_append_list($$$;%)
4400 # If you know the list is non-empty, please specify never_empty => 1
4401 # so str_append_join() can optimise.
4402 {
4403 354 ▶ my ($str, $list, $parens, %opt)= @_;
Subroutine str_append_list: called CC=5 SCAR=16.1
Pod undocumented
4404 354 local $SIG{__DIE__}= \&my_confess;
4405  
4406 # set line to first element (if any):
4407 354 ▶ if (scalar(@$list)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list) 354 0 354
4408 354 str_target_line ($str, $list->[0]{line});
4409 }
4410  
4411 # joining, delimiters, result if empty:
4412 str_append_join($str,
4413 sep => defined $opt{sep} ? $opt{sep} : COMMA_STR, # waiting for Perl 5.10: //
4414 prefix => $opt{prefix},
4415 suffix => $opt{suffix},
4416 result0 => $opt{result0},
4417 354 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'sep'} ? : 2 352 354
4418  
4419 # map?
4420 354 ▶ if (my $x= $opt{map}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $opt{"map"}) 1 353 354
4421 1 str_append_comma ($str);
4422 1 str_sync_line ($str);
4423 1 str_append_raw ($str, "map{$x} ");
4424 1 $str->{need_comma}= 0;
4425 };
4426  
4427 # the list:
4428 354 for my $l (@$list) {
4429 428 str_append_thing ($str, $l, IN_LIST, $parens);
4430 }
4431  
4432 # end:
4433 352 str_append_end($str);
4434 }
4435  
4436 sub interpol_set_context ($$);
4437  
4438 sub perl_val($$$)
4439 {
4440 1056 ▶ my ($token, $ctxt, $allow)= @_;
Subroutine perl_val: called CC=3 SCAR=11.6
Pod undocumented
4441  
4442 my_confess "Expected ".(english_or \&quote_perl, $allow).", but found '$token->{kind}'"
4443 if $allow &&
4444 1056 ▶ scalar(grep { $token->{kind} eq $_ } flatten($allow)) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $allow and scalar grep({$token->{"kind"} eq $_;} &flatten($allow)) == 0 0 1056 1056
Condition66%2/3
$allow and scalar grep({$token->{"kind"} eq $_;} &flatten($allow)) == 0
!ll&&!rl&&r
1024320
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
4445  
4446 return switch($token->{kind},
4447 526 ▶ 'ident' => sub { quote_perl($token->{value}) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4448 9 ▶ '*' => sub { __PACKAGE__.'::ASTERISK' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4449 2 ▶ '?' => sub { __PACKAGE__.'::QUESTION' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4450 2 ▶ 'NULL' => sub { __PACKAGE__.'::NULL' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4451 1 ▶ 'TRUE' => sub { __PACKAGE__.'::TRUE' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4452 0 ▶ 'FALSE' => sub { __PACKAGE__.'::FALSE' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4453 0 ▶ 'UNKNOWN' => sub { __PACKAGE__.'::UNKNOWN' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4454 1 ▶ 'DEFAULT' => sub { __PACKAGE__.'::DEFAULT' },
Subroutine __ANON__: called CC=1 SCAR=0.0
4455 -default => sub {
4456 515 ▶ if ($token->{kind} =~ /^interpol/) {
Subroutine __ANON__: called CC=2 SCAR=8.1
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{'kind'} =~ /^interpol/) { } 515 0 515
4457 515 return interpol_set_context ($token->{value}, $ctxt);
4458 }
4459 else {
4460 0 my_confess "No idea how to print thing in Perl: ".token_describe($token);
4461 }
4462 }
4463 1056 );
4464 }
4465  
4466 sub perl_val_list($$$)
4467 {
4468 43 ▶ my ($token, $ctxt, $allow)= @_;
Subroutine perl_val_list: called CC=2 SCAR=6.9
Pod undocumented
4469 43 my $s= perl_val($token, $ctxt, $allow);
4470  
4471 43 ▶ if ($token->{perltype} eq 'hash') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{'perltype'} eq 'hash') { } 9 34 43
4472 9 return "sort keys $s";
4473 }
4474 else {
4475 34 return $s;
4476 }
4477 }
4478  
4479 sub token_pos($)
4480 {
4481 3 ▶ my ($token)= @_;
Subroutine token_pos: called CC=1 SCAR=0.0
Pod undocumented
4482 3 return "$token->{lx}{file}:".($token->{line} + $token->{lx}{line_start});
4483 }
4484  
4485 sub lx_pos($)
4486 {
4487 2 ▶ my ($lx)= @_;
Subroutine lx_pos: called CC=1 SCAR=0.0
Pod undocumented
4488 2 return "$lx->{file}:".($lx->{line} + $lx->{line_start});
4489 }
4490  
4491 sub croak_unless_scalar($)
4492 {
4493 861 ▶ my ($token)= @_;
Subroutine croak_unless_scalar: called CC=3 SCAR=11.1
Pod undocumented
4494 die token_pos($token).": ".
4495 "Error: Scalar context, embedded Perl must not be syntactic array or hash.\n"
4496 861 ▶ if $token->{perltype} eq 'array' || $token->{perltype} eq 'hash';
Branch: 1 branch
BranchTrueFalseTotal
if $token->{"perltype"} eq "array" or $token->{"perltype"} eq "hash" 3 858 861
Condition66%2/3
$token->{"perltype"} eq "array" or $token->{"perltype"} eq "hash"
l!l&&r!l&&!r
30858
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
4497 }
4498  
4499 sub str_append_typed($$$$$%)
4500 {
4501 474 ▶ my ($str, $callback, $ctxt, $thing, $in_list, %opt)= @_;
Subroutine str_append_typed: called CC=6 SCAR=17.9
Pod undocumented
4502 474 my $q_val= perl_val ($thing->{token}, $ctxt, undef);
4503  
4504 474 ▶ if (!$in_list ||
Branch: 2 branches
BranchTrueFalseTotal
if (not $in_list or $thing->{'token'}{'perltype'} eq 'scalar') { } 358 116 474
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
207151116
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
4505 $thing->{token}{perltype} eq 'scalar')
4506 {
4507 358 croak_unless_scalar ($thing->{token});
4508 356 str_append_perl ($str, __PACKAGE__."::${callback}($q_val)");
4509 }
4510 elsif ($thing->{token}{perltype} eq 'hash') {
4511 19 ▶ if ($opt{hash}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt{'hash'}) { } 16 3 19
elsif ($opt{'hashkeys'}) { } 3 0 3
4512 16 str_append_perl ($str, __PACKAGE__."::${callback}_hash($q_val)");
4513 }
4514 elsif ($opt{hashkeys}) {
4515 3 str_append_map ($str, __PACKAGE__."::${callback}(\$_)");
4516 3 str_append_perl ($str, "sort keys $q_val");
4517 3 str_append_end ($str);
4518 }
4519 else {
4520 0 die token_pos($thing->{token}).": Error: Hashes are not allowed here.\n";
4521 }
4522 }
4523 else {
4524 97 str_append_map ($str, __PACKAGE__."::${callback}(\$_)");
4525 97 str_append_perl ($str, $q_val);
4526 97 str_append_end ($str);
4527 }
4528 }
4529  
4530 sub is_multicol($);
4531 sub is_multicol($)
4532 {
4533 510 ▶ my ($thing) = @_;
Subroutine is_multicol: called CC=1 SCAR=0.0
Pod undocumented
4534 return switch ($thing->{kind},
4535 'ExprAs' => sub{
4536 165 ▶ return is_multicol($thing->{expr});
Subroutine __ANON__: called CC=1 SCAR=0.0
4537 },
4538 'Expr' => sub {
4539 165 ▶ if ($thing->{type} eq 'column') {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"type"} eq "column") 90 75 165
4540 90 return is_multicol($thing->{arg});
4541 }
4542 75 return 0;
4543 },
4544 'Column' => sub {
4545 90 ▶ return is_multicol($thing->{ident_chain}[-1]);
Subroutine __ANON__: called CC=1 SCAR=0.0
4546 },
4547 '*' => sub {
4548 4 ▶ return 1;
Subroutine __ANON__: called CC=1 SCAR=0.0
4549 },
4550 'interpol' => sub {
4551 21 ▶ return $thing->{perltype} ne 'scalar';
Subroutine __ANON__: called CC=1 SCAR=0.0
4552 },
4553 -default => sub {
4554 65 ▶ return 0;
Subroutine __ANON__: called CC=1 SCAR=0.0
4555 },
4556 510 );
4557 }
4558  
4559 # Contexts for the different sql{...} interpolation blocks:
4560 5 my %ident_context= (
4561 'Column' => {
4562 1 => [ 'Column' ],
4563 2 => [ 'Table', 'none' ],
4564 },
4565 );
4566  
4567 sub str_append_ident_chain($$$@)
4568 {
4569 509 ▶ my ($str, $in_list, $family, @token)= @_;
Subroutine str_append_ident_chain: called CC=10 SCAR=23.1
Pod undocumented
4570 509 my $func= lc($family);
4571  
4572 509 ▶ my $ctxt= $ident_context{$family}{scalar @token} ||
Branch: 1 branch
BranchTrueFalseTotal
scalar @token == 1 ? : 177 11 188
Condition66%2/3
$ident_context{$family}{scalar @token} || (scalar @token == 1 ? [$family] : [map('none', 1 .. scalar @token)])
l!l&&r!l&&!r
3211880
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
4573 (scalar(@token) == 1 ?
4574 [ $family ]
4575 : [ map 'none', 1..scalar(@token) ]
4576 );
4577  
4578 509 my $n= scalar(@token);
4579 509 my @non_scalar_i= grep { $token[$_]{perltype} ne 'scalar' } 0..$n-1;
4580  
4581 509 ▶ if (!$in_list ||
Branch: 2 branches
BranchTrueFalseTotal
if (not $in_list or scalar @non_scalar_i == 0) { } 470 39 509
elsif (scalar @non_scalar_i == 1) { } 35 4 39
Condition100%3/3
not $in_list or scalar @non_scalar_i == 0
l!l&&r!l&&!r
16630439
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
4582 scalar(@non_scalar_i) == 0)
4583 {
4584 470 for my $a (@token) { croak_unless_scalar ($a); }
4585 my $q_vals= join(",",
4586 map
4587 469 { perl_val($token[$_], $ctxt->[$_], undef) }
4588 0..$n-1
4589 );
4590 469 str_append_perl ($str, __PACKAGE__."::${func}${n}($q_vals)");
4591 }
4592 elsif (scalar(@non_scalar_i) == 1) {
4593 str_append_map ($str,
4594 __PACKAGE__."::${func}${n}(".
4595 join(",",
4596 map {
4597 35 ▶ ($token[$_]{perltype} eq 'scalar' ?
Branch: 1 branch
BranchTrueFalseTotal
$token[$_]{'perltype'} eq 'scalar' ? : 5 35 40
4598 perl_val($token[$_], $ctxt->[$_], undef)
4599 : '$_'
4600 )
4601 }
4602 0..$n-1
4603 ).
4604 ")"
4605 );
4606 35 my ($i)= @non_scalar_i;
4607 35 str_append_perl ($str, perl_val_list($token[$i], $ctxt->[$i], undef));
4608 35 str_append_end ($str);
4609 }
4610 else {
4611 4 ▶ my $f_ident= "${func}${n}_".join('', map{ $_->{perltype} eq 'scalar' ? 1 : 'n' } @token);
Branch: 1 branch
BranchTrueFalseTotal
$_->{'perltype'} eq 'scalar' ? : 0 8 8
4612 str_append_perl ($str,
4613 __PACKAGE__."::$f_ident(".
4614 join(",",
4615 map {
4616 4 ▶ ($token[$_]{perltype} eq 'scalar' ?
Branch: 1 branch
BranchTrueFalseTotal
$token[$_]{'perltype'} eq 'scalar' ? : 0 8 8
4617 perl_val($token[$_], $ctxt->[$_], undef)
4618 : '['.perl_val_list($token[$_], $ctxt->[$_], undef).']'
4619 )
4620 }
4621 0..$n-1
4622 ).
4623 ")"
4624 );
4625 }
4626 }
4627  
4628 sub str_append_limit ($$$)
4629 {
4630 106 ▶ my ($str, $limit_cnt, $limit_offset)= @_;
Subroutine str_append_limit: called CC=5 SCAR=16.2
Pod undocumented
4631  
4632 106 ▶ if (defined $limit_cnt || defined $limit_offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit_cnt or defined $limit_offset) 5 101 106
Condition66%2/3
defined $limit_cnt or defined $limit_offset
l!l&&r!l&&!r
50101
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
4633 5 my $limit_cnt_str= 'undef';
4634 5 ▶ if ($limit_cnt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit_cnt) 5 0 5
4635 5 $limit_cnt_str= perl_val($limit_cnt, 'Expr', ['interpol', 'interpolExpr', '?']);
4636 }
4637  
4638 5 my $limit_offset_str= 'undef';
4639 5 ▶ if ($limit_offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit_offset) 3 2 5
4640 3 $limit_offset_str= perl_val($limit_offset, 'Expr', ['interpol', 'interpolExpr', '?']);
4641 }
4642  
4643 5 str_append_perl ($str, __PACKAGE__."::limit($limit_cnt_str, $limit_offset_str)");
4644 }
4645 }
4646  
4647 sub str_append_parens($$$)
4648 {
4649 18 ▶ my ($str, $thing, $in_list)= @_;
Subroutine str_append_parens: called CC=2 SCAR=8.1
Pod undocumented
4650 18 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 0 18 18
4651 0 str_append_map ($str, "\"(\$_)\"");
4652 0 str_append_thing ($str, $thing, $in_list, NO_PARENS);
4653 0 str_append_end ($str);
4654 }
4655 else {
4656 18 str_append_join ($str, prefix => '(', suffix => ')', never_empty => 1);
4657 18 str_append_thing ($str, $thing, $in_list, NO_PARENS);
4658 18 str_append_end ($str);
4659 }
4660 }
4661  
4662 sub str_append_table_key($$$)
4663 {
4664 3 ▶ my ($str, $thing, $type)= @_;
Subroutine str_append_table_key: called CC=5 SCAR=16.1
Pod undocumented
4665 3 str_append_join ($str, sep => ' ');
4666 3 ▶ if (my $x= $thing->{constraint}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"constraint"}) 3 0 3
4667 3 str_append_str ($str, 'CONSTRAINT');
4668 3 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4669 }
4670 3 str_append_str ($str, $type);
4671 3 ▶ if (my $x= $thing->{index_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"index_type"}) 1 2 3
4672 1 str_append_str ($str, "USING $x");
4673 }
4674 3 str_append_list ($str, $thing->{column}, NO_PARENS, prefix=>'(', suffix=>')');
4675 3 for my $o (@{ $thing->{index_option} }) {
4676 0 str_append_thing ($str, $o, IN_LIST, NO_PARENS);
4677 }
4678 3 ▶ if (my $x= $thing->{reference}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"reference"}) 2 1 3
4679 2 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4680 }
4681 3 str_append_end ($str);
4682 }
4683  
4684 # str_append_thing() converts a recursive representation of the parsed SQL
4685 # structure into a Perl string that generates a list of either string
4686 # representations of the SQL structure (in good SQL syntax), or blessed
4687 # objects of the correct type.
4688 #
4689 # The result of this function is then used to wrap and bless the string
4690 # or objects appropriately according to which kind of SQL structure the
4691 # string contains (statement, expressions, column, etc.).
4692 #
4693 # In detail, str_append_thing() appends pieces of Perl code to $str, that
4694 # each represent a small piece of the SQL command.
4695 #
4696 # Each invocation of str_append_thing appends code to $str that generates
4697 # exactly the amount of objects that are represented. This might seem
4698 # obvious, but since $str is actually a comma separated list, this
4699 # requirement means that if multiple pieces are pushed for a single
4700 # thing, then a join(...) must enclose and group these. E.g.
4701 # the code that generates a SELECT statement from scratch appends
4702 # several pieces of code to $str, and to make only one string, a
4703 # join() is generated.
4704 #
4705 sub str_append_thing($$$$)
4706 {
4707 2820 ▶ my ($str, $thing, $in_list, $parens)= @_;
Subroutine str_append_thing: called CC=4 SCAR=14.6
Pod undocumented
4708 2820 local $SIG{__DIE__}= \&my_confess;
4709  
4710 # simple things to append:
4711 2820 ▶ unless (defined $thing) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $thing) 16 2804 2820
4712 16 str_append_perl ($str, 'undef');
4713 16 return;
4714 }
4715 2804 ▶ unless (ref $thing) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $thing) 380 2424 2804
4716 380 str_append_str ($str, $thing);
4717 380 return;
4718 }
4719 2424 ▶ if (ref($thing) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing eq "ARRAY") 1 2423 2424
4720 1 str_append_list ($str, $thing, NO_PARENS, prefix => '(', suffix => ')');
4721 1 return;
4722 }
4723  
4724 # normal structure:
4725 2423 str_target_line ($str, $thing->{line});
4726  
4727 switch($thing->{kind},
4728 'Stmt' => sub {
4729 switch($thing->{type},
4730 'Select' => sub {
4731 # find out type name depending on number of columns:
4732 118 ▶ my $type_name = 'SelectStmt';
Subroutine __ANON__: called CC=12 SCAR=25.1
4733 118 ▶ if (scalar(@{ $thing->{expr_list} }) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$thing->{"expr_list"};} == 1) 114 4 118
4734 114 ▶ unless (is_multicol($thing->{expr_list}[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&is_multicol($thing->{"expr_list"}[0])) 98 16 114
4735 98 $type_name = 'SelectStmtSingle';
4736 }
4737 }
4738  
4739 # generate:
4740 118 str_append_funcall ($str, __PACKAGE__.'::'.$type_name.'->obj', $in_list);
4741 118 str_append_join ($str, never_empty => 1);
4742  
4743 str_append_list ($str, $thing->{expr_list}, NO_PARENS,
4744 prefix => join(' ', 'SELECT',
4745 118 @{ $thing->{opt_front} }
4746 ).' '
4747 );
4748  
4749 116 ▶ if (my $x= $thing->{from}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"from"}) 85 31 116
4750 85 str_append_list ($str, $x, NO_PARENS, prefix => ' FROM ');
4751  
4752 85 ▶ if (my $x= $thing->{join}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"join"}) 85 0 85
4753 85 ▶ if (@$x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x) 3 82 85
4754 3 str_append_map ($str, '" $_" ');
4755 3 for my $xi (@$x) {
4756 3 str_append_thing ($str, $xi, IN_LIST, NO_PARENS);
4757 }
4758 3 str_append_end ($str);
4759 }
4760 }
4761 85 ▶ if (my $x= $thing->{where}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"where"}) 42 43 85
4762 42 str_target_line ($str, $x->{line});
4763 42 str_append_str ($str, ' WHERE ');
4764 42 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4765 }
4766 84 ▶ if (my $x= $thing->{group_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"group_by"}) 4 80 84
4767 4 my $suffix= '';
4768 4 ▶ if ($thing->{group_by_with_rollup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"group_by_with_rollup"}) 0 4 4
4769 0 $suffix= ' WITH ROLLUP';
4770 }
4771 4 str_append_list ($str, $x, NO_PARENS,
4772 prefix => ' GROUP BY ',
4773 suffix => $suffix,
4774 result0 => '',
4775 );
4776 }
4777 84 ▶ if (my $x= $thing->{having}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"having"}) 0 84 84
4778 0 str_target_line ($str, $x->{line});
4779 0 str_append_str ($str, ' HAVING ');
4780 0 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4781 }
4782 84 ▶ if (my $x= $thing->{order_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"order_by"}) 5 79 84
4783 5 str_append_list ($str, $x, NO_PARENS,
4784 prefix => ' ORDER BY ',
4785 result0 => ''
4786 );
4787 }
4788 84 str_append_limit ($str, $thing->{limit_cnt}, $thing->{limit_offset});
4789  
4790 84 str_append_str ($str, join('', map " $_", @{ $thing->{opt_back} }));
4791 }
4792  
4793 115 str_append_end ($str);
4794 115 str_append_end ($str);
4795 },
4796 'Delete' => sub {
4797 1 ▶ str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
Subroutine __ANON__: called CC=7 SCAR=19.9
4798 1 str_append_join ($str, never_empty => 1);
4799  
4800 str_append_list ($str, $thing->{from}, NO_PARENS,
4801 prefix =>
4802 join(' ',
4803 'DELETE',
4804 1 @{ $thing->{opt_front} },
4805 'FROM',
4806 1 @{ $thing->{from_opt_front} },
4807 ).' '
4808 );
4809  
4810 1 ▶ if (my $x= $thing->{using}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"using"}) 1 0 1
4811 1 str_append_list ($str, $x, NO_PARENS,
4812 prefix => ' USING ',
4813 result0 => ''
4814 );
4815 }
4816  
4817 1 ▶ if (my $x= $thing->{join}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"join"}) 1 0 1
4818 1 ▶ if (@$x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x) 1 0 1
4819 1 str_append_map ($str, '" $_" ');
4820 1 for my $xi (@$x) {
4821 2 str_append_thing ($str, $xi, IN_LIST, NO_PARENS);
4822 }
4823 1 str_append_end ($str);
4824 }
4825 }
4826 1 ▶ if (my $x= $thing->{where}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"where"}) 1 0 1
4827 1 str_target_line ($str, $x->{line});
4828 1 str_append_str ($str, ' WHERE ');
4829 1 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4830 }
4831 1 ▶ if (my $x= $thing->{order_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"order_by"}) 0 1 1
4832 0 str_append_list ($str, $x, NO_PARENS,
4833 prefix => ' ORDER BY ',
4834 result0 => ''
4835 );
4836 }
4837 1 str_append_limit ($str, $thing->{limit_cnt}, $thing->{limit_offset});
4838  
4839 1 str_append_end ($str);
4840 1 str_append_end ($str);
4841 },
4842 'Insert' => sub {
4843 11 ▶ str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
Subroutine __ANON__: called CC=8 SCAR=23.6
4844 11 str_append_join ($str, never_empty => 1);
4845  
4846 str_append_str ($str,
4847 join(' ',
4848 'INSERT',
4849 11 @{ $thing->{opt_front} },
4850 'INTO',
4851 ).' '
4852 );
4853  
4854 11 str_append_thing ($str, $thing->{into}, NOT_IN_LIST, NO_PARENS);
4855  
4856 11 ▶ if (my $col= $thing->{column}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $col = $thing->{"column"}) 4 7 11
4857 4 str_append_list ($str, $col, NO_PARENS, prefix => ' (', suffix => ')');
4858 }
4859
4860 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
4861 4 str_append_str ($str, ' VALUES ');
4862 4 str_append_list ($str, $val, NO_PARENS);
4863 }
4864 elsif (my $set= $thing->{set}) {
4865 7 str_append_funcall ($str, __PACKAGE__."::set2values", NOT_IN_LIST);
4866 7 for my $l (@$set) {
4867 11 str_append_thing ($str, $l, IN_LIST, NO_PARENS);
4868 }
4869 7 str_append_end ($str);
4870 }
4871 elsif (my $sel= $thing->{select}) {
4872 0 str_append_str ($str, ' ');
4873 0 str_append_thing ($str, $sel, NOT_IN_LIST, NO_PARENS);
4874 }
4875 elsif ($thing->{default_values}) {
4876 0 str_append_str ($str, ' DEFAULT VALUES');
4877 }
4878 else {
4879 0 die;
4880 }
4881  
4882 11 ▶ if (my $x= $thing->{duplicate_update}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"duplicate_update"}) 0 11 11
4883 0 str_append_str ($str, ' ON DUPLICATE KEY UPDATE ');
4884 0 str_append_list ($str, $x, NO_PARENS, map => __PACKAGE__.'::assign($_)');
4885 }
4886  
4887 11 str_append_end ($str);
4888 11 str_append_end ($str);
4889 },
4890 'Update' => sub {
4891 8 ▶ str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
Subroutine __ANON__: called CC=8 SCAR=23.6
4892 8 str_append_join ($str, never_empty => 1);
4893  
4894 str_append_list ($str, $thing->{table}, NO_PARENS,
4895 prefix => join(' ', 'UPDATE',
4896 8 @{ $thing->{opt_front} }
4897 ).' '
4898 );
4899  
4900 8 ▶ if (my $x= $thing->{from}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"from"}) 0 8 8
4901 0 str_append_list ($str, $x, NO_PARENS,
4902 prefix => ' FROM ',
4903 result0 => ''
4904 );
4905 }
4906 8 ▶ if (my $x= $thing->{join}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"join"}) 8 0 8
4907 8 ▶ if (@$x) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$x) 0 8 8
4908 0 str_append_map ($str, '" $_" ');
4909 0 for my $xi (@$x) {
4910 0 str_append_thing ($str, $xi, IN_LIST, NO_PARENS);
4911 }
4912 0 str_append_end ($str);
4913 }
4914 }
4915 8 ▶ if (my $x= $thing->{set}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"set"}) 8 0 8
4916 8 str_append_list ($str, $x, NO_PARENS,
4917 prefix => ' SET ',
4918 result0 => '' # this is an error.
4919 );
4920 }
4921 8 ▶ if (my $x= $thing->{where}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"where"}) 8 0 8
4922 8 str_target_line ($str, $x->{line});
4923 8 str_append_str ($str, ' WHERE ');
4924 8 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4925 }
4926 8 ▶ if (my $x= $thing->{order_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"order_by"}) 0 8 8
4927 0 str_append_list ($str, $x, NO_PARENS,
4928 prefix => ' ORDER BY ',
4929 result0 => ''
4930 );
4931 }
4932 8 str_append_limit ($str, $thing->{limit_cnt}, $thing->{limit_offset});
4933  
4934 8 str_append_end ($str);
4935 8 str_append_end ($str);
4936 },
4937 'CreateTable' => sub {
4938 1 ▶ str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
Subroutine __ANON__: called CC=3 SCAR=11.4
4939 1 str_append_join ($str, never_empty => 1);
4940  
4941 1 str_append_str ($str, "$thing->{subtype} ");
4942 1 ▶ if ($thing->{if_not_exists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"if_not_exists"}) 0 1 1
4943 0 str_append_str ($str, 'IF NOT EXISTS ');
4944 }
4945 1 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
4946  
4947 my @tabspec= (
4948 1 @{ $thing->{column_def} },
4949 1 @{ $thing->{tabconstr} }
4950 );
4951 1 str_append_list ($str, \@tabspec, NO_PARENS,
4952 result0 => '',
4953 prefix => ' (',
4954 suffix => ')'
4955 );
4956  
4957 1 str_append_list ($str, $thing->{tableopt}, NO_PARENS,
4958 result0 => '',
4959 prefix => ' ',
4960 sep => ' ',
4961 );
4962  
4963 1 ▶ if (my $x= $thing->{select}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"select"}) 0 1 1
4964 0 str_append_str ($str, ' AS ');
4965 0 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
4966 }
4967  
4968 1 str_append_end ($str);
4969 1 str_append_end ($str);
4970 },
4971 'DropTable' => sub {
4972 0 ▶ str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
Subroutine __ANON__: not called CC=3 SCAR=24.8
4973 0 str_append_join ($str, never_empty => 1);
4974  
4975 0 str_append_str ($str, "$thing->{subtype} ");
4976 0 ▶ if ($thing->{if_exists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"if_exists"}) 0 0 0
4977 0 str_append_str ($str, 'IF EXISTS ');
4978 }
4979 0 str_append_list ($str, $thing->{table}, NO_PARENS);
4980  
4981 0 ▶ if (my $x= $thing->{cascade}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{"cascade"}) 0 0 0
4982 0 str_append_str ($str, " $x");
4983 }
4984 0 str_append_end ($str);
4985 0 str_append_end ($str);
4986 },
4987 'AlterTable' => sub {
4988 0 ▶ str_append_funcall ($str, __PACKAGE__.'::Stmt->obj', $in_list);
Subroutine __ANON__: not called CC=3 SCAR=24.8
4989 0 str_append_join ($str, never_empty => 1);
4990  
4991 0 str_append_str ($str, "$thing->{subtype} ");
4992 0 ▶ if ($thing->{only}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"only"}) 0 0 0
4993 0 str_append_str ($str, 'ONLY ');
4994 }
4995 0 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
4996  
4997 0 str_append_join ($str, sep => ' ', prefix => ' ');
4998 0 for my $l ($thing->{functor}, @{ $thing->{arg} }) {
4999 0 str_append_thing ($str, $l, NOT_IN_LIST, NO_PARENS);
5000 }
5001 0 str_append_end ($str);
5002  
5003 0 str_append_end ($str);
5004 0 str_append_end ($str);
5005 },
5006 'Interpol' => sub {
5007 2 ▶ str_append_typed ($str, 'stmt', 'Stmt', $thing, $in_list);
Subroutine __ANON__: called CC=1 SCAR=0.0
5008 },
5009 141 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5010 },
5011  
5012 'TableOption' => sub {
5013 switch ($thing->{type},
5014 'interpol' => sub {
5015 1 ▶ str_append_typed ($str, 'tableopt', 'TableOption', $thing, $in_list);
Subroutine __ANON__: called CC=1 SCAR=0.0
5016 },
5017 'literal' => sub {
5018 2 ▶ str_append_join ($str, sep => ' ');
Subroutine __ANON__: called CC=1 SCAR=0.0
5019 2 str_append_str ($str, $thing->{name});
5020 2 str_append_thing ($str, $thing->{value}, NOT_IN_LIST, NO_PARENS);
5021 2 str_append_end ($str);
5022 }
5023 3 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5024 },
5025  
5026 'Keyword' => sub {
5027 0 ▶ str_append_str ($str, $thing->{keyword});
Subroutine __ANON__: not called CC=1 SCAR=6.9
5028 },
5029  
5030 'Join' => sub {
5031 9 ▶ if ($thing->{type} eq 'interpol') {
Subroutine __ANON__: called CC=6 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'type'} eq 'interpol') { } 3 6 9
5032 3 str_append_typed ($str, 'joinclause', 'Join', $thing, $in_list);
5033 }
5034 else {
5035 6 str_append_join ($str, result0 => '');
5036  
5037 6 ▶ if ($thing->{natural}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'natural'}) { } 2 4 6
5038 2 ▶ if ($thing->{type} eq 'INNER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'type'} eq 'INNER') { } 2 0 2
5039 2 str_append_str ($str, "NATURAL JOIN ");
5040 }
5041 else {
5042 0 str_append_str ($str, "NATURAL $thing->{type} JOIN ");
5043 }
5044 }
5045 else {
5046 4 str_append_str ($str, "$thing->{type} JOIN ");
5047 }
5048  
5049 6 str_append_list ($str, $thing->{table}, NO_PARENS);
5050  
5051 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
5052 1 str_append_str ($str, ' ON ');
5053 1 str_append_thing ($str, $on, NOT_IN_LIST, NO_PARENS);
5054 }
5055 elsif (my $using= $thing->{using}) {
5056 1 str_append_str ($str, ' USING (');
5057 1 str_append_list ($str, $using, NO_PARENS);
5058 1 str_append_str ($str, ')');
5059 };
5060  
5061 6 str_append_end ($str);
5062 }
5063 },
5064  
5065 'Table' => 'Column',
5066 'CharSet' => 'Column',
5067 'Collate' => 'Column',
5068 'Index' => 'Column',
5069 'Constraint' => 'Column',
5070 'Transliteration' => 'Column',
5071 'Transcoding' => 'Column',
5072 'Engine' => 'Column',
5073 'Column' => sub {
5074 355 ▶ str_append_ident_chain ($str, $in_list, $thing->{kind}, @{ $thing->{ident_chain} });
Subroutine __ANON__: called CC=1 SCAR=0.0
5075 },
5076  
5077 'TableAs' => sub {
5078 102 ▶ if (my $x= $thing->{as}) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{'as'}) { } 1 101 102
5079 1 str_append_join ($str, sep => ' AS ', never_empty => 1);
5080 1 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
5081 1 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
5082 1 str_append_end ($str);
5083 }
5084 else {
5085 101 str_append_thing ($str, $thing->{table}, $in_list, NO_PARENS);
5086 }
5087 },
5088  
5089 'ExprAs' => sub {
5090 123 ▶ if (my $x= $thing->{as}) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $thing->{'as'}) { } 3 120 123
5091 3 str_append_join ($str, sep => ' AS ', never_empty => 1);
5092 3 str_append_thing ($str, $thing->{expr}, NOT_IN_LIST, NO_PARENS);
5093 2 str_append_thing ($str, $x, NOT_IN_LIST, NO_PARENS);
5094 2 str_append_end ($str);
5095 }
5096 else {
5097 120 str_append_thing ($str, $thing->{expr}, $in_list, $parens);
5098 }
5099 },
5100 'Order' => sub {
5101 switch($thing->{type},
5102 'interpol' => sub {
5103 9 ▶ if ($thing->{desc}) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'desc'}) { } 3 6 9
5104 3 str_append_typed ($str, 'desc', 'Order', $thing, $in_list, hashkeys => 1);
5105 }
5106 else {
5107 6 str_append_typed ($str, 'asc', 'Order', $thing, $in_list, hashkeys => 1);
5108 }
5109 },
5110 'expr' => sub {
5111 8 ▶ if ($thing->{desc}) {
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{'desc'}) { } 4 4 8
5112 4 str_append_map ($str, __PACKAGE__.'::desc($_)');
5113 4 str_append_thing ($str, $thing->{expr}, $in_list, NO_PARENS);
5114 4 str_append_end ($str);
5115 }
5116 else {
5117 4 str_append_thing ($str, $thing->{expr}, $in_list, NO_PARENS);
5118 }
5119 },
5120 17 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5121 },
5122 'TypeList' => sub {
5123 switch($thing->{type},
5124 'interpol' => sub {
5125 0 ▶ str_append_typed ($str, 'typelist', 'Type', $thing, $in_list);
Subroutine __ANON__: not called CC=1 SCAR=6.9
5126 },
5127  
5128 'explicit' => sub {
5129 0 ▶ str_append_list ($str, $thing->{arg}, NO_PARENS, prefix => '(', suffix => ')');
Subroutine __ANON__: not called CC=1 SCAR=6.9
5130 # may not be empty!
5131 },
5132 0 ▶ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
5133 },
5134 'Type' => sub {
5135 switch ($thing->{type},
5136 'interpol' => sub {
5137 6 ▶ str_append_typed ($str, 'type', 'Type', $thing, $in_list);
Subroutine __ANON__: called CC=1 SCAR=0.0
5138 },
5139 'base' => sub {
5140 9 ▶ str_append_perl ($str, __PACKAGE__.'::Type->new()');
Subroutine __ANON__: called CC=1 SCAR=0.0
5141 },
5142 15 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5143 },
5144 'TypePost' => sub {
5145 23 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 23 23
5146 if $parens;
5147  
5148 23 str_append_funcall_begin ($str, __PACKAGE__.'::type_'.$thing->{functor}, $in_list);
5149 23 for my $arg (@{ $thing->{arg} }) {
5150 25 str_append_thing ($str, $arg, NOT_IN_LIST, NO_PARENS);
5151 }
5152 23 str_append_funcall_end ($str, $in_list);
5153 23 str_append_thing ($str, $thing->{base}, $in_list, NO_PARENS);
5154 23 str_append_end ($str);
5155 },
5156 'ColumnDef' => sub {
5157 1 ▶ str_append_join ($str, sep => ' ');
Subroutine __ANON__: called CC=1 SCAR=0.0
5158 1 str_append_thing ($str, $thing->{name}, NOT_IN_LIST, NO_PARENS);
5159 1 str_append_thing ($str, $thing->{column_spec}, NOT_IN_LIST, NO_PARENS);
5160 1 str_append_end ($str);
5161 },
5162  
5163 'ColumnSpec' => sub {
5164 switch ($thing->{type},
5165 'interpol' => sub {
5166 2 ▶ str_append_typed ($str, 'colspec', 'ColumnSpec', $thing, $in_list);
Subroutine __ANON__: called CC=1 SCAR=0.0
5167 },
5168 'base' => sub {
5169 2 ▶ str_append_funcall ($str, __PACKAGE__.'::ColumnSpec->new', $in_list);
Subroutine __ANON__: called CC=1 SCAR=0.0
5170 2 str_append_thing ($str, $thing->{datatype}, $in_list, NO_PARENS);
5171 2 str_append_end ($str);
5172 }
5173 4 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5174 },
5175 'ColumnSpecPost' => sub {
5176 4 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 4 4
5177 if $parens;
5178  
5179 4 str_append_funcall_begin ($str, __PACKAGE__.'::colspec_'.$thing->{functor}, $in_list);
5180 4 for my $arg (@{ $thing->{arg} }) {
5181 12 str_append_thing ($str, $arg, NOT_IN_LIST, NO_PARENS);
5182 }
5183 4 str_append_funcall_end ($str, $in_list);
5184 4 str_append_thing ($str, $thing->{base}, $in_list, NO_PARENS);
5185 4 str_append_end ($str);
5186 },
5187  
5188 'TableConstraint' => sub {
5189 switch($thing->{type},
5190 'primary_key' => sub {
5191 0 ▶ str_append_table_key ($str, $thing, 'PRIMARY KEY');
Subroutine __ANON__: not called CC=1 SCAR=6.9
5192 },
5193 'unique' => sub {
5194 0 ▶ str_append_table_key ($str, $thing, 'UNIQUE');
Subroutine __ANON__: not called CC=1 SCAR=6.9
5195 },
5196 'fulltext' => sub {
5197 0 ▶ str_append_table_key ($str, $thing, 'FULLTEXT');
Subroutine __ANON__: not called CC=1 SCAR=6.9
5198 },
5199 'spatial' => sub {
5200 0 ▶ str_append_table_key ($str, $thing, 'SPATIAL');
Subroutine __ANON__: not called CC=1 SCAR=6.9
5201 },
5202 'index' => sub {
5203 0 ▶ str_append_table_key ($str, $thing, 'INDEX');
Subroutine __ANON__: not called CC=1 SCAR=6.9
5204 },
5205 'foreign_key' => sub {
5206 0 ▶ str_append_table_key ($str, $thing, 'FOREIGN KEY');
Subroutine __ANON__: not called CC=1 SCAR=6.9
5207 },
5208 0 ▶ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
5209 },
5210  
5211 'IndexOption' => sub {
5212 switch($thing->{type},
5213 'using' => sub {
5214 0 ▶ str_append_str ($str, "USING $thing->{arg}");
Subroutine __ANON__: not called CC=1 SCAR=6.9
5215 }
5216 0 ▶ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
5217 },
5218  
5219 'References' => sub {
5220 # table column match on_delete on_update));
5221 str_append_join ($str, sep => ' ',
5222 prefix => 'REFERENCES ',
5223 suffix =>
5224 0 ▶ join('', map { " $_" }
Branch: 3 branches
BranchTrueFalseTotal
$thing->{'match'} ? : 0 0 0
$thing->{'on_delete'} ? : 0 0 0
$thing->{'on_update'} ? : 0 0 0
5225 ($thing->{match} ?
5226 ('MATCH', $thing->{match})
5227 : ()
5228 ),
5229 ($thing->{on_delete} ?
5230 ('ON DELETE', $thing->{on_delete})
5231 : ()
5232 ),
5233 ($thing->{on_update} ?
5234 ('ON UPDATE', $thing->{on_update})
5235 0 ▶ : ()
Subroutine __ANON__: not called CC=4 SCAR=30.0
5236 ),
5237 )
5238 );
5239 0 str_append_thing ($str, $thing->{table}, NOT_IN_LIST, NO_PARENS);
5240 0 str_append_list ($str, $thing->{column}, NO_PARENS,
5241 prefix => '(', suffix => ')', result0 => '');
5242 0 str_append_end ($str);
5243 },
5244  
5245 'CharUnit' => sub {
5246 0 ▶ str_append_str ($str, $thing->{name});
Subroutine __ANON__: not called CC=1 SCAR=6.9
5247 },
5248  
5249 'ExprList' => sub {
5250 switch($thing->{type},
5251 'interpol' => sub {
5252 4 ▶ str_append_typed ($str, 'exprlist', 'Expr', $thing, $in_list);
Subroutine __ANON__: called CC=1 SCAR=0.0
5253 },
5254  
5255 'explicit' => sub {
5256 4 ▶ str_append_list ($str, $thing->{arg}, NO_PARENS, prefix => '(', suffix => ')');
Subroutine __ANON__: called CC=1 SCAR=0.0
5257 # may not be empty!
5258 },
5259 8 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5260 },
5261 'ExprEmpty' => sub {
5262 # Append an empty string. Must have an operand here, otherwise
5263 # parameters might get mixed up.
5264 10 ▶ str_append_str($str, '');
Subroutine __ANON__: called CC=1 SCAR=0.0
5265 },
5266 'Check' => sub {
5267 9 ▶ str_append_join ($str, joinfunc => __PACKAGE__.'::Check->obj');
Subroutine __ANON__: called CC=1 SCAR=0.0
5268 9 str_append_thing ($str, $thing->{expr}, NOT_IN_LIST, NO_PARENS);
5269 9 str_append_end ($str);
5270 },
5271 'Expr' => sub {
5272 switch($thing->{type},
5273 'limit' => sub {
5274 10 ▶ my $limit_cnt_str= perl_val($thing->{arg}, 'Expr',
Subroutine __ANON__: called CC=1 SCAR=0.0
5275 ['interpol', 'interpolExpr', '?']);
5276 10 str_append_perl ($str, __PACKAGE__."::limit_number($limit_cnt_str)");
5277 },
5278 'interpol' => sub {
5279 my $func= $thing->{maybe_check} ?
5280 'expr_or_check'
5281 : ($thing->{token}{type} eq 'num' ||
5282 204 ▶ $thing->{token}{type} eq 'string' ||
Subroutine __ANON__: called CC=5 SCAR=16.1
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
5283 !$parens) ?
5284 'expr'
5285 : 'exprparen';
5286 204 str_append_typed ($str, $func, 'Expr', $thing, $in_list, hash => 1);
5287 },
5288 'column' => sub {
5289 227 ▶ str_append_thing ($str, $thing->{arg}, $in_list, NO_PARENS);
Subroutine __ANON__: called CC=1 SCAR=0.0
5290 },
5291 '()' => sub {
5292 4 ▶ str_append_thing ($str, $thing->{arg}, $in_list, PARENS);
Subroutine __ANON__: called CC=1 SCAR=0.0
5293 },
5294 'subquery' => sub {
5295 2 ▶ str_append_funcall ($str, __PACKAGE__.'::subquery', $in_list);
Subroutine __ANON__: called CC=1 SCAR=0.0
5296 2 str_append_thing ($str, $thing->{arg}, $in_list, NO_PARENS);
5297 2 str_append_end ($str);
5298 },
5299 'prefix1' => sub {
5300 1 ▶ $in_list= NOT_IN_LIST; # just to be sure
Subroutine __ANON__: called CC=3 SCAR=11.6
5301 1 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 1 1
5302 if $parens;
5303 1 ▶ die 'Expected exactly 1 argument' unless scalar(@{ $thing->{arg} }) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$thing->{"arg"};} == 1 0 1 1
5304  
5305 1 str_append_join ($str,
5306 prefix => "$thing->{functor}{value} ",
5307 never_empty => 1
5308 );
5309 1 str_append_thing ($str, $thing->{arg}[0], NOT_IN_LIST, PARENS);
5310 0 str_append_end ($str);
5311 },
5312 'prefixn' => sub {
5313 0 ▶ $parens= NO_PARENS; # just to be sure
Subroutine __ANON__: not called CC=3 SCAR=24.8
5314 0 ▶ die 'Expected exactly 1 argument' unless scalar(@{ $thing->{arg} }) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$thing->{"arg"};} == 1 0 0 0
5315  
5316 0 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 0 0 0
5317 0 str_append_map ($str, "'$thing->{functor}{value} '.(\$_)");
5318 }
5319 else {
5320 0 str_append_join ($str,
5321 prefix => "$thing->{functor}{value} ",
5322 never_empty => 1
5323 );
5324 }
5325 0 str_append_thing ($str, $thing->{arg}[0], $in_list, PARENS);
5326 0 str_append_end ($str);
5327 },
5328  
5329 'infix2' => sub {
5330 61 ▶ $in_list= NOT_IN_LIST; # just to be sure
Subroutine __ANON__: called CC=2 SCAR=6.9
5331 61 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 2 59 61
5332 if $parens;
5333  
5334 59 my $f= $thing->{functor};
5335 59 str_append_join ($str, joinfunc => __PACKAGE__.'::Infix->obj');
5336 59 str_append_str ($str, $thing->{functor}{value});
5337 59 str_append_thing ($str, $thing->{arg}[0], NOT_IN_LIST, PARENS);
5338 59 str_append_thing ($str, $thing->{arg}[1], NOT_IN_LIST, PARENS);
5339 59 str_append_end ($str);
5340 },
5341  
5342 'infix23' => 'infix3',
5343 'infix3' => sub {
5344 3 ▶ $in_list= NOT_IN_LIST; # just to be sure
Subroutine __ANON__: called CC=3 SCAR=11.0
5345 3 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 3 3
5346 if $parens;
5347  
5348 3 my $f= $thing->{functor};
5349 3 str_append_join ($str, never_empty => 1);
5350 3 str_append_thing ($str, $thing->{arg}[0], NOT_IN_LIST, PARENS);
5351 3 str_append_str ($str, " $thing->{functor}{value} ");
5352 3 str_append_thing ($str, $thing->{arg}[1], NOT_IN_LIST, PARENS);
5353 3 ▶ if (scalar(@{ $thing->{arg} }) == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$thing->{"arg"};} == 3) 1 2 3
5354 1 str_append_str ($str, " $thing->{functor}{value2} ");
5355 1 str_append_thing ($str, $thing->{arg}[2], NOT_IN_LIST, PARENS);
5356 }
5357 3 str_append_end ($str);
5358 },
5359  
5360 # prefix and suffix allow bitwise application:
5361 # Currently not supported via _prefix() and _suffix() helper
5362 # functions, but may be later. (Needs only a little rewrite
5363 # here. The helper functions don't need to be changed.)
5364 'prefix()' => 'prefix',
5365 'suffix' => 'prefix',
5366 'prefix' => sub {
5367 37 ▶ if ($thing->{type} eq 'prefix()') { # for AND() and OR() as functors
Subroutine __ANON__: called CC=9 SCAR=22.0
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"type"} eq "prefix()") 20 17 37
5368 20 $in_list = NOT_IN_LIST;
5369 }
5370 37 my $f= $thing->{functor};
5371 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] 0 37 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
5372 or die "Expected $thing->{type} to be mapped by \%functor_kind";
5373 37 ▶ if ($in_list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_list) { } 13 24 37
5374 13 my $qt= quote_perl($f->{value});
5375 13 ▶ str_append_map ($str, __PACKAGE__."::_".$fk."($qt,".($parens?1:0).",\$_)");
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 11 2 13
5376 13 for my $l (@{ $thing->{arg} }) {
5377 21 str_append_thing ($str, $l, IN_LIST, PARENS);
5378 }
5379 13 str_append_end ($str);
5380 }
5381 else {
5382 24 str_append_funcall($str, __PACKAGE__."::_".$fk, NOT_IN_LIST);
5383 24 str_append_thing ($str, $f->{value}, IN_LIST, NO_PARENS);
5384 24 ▶ str_append_thing ($str, $parens?1:0, IN_LIST, NO_PARENS);
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 7 17 24
5385 24 for my $l (@{ $thing->{arg} }) {
5386 34 str_append_thing ($str, $l, IN_LIST, PARENS);
5387 }
5388 24 str_append_end ($str);
5389 }
5390 },
5391  
5392 # funcall and infix use args inline if they are in list context.
5393 # They are handled by _prefix() and _suffix() helper functions in order
5394 # to allow dialect conversion:
5395 'funcall' => 'infix()',
5396 'infix()' => sub {
5397 60 ▶ $in_list= NOT_IN_LIST; # just to be sure
Subroutine __ANON__: called CC=5 SCAR=16.2
5398 60 my $f= $thing->{functor};
5399 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" 0 60 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
5400 or die 'Expected $thing->{type} to be mapped by %functor_kind';
5401  
5402 60 str_append_funcall($str, __PACKAGE__."::_".$fk, NOT_IN_LIST);
5403 60 str_append_thing ($str, $f->{value}, IN_LIST, NO_PARENS);
5404 60 ▶ str_append_thing ($str, $parens?1:0, IN_LIST, NO_PARENS);
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 7 53 60
5405 60 for my $l (@{ $thing->{arg} }) {
5406 115 str_append_thing ($str, $l, IN_LIST, PARENS);
5407 }
5408 60 str_append_end ($str);
5409 },
5410  
5411 'funcsep' => sub {
5412 1 ▶ $in_list= NOT_IN_LIST; # just to be sure
Subroutine __ANON__: called CC=2 SCAR=6.9
5413 1 str_append_join ($str, never_empty => 1, sep => ' ');
5414 1 str_append_str ($str, "$thing->{functor}{value}(");
5415 1 for my $t (@{ $thing->{arg} }) {
5416 4 str_append_thing ($str, $t, NOT_IN_LIST, NO_PARENS);
5417 }
5418 1 str_append_end ($str);
5419 },
5420  
5421 'case' => sub {
5422 8 ▶ $in_list= NOT_IN_LIST; # just to be sure
Subroutine __ANON__: called CC=6 SCAR=18.3
5423  
5424 # FIXME (maybe): we add parens here, so if there are no
5425 # when-then pairs at all and only the else part is printed,
5426 # it will get parens, too, no matter what. That's ok,
5427 # since it's a non-standard, marginal special case.
5428 8 ▶ return str_append_parens ($str, $thing, NOT_IN_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if $parens 0 8 8
5429 if $parens;
5430  
5431 8 my $sw= $thing->{switchval};
5432 8 ▶ if ($sw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sw) { } 8 0 8
5433 8 str_append_funcall ($str, __PACKAGE__."::caseswitch", NOT_IN_LIST);
5434 8 str_append_thing ($str, $sw, NOT_IN_LIST, NO_PARENS);
5435 }
5436 else {
5437 0 str_append_funcall ($str, __PACKAGE__."::casecond", NOT_IN_LIST);
5438 }
5439  
5440 8 ▶ if (my $e= $thing->{otherwise}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $thing->{'otherwise'}) { } 6 2 8
5441 6 str_append_thing ($str, $e, NOT_IN_LIST, NO_PARENS);
5442 }
5443 else {
5444 2 str_append_str ($str, 'NULL');
5445 }
5446  
5447 8 for my $wh (@{ $thing->{arg} }) {
5448 6 ▶ if (ref($wh) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $wh eq 'ARRAY') { } 6 0 6
5449 6 my ($when,$expr)= @$wh;
5450 6 str_append_funcall ($str, __PACKAGE__.'::whenthen', NOT_IN_LIST);
5451 6 str_append_thing ($str, $when, NOT_IN_LIST, NO_PARENS);
5452 6 str_append_thing ($str, $expr, NOT_IN_LIST, NO_PARENS);
5453 6 str_append_end ($str);
5454 }
5455 else {
5456 0 die 'expected array';
5457 }
5458 }
5459  
5460 8 str_append_end ($str);
5461 },
5462 618 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5463 },
5464  
5465 'ColumnName' => sub {
5466 switch ($thing->{type},
5467 'interpol' => 'ident',
5468 'ident' => sub {
5469 11 ▶ str_append_typed ($str, 'colname', 'none', $thing, $in_list, hashkeys => 1);
Subroutine __ANON__: called CC=1 SCAR=0.0
5470 }
5471 11 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5472 },
5473  
5474 'ColumnIndex' => sub {
5475 0 ▶ if (defined $thing->{length} || $thing->{desc}) {
Subroutine __ANON__: not called CC=5 SCAR=34.0
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
5476 0 str_append_join ($str, sep => ' ');
5477 0 str_append_thing ($str, $thing->{name}, NOT_IN_LIST, NO_PARENS);
5478 0 ▶ if (defined $thing->{length}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $thing->{"length"}) 0 0 0
5479 0 str_append_join ($str, prefix => '(', suffix => ')');
5480 0 str_append_thing ($str, $thing->{length}, NOT_IN_LIST, NO_PARENS);
5481 0 str_append_end ($str);
5482 }
5483 0 ▶ if ($thing->{desc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"desc"}) 0 0 0
5484 0 str_append_str ($str, 'DESC');
5485 }
5486 0 str_append_end ($str);
5487 }
5488 else {
5489 0 str_append_thing ($str, $thing->{name}, $in_list, $parens);
5490 }
5491 },
5492  
5493 'TableName' => sub {
5494 switch ($thing->{type},
5495 'interpol' => 'ident',
5496 'ident' => sub {
5497 1 ▶ str_append_typed ($str, 'tabname', 'none', $thing, $in_list, hashkeys => 1);
Subroutine __ANON__: called CC=1 SCAR=0.0
5498 }
5499 1 ▶ );
Subroutine __ANON__: called CC=1 SCAR=0.0
5500 },
5501  
5502 'Fetch' => 'Do',
5503 'Do' => sub {
5504 12 ▶ str_append_thing ($str, $thing->{stmt}, $in_list, $parens);
Subroutine __ANON__: called CC=1 SCAR=0.0
5505 },
5506 2423 );
5507 }
5508  
5509 sub to_perl($$\@)
5510 {
5511 278 ▶ my ($line_start, $kind, $things)= @_;
Subroutine to_perl: called CC=2 SCAR=6.9
Pod undocumented
5512 278 my $str= str_new($line_start);
5513 278 for my $thing (@$things) {
5514 383 str_append_thing ($str, $thing, IN_LIST, NO_PARENS);
5515 }
5516 275 my $text= str_get_string($str);
5517 275 return "do{".__PACKAGE__."::_max1_if_scalar map{".__PACKAGE__."::${kind}->obj(\$_)} $text}",
5518 }
5519  
5520 ######################################################################
5521 # Top-level parser interface:
5522  
5523 sub lx_die_perhaps($;$)
5524 {
5525 559 ▶ my $lx= shift;
Subroutine lx_die_perhaps: called CC=5 SCAR=16.1
Pod undocumented
5526  
5527 # if a test value is given, check that it is defined:
5528 559 ▶ if (scalar(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 280 279 559
5529 280 my ($check_val)= @_;
5530 280 ▶ unless (defined $check_val) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $check_val) 1 279 280
5531 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
5532 }
5533 }
5534  
5535 # if an error is set, then die:
5536 559 ▶ if ($lx->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lx->{"error"}) 2 557 559
5537 2 die lx_pos($lx).": Error: $lx->{error}\n";
5538 }
5539 }
5540  
5541  
5542 sub parse_1_or_list($$$;$)
5543 {
5544 273 ▶ my ($lx, $parse_elem, $list_sep, $end)= @_;
Subroutine parse_1_or_list: called CC=1 SCAR=0.0
Pod undocumented
5545 273 my $r= parse_list([], $lx, $parse_elem, $list_sep, $end);
5546 273 lx_die_perhaps($lx, $r);
5547 272 return @$r;
5548 }
5549  
5550 sub parse_0_try_list($$)
5551 {
5552 7 ▶ my ($lx, $parse_elem)= @_;
Subroutine parse_0_try_list: called CC=1 SCAR=0.0
Pod undocumented
5553 7 my $r= parse_try_list([], $lx, $parse_elem);
5554 7 lx_die_perhaps($lx, $r);
5555 7 return @$r;
5556 }
5557  
5558 sub parse_stmt_list($)
5559 {
5560 137 ▶ parse_1_or_list ($_[0], \&parse_stmt, ';', ['}',')',']']);
Subroutine parse_stmt_list: called CC=1 SCAR=0.0
Pod undocumented
5561 }
5562  
5563 sub parse_do_stmt($)
5564 {
5565 2 ▶ my ($lx) = @_;
Subroutine parse_do_stmt: called CC=1 SCAR=0.0
Pod undocumented
5566 map {
5567 2 my $stmt = $_;
5568 2 my $r = create($lx, 'Do', qw(stmt));
5569 2 $r->{stmt} = $stmt;
5570 2 $r;
5571 }
5572 parse_stmt_list($lx);
5573 }
5574  
5575 sub parse_fetch_stmt($)
5576 {
5577 10 ▶ my ($lx) = @_;
Subroutine parse_fetch_stmt: called CC=1 SCAR=0.0
Pod undocumented
5578 map {
5579 10 my $stmt = $_;
5580 10 my $r = create($lx, 'Fetch', qw(stmt));
5581 10 $r->{stmt} = $stmt;
5582 10 $r;
5583 }
5584 parse_stmt_list($lx);
5585 }
5586  
5587 my %top_parse= (
5588 # pure parse actions:
5589 'Stmt' => \&parse_stmt_list,
5590  
5591 5 ▶ 'Join' => sub { parse_0_try_list($_[0], \&parse_join) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5592 2 ▶ 'TableOption' => sub { parse_0_try_list($_[0], \&parse_table_option) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5593  
5594 81 ▶ 'Expr' => sub { parse_1_or_list ($_[0], \&parse_expr, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5595 9 ▶ 'Check' => sub { parse_1_or_list ($_[0], \&parse_check, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5596 15 ▶ 'Type' => sub { parse_1_or_list ($_[0], \&parse_type, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5597 9 ▶ 'Column' => sub { parse_1_or_list ($_[0], \&parse_column, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5598 6 ▶ 'Table' => sub { parse_1_or_list ($_[0], \&parse_table, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5599 0 ▶ 'Index' => sub { parse_1_or_list ($_[0], \&parse_index, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5600 1 ▶ 'CharSet' => sub { parse_1_or_list ($_[0], \&parse_charset, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5601 0 ▶ 'Collate' => sub { parse_1_or_list ($_[0], \&parse_collate, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5602 0 ▶ 'Constraint' => sub { parse_1_or_list ($_[0], \&parse_constraint, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5603 0 ▶ 'Transliteration' => sub { parse_1_or_list ($_[0], \&parse_transliteration, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5604 0 ▶ 'Transcoding' => sub { parse_1_or_list ($_[0], \&parse_transcoding, ',') },
Subroutine __ANON__: not called CC=1 SCAR=6.9
5605 8 ▶ 'Order' => sub { parse_1_or_list ($_[0], \&parse_order, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5606 7 ▶ 'ColumnSpec' => sub { parse_1_or_list ($_[0], \&parse_column_spec, ',') },
Subroutine __ANON__: called CC=1 SCAR=0.0
5607  
5608 # parse & execute actions:
5609 2 ▶ 'Do' => sub { parse_do_stmt ($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5610 10 ▶ 'Fetch' => sub { parse_fetch_stmt($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
5611 5 );
5612 5 my $top_parse_re= '(?:'.join('|', sort { length($b) <=> length($a) } '', keys %top_parse).')';
5613 5 my $top_parse_re2= '(?:'.join('|', sort { length($b) <=> length($a) } 'none', keys %top_parse).')';
5614  
5615 sub interpol_set_context ($$)
5616 {
5617 515 ▶ my ($text, $ctxt)= @_;
Subroutine interpol_set_context: called CC=1 SCAR=0.0
Pod undocumented
5618 515 $text=~ s/(\Q${\SQL_MARK}\E$top_parse_re)(?::$top_parse_re2)?(\s*\{)/$1:$ctxt$2/gs;
5619 515 return $text;
5620 }
5621  
5622 sub good_interpol_type($)
5623 {
5624 8 ▶ my ($type)= @_;
Subroutine good_interpol_type: called CC=1 SCAR=0.0
Pod undocumented
5625 8 return !!$top_parse{$type};
5626 }
5627  
5628 sub mark_sql()
5629 {
5630 # Step 1:
5631 # This function will get the text without comments, strings, etc.,
5632 # and replace the initial SQL marking the start of SQL syntax by
5633 # our special SQL_MARK. Then, the unprocessed text will be
5634 # processed by replace_sql().
5635 5 ▶ s/\b\Q$sql_marker\E($top_parse_re\s*\{)/${\SQL_MARK}$1/gs;
Subroutine mark_sql: called CC=1 SCAR=0.0
Pod undocumented
5636  
5637 # Step 2:
5638 # Unmark false positives. The above finds false matches in
5639 # variables:
5640 #
5641 # $sql{...}
5642 #
5643 # We cannot(?) do this in one go, as we'd need a variable-width
5644 # negative look-behind regexp, which Perl does not have. This
5645 # is because there can be arbitrary white space between $ and
5646 # a variable name.
5647 5 s/([\$\@\%]\s*)\Q${\SQL_MARK}\E/$1$sql_marker/gs;
5648  
5649 # Note that there are still false positives, which are really hard
5650 # to find unless we start parsing Perl completely:
5651 #
5652 # ${ sql{blah} }
5653 }
5654  
5655 sub parse($$)
5656 {
5657 22 ▶ my ($kind, $str)= @_;
Subroutine parse: called CC=3 SCAR=11.1
Pod undocumented
5658 22 my $lx= lexer_new ($str, "<string>", 0);
5659 22 my $func= $top_parse{$kind};
5660 22 ▶ return undef unless $func;
Branch: 1 branch
BranchTrueFalseTotal
unless $func 0 22 22
5661 22 ▶ return () if looking_at($lx, '<EOF>');
Branch: 1 branch
BranchTrueFalseTotal
if &looking_at($lx, "<EOF>") 0 22 22
5662 22 my @thing= $func->($lx);
5663 21 expect($lx, '<EOF>', SHIFT);
5664 21 lx_die_perhaps ($lx);
5665 20 return to_perl(1, $kind, @thing);
5666 }
5667  
5668 sub replace_sql()
5669 {
5670 5 ▶ my ($module, $file, $line)= caller(4); # find our from where we were invoked
Subroutine replace_sql: called CC=10 SCAR=23.6
Pod undocumented
5671  
5672 5 mark_sql();
5673 #print STDERR "DEBUG: BEFORE: $_\n";
5674  
5675 5 pos($_)= 0;
5676 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
5677 # prepare lexer:
5678 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
5679 258 my $speckind= $2;
5680 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
5681 258 my $start= pos($_) - length($1);
5682 258 my $prefix= substr($_, 0, $start);
5683 258 my $line_rel= ($prefix =~ tr/\n//);
5684 258 my $lx= lexer_new ($_, $file, $line + $line_rel);
5685  
5686 # select parser:
5687 258 my $func= $top_parse{$kind};
5688 258 ▶ unless ($func) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($func) 0 258 258
5689 0 die "$file:".($line+$line_rel+1).
5690 ": Error: Plain ${sql_marker}${speckind}{...} is illegal, because the ".
5691 "surrounding block must not return an object.\n\tPlease use ".
5692 (english_or map "${sql_marker}${_}{...}", keys %top_parse)." to disambiguate.\n";
5693 0 last REPLACEMENT;
5694 }
5695  
5696 # parse (including closing brace):
5697 258 my @thing= $func->($lx);
5698 258 expect ($lx, '}', SHIFT);
5699 258 lx_die_perhaps ($lx);
5700  
5701 258 my $end= $lx->{token}{pos};
5702 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
5703  
5704 # Make Perl code:
5705 # Represent the parse result as a list in Perl (if it's only
5706 # one element, the parens don't hurt). Each thing is
5707 # handled individually by to_perl():
5708 258 my $perl= to_perl($line + $line_rel, $kind, @thing);
5709  
5710 # replace:
5711 258 ▶ print STDERR "$file:".($line+$line_rel+1).': DEBUG: '.__PACKAGE__." replacement: $perl\n"
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 258 258
5712 if $debug;
5713  
5714 258 my $old_text= substr($_, $start, $end-$start, $perl); # extract and replace text
5715 # pos($_) is now undef, which is ok, we will
5716 # rescan the text anyway.
5717  
5718 # Insert newlines at the end that have been dropped so that the line
5719 # count does not change and Perl's error messages are useful:
5720 258 my $line_cnt_old= ($old_text =~ tr/\n//);
5721 258 my $line_cnt_new= ($perl =~ tr/\n//);
5722 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
5723 if $line_cnt_new > $line_cnt_old;
5724  
5725 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
5726 101 substr($_, $start + length($perl), 0, "\n" x $line_cnt_less);
5727 }
5728  
5729 # rescan everything in order to recurse into embedded sql{...}:
5730 258 pos($_)= 0;
5731 }
5732 5 pos($_)= undef;
5733  
5734 #print STDERR "DEBUG: AFTER: $_\n";
5735 };
5736  
5737 5 FILTER_ONLY
5738 # code_no_comments => \&mark_sql, # This is way to slow.
5739 all => \&replace_sql;
5740  
5741 ######################################################################
5742 # Functions used in generated code:
5743  
5744 # Obj:
5745 {
5746 package SQL::Yapp::Obj;
5747  
5748 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5749 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5750 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5751  
5752 0 ▶ sub op($) { return ''; }
Subroutine op: not called CC=1 SCAR=6.9
5753  
5754 ######################################################################
5755 # stringify: simply return second entry in array, the string:
5756 use overload '""' => 'value',
5757 5 ▶ cmp => sub { "$_[0]" cmp "$_[1]" };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
5758  
5759 sub type_error($$)
5760 {
5761 3 ▶ my ($x, $want)= @_;
Subroutine type_error: called CC=1 SCAR=0.0
5762 3 my $r= ref($x);
5763 3 $r=~ s/^SQL::Yapp:://;
5764 3 croak "Error: Expected $want, but found ".$r;
5765 }
5766  
5767 0 ▶ sub asc($) { $_[0]->type_error('Asc'); }
Subroutine asc: not called CC=1 SCAR=6.9
5768 0 ▶ sub assign($) { $_[0]->type_error('assignment'); }
Subroutine assign: not called CC=1 SCAR=6.9
5769 0 ▶ sub charset($) { $_[0]->type_error('CharSet'); }
Subroutine charset: not called CC=1 SCAR=6.9
5770 0 ▶ sub constraint($) { $_[0]->type_error('Constraint'); }
Subroutine constraint: not called CC=1 SCAR=6.9
5771 0 ▶ sub charset1($) { $_[0]->type_error('CharSet'); }
Subroutine charset1: not called CC=1 SCAR=6.9
5772 0 ▶ sub collate1($) { $_[0]->type_error('Collate'); }
Subroutine collate1: not called CC=1 SCAR=6.9
5773 0 ▶ sub colname($) { $_[0]->type_error('ColumnName'); }
Subroutine colname: not called CC=1 SCAR=6.9
5774 0 ▶ sub colspec($) { $_[0]->type_error('ColumnSpec'); }
Subroutine colspec: not called CC=1 SCAR=6.9
5775 0 ▶ sub column1($) { $_[0]->type_error('Column'); }
Subroutine column1: not called CC=1 SCAR=6.9
5776 1 ▶ sub column1_single($) { $_[0]->type_error('Column'); }
Subroutine column1_single: called CC=1 SCAR=0.0
5777 0 ▶ sub constraint1($) { $_[0]->type_error('Constraint'); }
Subroutine constraint1: not called CC=1 SCAR=6.9
5778 0 ▶ sub desc($) { $_[0]->type_error('Desc'); }
Subroutine desc: not called CC=1 SCAR=6.9
5779 0 ▶ sub engine1($) { $_[0]->type_error('Engine'); }
Subroutine engine1: not called CC=1 SCAR=6.9
5780 0 ▶ sub expr($) { $_[0]->type_error('Expr'); }
Subroutine expr: not called CC=1 SCAR=6.9
5781 0 ▶ sub expr_or_check($) { $_[0]->type_error('Expr or Check'); }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5782 0 ▶ sub check($) { $_[0]->type_error('Check'); }
Subroutine check: not called CC=1 SCAR=6.9
5783 1 ▶ sub exprparen($) { $_[0]->type_error('Expr'); }
Subroutine exprparen: called CC=1 SCAR=0.0
5784 0 ▶ sub index1($) { $_[0]->type_error('Index'); }
Subroutine index1: not called CC=1 SCAR=6.9
5785 0 ▶ sub joinclause($) { $_[0]->type_error('JOIN clause'); }
Subroutine joinclause: not called CC=1 SCAR=6.9
5786 0 ▶ sub limit_number($) { $_[0]->type_error('number or ?'); }
Subroutine limit_number: not called CC=1 SCAR=6.9
5787 0 ▶ sub stmt($) { $_[0]->type_error('Stmt'); }
Subroutine stmt: not called CC=1 SCAR=6.9
5788 0 ▶ sub subquery($) { $_[0]->type_error('subquery'); }
Subroutine subquery: not called CC=1 SCAR=6.9
5789 0 ▶ sub table1($) { $_[0]->type_error('Table'); }
Subroutine table1: not called CC=1 SCAR=6.9
5790 0 ▶ sub tabname($) { $_[0]->type_error('TableName'); }
Subroutine tabname: not called CC=1 SCAR=6.9
5791 0 ▶ sub tableopt($) { $_[0]->type_error('TableOption'); }
Subroutine tableopt: not called CC=1 SCAR=6.9
5792 0 ▶ sub transcoding($) { $_[0]->type_error('Transcoding'); }
Subroutine transcoding: not called CC=1 SCAR=6.9
5793 0 ▶ sub transliteration1($) { $_[0]->type_error('Transliteration'); }
Subroutine transliteration1: not called CC=1 SCAR=6.9
5794 0 ▶ sub type($) { $_[0]->type_error('Type'); }
Subroutine type: not called CC=1 SCAR=6.9
5795  
5796 0 ▶ sub do($) { $_[0]->type_error('Do'); }
Subroutine do: not called CC=1 SCAR=6.9
5797 0 ▶ sub fetch($) { $_[0]->type_error('Fetch'); }
Subroutine fetch: not called CC=1 SCAR=6.9
5798 }
5799  
5800 # Obj1:
5801 {
5802 5 package SQL::Yapp::Obj1;
5803  
5804 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5805 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5806 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
5807 5 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
5808  
5809 sub obj($$)
5810 {
5811 890 ▶ my ($class,$x)= @_;
Subroutine obj: called CC=3 SCAR=11.0
5812 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
5813 if blessed($x) && $x->isa(__PACKAGE__);
5814 731 return bless([$x], $class);
5815 }
5816  
5817 816 ▶ sub value($) { return $_[0][0]; }
Subroutine value: called CC=1 SCAR=0.0
5818 }
5819  
5820 ###############
5821 # Asterisk:
5822 {
5823 5 package SQL::Yapp::Asterisk;
5824  
5825 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5826 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5827 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
5828  
5829 sub obj($)
5830 {
5831 2 ▶ my ($class)= @_;
Subroutine obj: called CC=1 SCAR=0.0
5832 2 return bless([], $class);
5833 }
5834  
5835 2 ▶ sub value($) { return '*'; }
Subroutine value: called CC=1 SCAR=0.0
5836  
5837 2 ▶ sub column1($) { return $_[0]; }
Subroutine column1: called CC=1 SCAR=0.0
5838 0 ▶ sub column1_single($) { return $_[0]; }
Subroutine column1_single: not called CC=1 SCAR=6.9
5839 0 ▶ sub expr($) { return $_[0]; }
Subroutine expr: not called CC=1 SCAR=6.9
5840 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5841  
5842 0 ▶ sub asterisk($) { return $_[0]; }
Subroutine asterisk: not called CC=1 SCAR=6.9
5843 }
5844  
5845 # Question:
5846 {
5847 5 package SQL::Yapp::Question;
5848  
5849 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5850 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5851 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
5852  
5853 sub obj($)
5854 {
5855 1 ▶ my ($class)= @_;
Subroutine obj: called CC=1 SCAR=0.0
5856 1 return bless([], $class);
5857 }
5858  
5859 1 ▶ sub value($) { return '?' }
Subroutine value: called CC=1 SCAR=0.0
5860  
5861 0 ▶ sub limit_number($) { return $_[0]; }
Subroutine limit_number: not called CC=1 SCAR=6.9
5862 1 ▶ sub exprparen($) { return $_[0]; }
Subroutine exprparen: called CC=1 SCAR=0.0
5863 0 ▶ sub expr($) { return $_[0]; }
Subroutine expr: not called CC=1 SCAR=6.9
5864 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5865 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
5866 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
5867 }
5868  
5869 # ExprSpecial:
5870 {
5871 5 package SQL::Yapp::ExprSpecial;
5872  
5873 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5874 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5875 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
5876  
5877 0 ▶ sub exprparen($) { return $_[0]; }
Subroutine exprparen: not called CC=1 SCAR=6.9
5878 0 ▶ sub expr($) { return $_[0]; }
Subroutine expr: not called CC=1 SCAR=6.9
5879 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5880 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
5881 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
5882 }
5883  
5884 # Stmt:
5885 {
5886 5 package SQL::Yapp::Stmt;
5887  
5888 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5889 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5890 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5891 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
5892  
5893 1 ▶ sub subquery($) { $_[0]->type_error('SELECT statement'); }
Subroutine subquery: called CC=1 SCAR=0.0
5894 0 ▶ sub exprparen($) { $_[0]->subquery(); }
Subroutine exprparen: not called CC=1 SCAR=6.9
5895 2 ▶ sub expr($) { $_[0]->subquery(); }
Subroutine expr: called CC=1 SCAR=0.0
5896 0 ▶ sub expr_or_check($) { $_[0]->subquery(); }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
5897  
5898 3 ▶ sub stmt($) { return $_[0]; }
Subroutine stmt: called CC=1 SCAR=0.0
5899  
5900 sub do($)
5901 {
5902 0 ▶ my ($stmt) = @_;
Subroutine do: not called CC=1 SCAR=6.9
5903 0 my $dbh = SQL::Yapp::get_dbh();
5904 0 $dbh->do($stmt);
5905 0 return; # return no statements so that _max1_if_scalar is ok with void context
5906 }
5907 }
5908  
5909 # SelectStmt:
5910 {
5911 5 package SQL::Yapp::SelectStmt;
5912  
5913 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5914 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5915 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5916 5 ▶ use base qw(SQL::Yapp::Stmt);
Subroutine BEGIN: called CC=1 SCAR=0.0
5917  
5918 2 ▶ sub subquery($) { return '('.($_[0]->value).')'; }
Subroutine subquery: called CC=1 SCAR=0.0
5919  
5920 sub fetch($)
5921 {
5922 0 ▶ my ($stmt) = @_;
Subroutine fetch: not called CC=2 SCAR=17.9
5923 0 my $dbh = SQL::Yapp::get_dbh();
5924 0 my $sth = $dbh->prepare($stmt);
5925 0 my $aref = $dbh->selectall_arrayref($sth, { Slice => {} });
5926 0 ▶ return unless $aref;
Branch: 1 branch
BranchTrueFalseTotal
unless $aref 0 0 0
5927 0 return @$aref;
5928 }
5929 }
5930  
5931 # SelectStmtSingle:
5932 {
5933 5 package SQL::Yapp::SelectStmtSingle;
5934  
5935 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5936 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5937 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5938 5 ▶ use base qw(SQL::Yapp::SelectStmt);
Subroutine BEGIN: called CC=1 SCAR=0.0
5939  
5940 sub fetch($)
5941 {
5942 0 ▶ my ($stmt) = @_;
Subroutine fetch: not called CC=4 SCAR=30.0
5943 0 my $dbh = SQL::Yapp::get_dbh();
5944 0 my $sth = $dbh->prepare($stmt);
5945 0 ▶ return unless $sth->execute;
Branch: 1 branch
BranchTrueFalseTotal
unless $sth->execute 0 0 0
5946 0 my @r= ();
5947 0 ▶ while (my $a= $sth->fetchrow_arrayref) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $sth->fetchrow_arrayref) 0 0 0
5948 0 ▶ die unless scalar(@$a) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$a == 1 0 0 0
5949 0 push @r, $a->[0];
5950 }
5951 0 return @r;
5952 }
5953 }
5954  
5955 # Do:
5956 # This is a bit different, since the obj() method will actually execute the statement.
5957 {
5958 5 package SQL::Yapp::Do;
5959  
5960 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5961 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5962 5 ▶ use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
5963  
5964 sub obj($$)
5965 {
5966 0 ▶ my ($class, $stmt) = @_;
Subroutine obj: not called CC=1 SCAR=6.9
5967 0 return $stmt->do;
5968 }
5969 }
5970  
5971 # Fetch:
5972 # This is a bit different, since the obj() method will actually execute the statement.
5973 {
5974 5 package SQL::Yapp::Fetch;
5975  
5976 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5977 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5978  
5979 sub obj($$)
5980 {
5981 0 ▶ my ($class, $stmt) = @_;
Subroutine obj: not called CC=1 SCAR=6.9
5982 0 return $stmt->fetch;
5983 }
5984 }
5985  
5986 # ColumnName:
5987 {
5988 5 package SQL::Yapp::ColumnName;
5989  
5990 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5991 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5992 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
5993  
5994 0 ▶ sub colname($) { return $_[0]; }
Subroutine colname: not called CC=1 SCAR=6.9
5995 }
5996  
5997 # TableName:
5998 {
5999 5 package SQL::Yapp::TableName;
6000  
6001 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6002 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6003 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6004  
6005 0 ▶ sub tabname($) { return $_[0]; }
Subroutine tabname: not called CC=1 SCAR=6.9
6006 }
6007  
6008 # Column:
6009 {
6010 5 package SQL::Yapp::Column;
6011  
6012 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6013 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6014 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6015  
6016 2 ▶ sub column1($) { return $_[0]; }
Subroutine column1: called CC=1 SCAR=0.0
6017 3 ▶ sub exprparen($) { return $_[0]; }
Subroutine exprparen: called CC=1 SCAR=0.0
6018 1 ▶ sub expr($) { return $_[0]; }
Subroutine expr: called CC=1 SCAR=0.0
6019 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
6020 2 ▶ sub asc($) { return $_[0]; }
Subroutine asc: called CC=1 SCAR=0.0
6021 5 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: called CC=1 SCAR=0.0
6022 }
6023  
6024 # Table:
6025 {
6026 5 package SQL::Yapp::Table;
6027 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6028 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6029 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6030 5 ▶ sub table1($) { return $_[0]; }
Subroutine table1: called CC=1 SCAR=0.0
6031 }
6032  
6033 # CharSet:
6034 {
6035 5 package SQL::Yapp::CharSet;
6036 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6037 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6038 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6039 0 ▶ sub charset1($) { return $_[0]; }
Subroutine charset1: not called CC=1 SCAR=6.9
6040 }
6041  
6042 # Collate:
6043 {
6044 5 package SQL::Yapp::Collate;
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 0 ▶ sub collate1($) { return $_[0]; }
Subroutine collate1: not called CC=1 SCAR=6.9
6049 }
6050  
6051 # Constraint:
6052 {
6053 5 package SQL::Yapp::Constraint;
6054 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6055 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6056 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6057 0 ▶ sub constraint1($) { return $_[0]; }
Subroutine constraint1: not called CC=1 SCAR=6.9
6058 }
6059  
6060 # Index:
6061 {
6062 5 package SQL::Yapp::Index;
6063 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6064 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6065 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6066 0 ▶ sub index1($) { return $_[0]; }
Subroutine index1: not called CC=1 SCAR=6.9
6067 }
6068  
6069 # Transliteration:
6070 {
6071 5 package SQL::Yapp::Transliteration;
6072 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6073 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6074 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6075 0 ▶ sub transliteration($) { return $_[0]; }
Subroutine transliteration: not called CC=1 SCAR=6.9
6076 }
6077  
6078 # Transcoding:
6079 {
6080 5 package SQL::Yapp::Transcoding;
6081 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6082 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6083 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6084 0 ▶ sub transcoding($) { return $_[0]; }
Subroutine transcoding: not called CC=1 SCAR=6.9
6085 }
6086  
6087 # TableOption:
6088 {
6089 5 package SQL::Yapp::TableOption;
6090 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6091 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6092 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6093 2 ▶ sub tableopt($) { return $_[0]; }
Subroutine tableopt: called CC=1 SCAR=0.0
6094 }
6095  
6096 # Engine:
6097 {
6098 5 package SQL::Yapp::Engine;
6099 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6100 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6101 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6102 0 ▶ sub engine1($) { return $_[0]; }
Subroutine engine1: not called CC=1 SCAR=6.9
6103 }
6104  
6105  
6106 # Join:
6107 {
6108 5 package SQL::Yapp::Join;
6109  
6110 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6111 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6112 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6113  
6114 4 ▶ sub joinclause($) { return $_[0]; }
Subroutine joinclause: called CC=1 SCAR=0.0
6115 }
6116  
6117 # Check:
6118 {
6119 5 package SQL::Yapp::Check;
6120  
6121 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6122 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6123 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6124  
6125 3 ▶ sub check($) { return $_[0]; }
Subroutine check: called CC=1 SCAR=0.0
6126 3 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: called CC=1 SCAR=0.0
6127  
6128 sub obj($$)
6129 {
6130 18 ▶ if (ref($_[1]) eq $_[0]) {
Subroutine obj: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[1] eq $_[0]) { } 9 9 18
elsif (ref $_[1]) { } 7 2 9
6131 9 return $_[1];
6132 }
6133 elsif (ref($_[1])) {
6134 7 bless($_[1], $_[0]);
6135 }
6136 else {
6137 2 $_[0]->SUPER::obj($_[1]);
6138 }
6139 }
6140 }
6141  
6142 # Expr:
6143 {
6144 5 package SQL::Yapp::Expr;
6145  
6146 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6147 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6148 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6149  
6150 0 ▶ sub exprparen($) { return '('.($_[0]->value).')'; }
Subroutine exprparen: not called CC=1 SCAR=6.9
6151 18 ▶ sub expr($) { return $_[0]; }
Subroutine expr: called CC=1 SCAR=0.0
6152 0 ▶ sub expr_or_check($) { return $_[0]; }
Subroutine expr_or_check: not called CC=1 SCAR=6.9
6153 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
6154 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
6155 }
6156  
6157 # Infix:
6158 {
6159 5 package SQL::Yapp::Infix;
6160  
6161 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6162 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6163 5 ▶ use base qw(SQL::Yapp::Expr);
Subroutine BEGIN: called CC=1 SCAR=0.0
6164 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6165  
6166 sub obj($$$$)
6167 {
6168 56 ▶ my ($class, $op, $a1, $a2)= @_;
Subroutine obj: called CC=1 SCAR=0.0
6169 56 return bless(["$a1 $op $a2", $op, $a1, $a2], $class);
6170 }
6171  
6172 14 ▶ sub op($) { return $_[0][1]; }
Subroutine op: called CC=1 SCAR=0.0
6173 14 ▶ sub arg1($) { return $_[0][2]; }
Subroutine arg1: called CC=1 SCAR=0.0
6174 14 ▶ sub arg2($) { return $_[0][3]; }
Subroutine arg2: called CC=1 SCAR=0.0
6175  
6176 sub assign($)
6177 {
6178 14 ▶ my ($self)= @_;
Subroutine assign: called CC=2 SCAR=7.6
6179 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
6180 14 return $self;
6181 }
6182 0 croak "Assignment expected, but found top-level operator '".($self->op)."'.";
6183 }
6184 }
6185  
6186 # Order:
6187 {
6188 5 package SQL::Yapp::Order;
6189  
6190 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6191 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6192 5 ▶ use base qw(SQL::Yapp::Obj1);
Subroutine BEGIN: called CC=1 SCAR=0.0
6193 5 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
6194  
6195 sub obj($$)
6196 {
6197 7 ▶ my ($class,$x)= @_;
Subroutine obj: called CC=3 SCAR=14.2
6198 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
6199 if blessed($x) && $x->isa('SQL::Yapp::Obj');
6200 0 return bless([$x], 'SQL::Yapp::Asc'); # not Order, but Asc.
6201 }
6202 }
6203  
6204 # Asc:
6205 {
6206 5 package SQL::Yapp::Asc;
6207  
6208 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6209 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6210 5 ▶ use base qw(SQL::Yapp::Order);
Subroutine BEGIN: called CC=1 SCAR=0.0
6211  
6212 0 ▶ sub asc($) { return $_[0]; }
Subroutine asc: not called CC=1 SCAR=6.9
6213 0 ▶ sub desc($) { return SQL::Yapp::Desc->obj($_[0]); }
Subroutine desc: not called CC=1 SCAR=6.9
6214 }
6215  
6216 # Desc:
6217 {
6218 5 package SQL::Yapp::Desc;
6219  
6220 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6221 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6222 5 ▶ use base qw(SQL::Yapp::Order);
Subroutine BEGIN: called CC=1 SCAR=0.0
6223  
6224 sub obj($$)
6225 {
6226 9 ▶ my ($class, $orig)= @_;
Subroutine obj: called CC=1 SCAR=0.0
6227 9 return bless(["$orig DESC",$orig],$class);
6228 }
6229  
6230 1 ▶ sub orig($) { return $_[0][1]; }
Subroutine orig: called CC=1 SCAR=0.0
6231  
6232 2 ▶ sub asc($) { return $_[0]; }
Subroutine asc: called CC=1 SCAR=0.0
6233 1 ▶ sub desc($) { return &orig; }
Subroutine desc: called CC=1 SCAR=0.0
6234 }
6235  
6236 # Type:
6237 {
6238 5 package SQL::Yapp::Type;
6239  
6240 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6241 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6242 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
6243 5 ▶ use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
6244 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6245  
6246 sub set_base($$$)
6247 {
6248 11 ▶ my ($self, $base, $spec)= @_;
Subroutine set_base: called CC=3 SCAR=11.0
6249  
6250 # set new spec:
6251 11 $self->{base}= $base;
6252 11 $self->{spec}= $spec;
6253  
6254 # filter options by new spec:
6255 11 for my $o (keys %{ $self->{option} }) {
6256 3 ▶ unless ($spec->{$o}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($spec->{$o}) 1 2 3
6257 1 delete $self->{option}{$o};
6258 }
6259 }
6260  
6261 11 return $self;
6262 }
6263  
6264 sub set_property($$$)
6265 {
6266 13 ▶ my ($self, $key, $value)= @_;
Subroutine set_property: called CC=2 SCAR=7.0
6267 13 my %a= %$self;
6268 13 ▶ croak "No $key for $self->{base} allowed." unless $self->{spec}{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"spec"}{$key} 0 13 13
6269 13 $self->{option}{$key}= $value;
6270 13 return $self;
6271 }
6272  
6273 sub new($)
6274 {
6275 9 ▶ my $r= bless({ base => undef, spec => undef, option => {} }, $_[0]);
Subroutine new: called CC=1 SCAR=0.0
6276 9 lock_keys %$r;
6277 9 return $r;
6278 }
6279  
6280 sub obj($$)
6281 {
6282 13 ▶ return $_[1];
Subroutine obj: called CC=1 SCAR=0.0
6283 }
6284  
6285 sub clone($)
6286 {
6287 11 ▶ my ($self)= @_;
Subroutine clone: called CC=1 SCAR=0.0
6288 my $r= bless({
6289 %$self,
6290 # no need to make a deep copy of 'spec', because it is never changed.
6291 11 option => { %{ $self->{option} } },
6292 }, __PACKAGE__);
6293 11 lock_keys %$r;
6294 11 return $r;
6295 }
6296  
6297 sub type($)
6298 {
6299 7 ▶ return $_[0]->clone(); # make a copy before trying to modify this
Subroutine type: called CC=1 SCAR=0.0
6300 }
6301  
6302 sub colspec($)
6303 {
6304 1 ▶ return SQL::Yapp::ColumnSpec->new($_[0]); # make a copy producing a ColumnSpec
Subroutine colspec: called CC=1 SCAR=0.0
6305 }
6306  
6307 sub value($)
6308 {
6309 38 ▶ my ($self)= @_;
Subroutine value: called CC=19 SCAR=35.0
6310 38 ▶ return '<error: no base type>' unless $self->{base};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"base"} 18 20 38
6311 20 my @r= ($self->{base});
6312 20 ▶ if ($self->{spec}{prec1} && defined $self->{option}{prec1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"spec"}{"prec1"} and defined $self->{"option"}{"prec1"}) 19 1 20
Condition66%2/3
$self->{"spec"}{"prec1"} and defined $self->{"option"}{"prec1"}
!ll&&!rl&&r
0119
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
6313 19 my $len_str= '';
6314 19 $len_str.= $self->{option}{prec1};
6315 19 ▶ if ($self->{spec}{prec2} && defined $self->{option}{prec2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'spec'}{'prec2'} and defined $self->{'option'}{'prec2'}) { } 0 19 19
Condition66%2/3
$self->{"spec"}{"prec2"} and defined $self->{"option"}{"prec2"}
!ll&&!rl&&r
1630
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
6316 0 $len_str.= ', '.$self->{option}{prec2};
6317 }
6318 else {
6319 19 ▶ if ($self->{spec}{prec_mul} && $self->{option}{prec_mul}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"spec"}{"prec_mul"} and $self->{"option"}{"prec_mul"}) 0 19 19
Condition33%1/3
$self->{"spec"}{"prec_mul"} and $self->{"option"}{"prec_mul"}
!ll&&!rl&&r
1900
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
6320 0 $len_str.= ' '.$self->{option}{prec_mul};
6321 }
6322 19 ▶ if ($self->{spec}{prec_unit} && $self->{option}{prec_unit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"spec"}{"prec_unit"} and $self->{"option"}{"prec_unit"}) 0 19 19
Condition33%1/3
$self->{"spec"}{"prec_unit"} and $self->{"option"}{"prec_unit"}
!ll&&!rl&&r
1900
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
6323 0 $len_str.= ' '.$self->{option}{prec_unit};
6324 }
6325 }
6326 19 push @r, '('.$len_str.')';
6327 }
6328 20 ▶ 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 20 20
Condition33%1/3
$self->{'spec'}{'value_list'} && $self->{'option'}{'value_list'}
!ll&&!rl&&r
2000
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
6329 0 push @r, '('.join(', ',@$value_list).')';
6330 }
6331 20 ▶ if (my $x= $self->{spec}{charset} && $self->{option}{charset}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"spec"}{"charset"} && $self->{"option"}{"charset"}) 3 17 20
Condition100%3/3
$self->{'spec'}{'charset'} && $self->{'option'}{'charset'}
!ll&&!rl&&r
6113
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
6332 3 push @r, 'CHARACTER SET', $x;
6333 }
6334 20 ▶ if (my $x= $self->{spec}{collate} && $self->{option}{collate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"spec"}{"collate"} && $self->{"option"}{"collate"}) 0 20 20
Condition66%2/3
$self->{'spec'}{'collate'} && $self->{'option'}{'collate'}
!ll&&!rl&&r
6140
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
6335 0 push @r, 'COLLATE', $x;
6336 }
6337 20 for my $key ('sign', 'zerofill', 'timezone') {
6338 60 ▶ if (my $x= $self->{spec}{$key} && $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"spec"}{$key} && $self->{"option"}{$key}) 0 60 60
Condition66%2/3
$self->{'spec'}{$key} && $self->{'option'}{$key}
!ll&&!rl&&r
48120
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
6339 0 push @r, $x;
6340 }
6341 }
6342  
6343 20 return join(' ', @r);
6344 }
6345 }
6346  
6347  
6348 # ColumnSpec:
6349 {
6350 5 package SQL::Yapp::ColumnSpec;
6351  
6352 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6353 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6354 5 ▶ use base qw(SQL::Yapp::Obj);
Subroutine BEGIN: called CC=1 SCAR=0.0
6355 5 ▶ use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
6356 5 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6357  
6358 sub new($$)
6359 {
6360 3 ▶ my ($class, $type)= @_;
Subroutine new: called CC=1 SCAR=0.0
6361 3 my $r= bless({ datatype => $type->clone(), name => {}, option => {} }, $class);
6362 3 lock_keys %$r;
6363 3 return $r;
6364 }
6365  
6366 sub obj($$)
6367 {
6368 3 ▶ return $_[1];
Subroutine obj: called CC=1 SCAR=0.0
6369 }
6370  
6371 sub clone($)
6372 {
6373 1 ▶ my ($self)= @_;
Subroutine clone: called CC=1 SCAR=0.0
6374 my $r= bless({
6375 datatype => $self->{datatype}->clone(),
6376 1 name => { %{ $self->{name} } },
6377 1 option => { %{ $self->{option} } },
6378 }, __PACKAGE__);
6379 1 lock_keys %$r;
6380 1 return $r;
6381 }
6382  
6383 sub colspec($)
6384 {
6385 1 ▶ return $_[0]->clone(); # make a copy before trying to modify this
Subroutine colspec: called CC=1 SCAR=0.0
6386 }
6387  
6388 sub name($$)
6389 {
6390 6 ▶ my ($self, $key)= @_;
Subroutine name: called CC=2 SCAR=7.6
6391 6 ▶ if (my $x= $self->{name}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"name"}{$key}) 0 6 6
6392 0 return ('CONSTRAINT', $x);
6393 }
6394 6 return;
6395 }
6396  
6397 sub value($)
6398 {
6399 4 ▶ my ($self)= @_;
Subroutine value: called CC=9 SCAR=22.4
6400 4 my @r= ($self->{datatype});
6401  
6402 4 for my $key ('notnull', 'autoinc', 'unique', 'primary', 'key') {
6403 20 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 4 16 20
6404 4 push @r, $self->name($key), $x;
6405 }
6406 }
6407  
6408 4 for my $key ('default', 'column_format', 'storage') {
6409 12 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 2 10 12
6410 2 push @r, $self->name($key), uc($key), $x;
6411 }
6412 }
6413  
6414 4 for my $key ('check') {
6415 4 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 0 4 4
6416 0 push @r, $self->name($key), uc($key), '('.$x.')';
6417 }
6418 }
6419  
6420 4 for my $key ('references') {
6421 4 ▶ if (my $x= $self->{option}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $self->{"option"}{$key}) 0 4 4
6422 0 push @r, $self->name($key), $x;
6423 }
6424 }
6425  
6426 4 return join(' ', @r);
6427 }
6428 }
6429  
6430  
6431 # Special Constants:
6432 2 ▶sub ASTERISK { SQL::Yapp::Asterisk->obj(); }
Subroutine ASTERISK: called CC=1 SCAR=0.0
Pod undocumented
6433 1 ▶sub QUESTION { SQL::Yapp::Question->obj(); }
Subroutine QUESTION: called CC=1 SCAR=0.0
Pod undocumented
6434 0 ▶sub NULL { SQL::Yapp::ExprSpecial->obj('NULL'); }
Subroutine NULL: not called CC=1 SCAR=6.9
Pod undocumented
6435 0 ▶sub TRUE { SQL::Yapp::ExprSpecial->obj('TRUE'); }
Subroutine TRUE: not called CC=1 SCAR=6.9
Pod undocumented
6436 0 ▶sub FALSE { SQL::Yapp::ExprSpecial->obj('FALSE'); }
Subroutine FALSE: not called CC=1 SCAR=6.9
Pod undocumented
6437 0 ▶sub UNKNOWN { SQL::Yapp::ExprSpecial->obj('UNKNOWN'); }
Subroutine UNKNOWN: not called CC=1 SCAR=6.9
Pod undocumented
6438 0 ▶sub DEFAULT { SQL::Yapp::ExprSpecial->obj('DEFAULT'); }
Subroutine DEFAULT: not called CC=1 SCAR=6.9
Pod undocumented
6439  
6440  
6441 # Wrapped DBI methods:
6442 sub croak_no_ref($)
6443 {
6444 1 ▶ my ($self)= @_;
Subroutine croak_no_ref: called CC=1 SCAR=0.0
Pod undocumented
6445 1 croak "Error: Wrong type argument from interpolated code:\n".
6446 "\tExpected scalar, but found ".my_dumper($self);
6447 }
6448  
6449 ########################################
6450 # Generators:
6451  
6452 # These functions are used to typecheck interpolated Perl code's
6453 # result values and to generate objects on the fly if that's possible.
6454 # Usually on-the-fly generation coerces basic Perl types to a blessed
6455 # object, but it would also be feasible to coerce objects to objects.
6456 # Some 'generator' functions don't generate at all, but simply type
6457 # check.
6458 #
6459 # Note: often these functions are invoked in string context, which
6460 # means that directly after their invocation, the string cast operator
6461 # is invoked. However, there's no easy way to prevent object creation
6462 # in that case, because there is no such thing as 'wantstring'
6463 # (would-be analog to 'wantarray'). So these functions must always
6464 # return a blessed reference.
6465  
6466 sub _functor($$@)
6467 {
6468 106 ▶ my ($functor, $parens, @arg)= @_;
Subroutine _functor: called CC=4 SCAR=13.9
6469  
6470 # possibly translate the functor to a different SQL dialect:
6471 106 ▶ if (my $dialect= $functor->{dialect}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dialect = $functor->{"dialect"}) 97 9 106
6472 97 ▶ if (my $f2= find_ref(%$dialect, $write_dialect)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f2 = &find_ref(\%$dialect, $write_dialect)) 28 69 97
6473 28 $functor= $f2;
6474 }
6475 }
6476  
6477 # print it:
6478 106 my $name= $functor->{value};
6479  
6480 # prefix and suffix are not handled here, because they behave
6481 # differently: they assume exactly one argument are applied
6482 # point-wise. They cannot be switched (ok, we might switch
6483 # between prefix and suffix, but that's not supported yet).
6484 my $s= switch ($functor->{type},
6485 'infix()' => sub {
6486 (scalar(@arg) ?
6487 join(" $name ", @arg)
6488 : defined($functor->{result0}) ?
6489 get_quote_val->($functor->{result0})
6490 52 ▶ : die "Error: Functor $functor->{value} used with 0 args, but requires at least one."
Subroutine __ANON__: called CC=3 SCAR=11.2
Branch: 2 branches
BranchTrueFalseTotal
scalar @arg ? : 46 6 52
defined $functor->{'result0'} ? : 6 0 6
6491 );
6492 },
6493 'funcall' => sub {
6494 21 ▶ $parens= 0;
Subroutine __ANON__: called CC=1 SCAR=0.0
6495 21 "$name(".join(", ", @arg).")";
6496 },
6497 'prefix' => sub {
6498 26 ▶ die "Error: Exactly one argument expected for operator $functor->{value},\n".
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @arg == 1 1 25 26
6499 "\tfound (".join(",", @arg).")"
6500 unless scalar(@arg) == 1;
6501 25 "$name $arg[0]"
6502 },
6503 'suffix' => sub {
6504 7 ▶ die "Error: exactly one argument expected, found @arg" unless scalar(@arg) == 1;
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @arg == 1 0 7 7
6505 7 "$arg[0] $name"
6506 },
6507 106 );
6508 105 ▶ return $parens ? "($s)" : $s;
Branch: 1 branch
BranchTrueFalseTotal
$parens ? : 35 70 105
6509 }
6510  
6511 sub _prefix($$@)
6512 {
6513 67 ▶ my ($name, $parens)= splice @_,0,2;
Subroutine _prefix: called CC=2 SCAR=6.9
6514 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
6515 }
6516  
6517 sub _suffix($$@)
6518 {
6519 39 ▶ my ($name, $parens)= splice @_,0,2;
Subroutine _suffix: called CC=1 SCAR=0.0
6520 39 return _functor($functor_suffix{$name}, $parens, @_);
6521 }
6522  
6523 sub _max1_if_scalar(@)
6524 {
6525 # void context:
6526 219 ▶ unless (defined wantarray) {
Subroutine _max1_if_scalar: called CC=5 SCAR=16.1
Branch: 1 branch
BranchTrueFalseTotal
unless (defined wantarray) 1 218 219
6527 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
6528 1 croak 'Error: NYI: void context is currently not supported for SQL blocks.';
6529 }
6530  
6531 # list context:
6532 218 ▶ return @_ if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 27 191 218
6533  
6534 # scalar context:
6535 191 ▶ croak 'Error: Multiple results cannot be assigned to scalar'
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 1 1 190 191
6536 if scalar(@_) > 1;
6537 190 return $_[0];
6538 }
6539  
6540 sub min1(@)
6541 {
6542 0 ▶ croak 'Error: Expected at least one element, but found an empty list'
Subroutine min1: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 0 0 0 0
6543 if scalar(@_) == 0;
6544 0 return @_;
6545 }
6546  
6547 sub min1default($@)
6548 {
6549 0 ▶ return @_ if scalar(@_) == 1;
Subroutine min1default: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 1 0 0 0
6550 0 shift;
6551 0 return @_;
6552 }
6553  
6554 sub joinlist($$$$$@)
6555 {
6556 213 ▶ if (scalar(@_) == 5) {
Subroutine joinlist: called CC=3 SCAR=12.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 5) 1 212 213
6557 1 ▶ return $_[1] if defined $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[1] 1 0 1
6558 0 my ($module, $file, $line)= caller;
6559 0 croak "$file:$_[0]: Error: Expected at least one element, but found an empty list";
6560 }
6561 212 return $_[2].join ($_[3], @_[5..$#_]).$_[4];
6562 }
6563  
6564 sub assign($) # check that the result is an assignment, i.e.:`a` = <expr>
6565 {
6566 14 ▶ my ($x)= @_;
Subroutine assign: called CC=2 SCAR=7.6
Pod undocumented
6567 14 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 14 0 14
6568 14 return $x->assign();
6569 }
6570 else {
6571 0 croak "Assignment expected, but found non-reference.";
6572 }
6573 }
6574  
6575 sub set2values(@)
6576 {
6577 7 ▶ croak "At least one value expected" if scalar(@_) == 0;
Subroutine set2values: called CC=2 SCAR=7.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ == 0 0 7 7
6578 return
6579 ' ('.
6580 14 join(',', map { assign($_)->arg1() } @_).
6581 ') VALUES ('.
6582 7 join(',', map { $_->arg2() } @_).
6583 ')';
6584 }
6585  
6586 sub exprlist($)
6587 {
6588 7 ▶ my ($x)= @_;
Subroutine exprlist: called CC=3 SCAR=11.3
Pod undocumented
6589 7 ▶ croak "Array reference expected for expression list"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $x eq "ARRAY" 0 7 7
6590 unless ref($x) eq 'ARRAY';
6591 7 ▶ croak "At least one element expected in expression list"
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$x >= 1 0 7 7
6592 unless scalar(@$x) >= 1;
6593 7 return '('.join(', ', map { expr($_) } @$x).')';
6594 }
6595  
6596 ####################
6597 # Type
6598  
6599 sub type($)
6600 {
6601 7 ▶ my ($x)= @_;
Subroutine type: called CC=2 SCAR=7.6
Pod undocumented
6602 7 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 7 0 7
6603 7 return $x->type();
6604 }
6605 else {
6606 0 croak "Type expected, but found non-reference (user types are not supported yet).";
6607 }
6608 }
6609  
6610 # These have $self at the end because it's easier to generate code like that.
6611 sub type_base($$)
6612 {
6613 11 ▶ my $self= pop @_;
Subroutine type_base: called CC=3 SCAR=11.3
Pod undocumented
6614 11 my ($base)= @_;
6615 11 ▶ croak "Unrecognised base type '$base'" unless
Branch: 1 branch
BranchTrueFalseTotal
unless my $spec = &find_ref(\%type_spec, $base) 0 11 11
6616 my $spec= find_ref(%type_spec, $base);
6617 11 ▶ die unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 11 11
6618 11 return $self->set_base($base, $spec);
6619 }
6620  
6621 sub type_basewlist($@)
6622 {
6623 0 ▶ my $self= pop @_;
Subroutine type_basewlist: not called CC=3 SCAR=24.8
Pod undocumented
6624 0 my ($base, @value)= @_;
6625 0 ▶ croak "Unrecognised base type '$base'" unless
Branch: 1 branch
BranchTrueFalseTotal
unless my $spec = &find_ref(\%type_spec, $base) 0 0 0
6626 my $spec= find_ref(%type_spec, $base);
6627 0 ▶ die unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
6628 0 $self->set_base($base, $spec);
6629 0 $self->set_property('value_list', \@value);
6630 0 return $self;
6631 }
6632  
6633 sub type_length($$;$)
6634 {
6635 11 ▶ my $self= pop @_;
Subroutine type_length: called CC=2 SCAR=7.0
Pod undocumented
6636 11 my ($prec1, $prec2)= @_;
6637 11 $self->set_property('prec1', $prec1);
6638 11 ▶ $self->set_property('prec2', $prec2) if defined $prec2;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prec2 0 11 11
6639 11 return $self;
6640 }
6641  
6642 sub type_largelength($$$;$)
6643 {
6644 0 ▶ my $self= pop @_;
Subroutine type_largelength: not called CC=3 SCAR=24.8
Pod undocumented
6645 0 my ($coeff, $mul, $unit)= @_;
6646 0 $self->set_property('prec1', $coeff);
6647 0 ▶ $self->set_property('prec_mul', $mul) if defined $mul;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mul 0 0 0
6648 0 ▶ $self->set_property('prec_unit', $unit) if defined $unit;
Branch: 1 branch
BranchTrueFalseTotal
if defined $unit 0 0 0
6649 0 return $self;
6650 }
6651  
6652 sub type_property($$$)
6653 {
6654 2 ▶ my $self= pop @_;
Subroutine type_property: called CC=1 SCAR=0.0
Pod undocumented
6655 2 my ($key,$value)= @_;
6656 2 $self->set_property($key,$value);
6657 2 return $self;
6658 }
6659  
6660 ####################
6661 # ColumnSpec
6662  
6663 sub colspec($)
6664 {
6665 2 ▶ my ($x)= @_;
Subroutine colspec: called CC=2 SCAR=7.6
Pod undocumented
6666 2 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 2 0 2
6667 2 return $x->colspec();
6668 }
6669 else {
6670 0 croak "ColumnSpec expected, but found non-reference (user types are not supported yet).";
6671 }
6672 }
6673  
6674 sub colspec_property($$$$)
6675 {
6676 4 ▶ my $self= pop @_;
Subroutine colspec_property: called CC=1 SCAR=0.0
Pod undocumented
6677 4 my ($name, $key, $value)= @_;
6678 4 $self->{name}{$key}= $name;
6679 4 $self->{option}{$key}= $value;
6680 4 return $self;
6681 }
6682  
6683 sub colspec_type_base($$)
6684 {
6685 0 ▶ my $self= pop @_;
Subroutine colspec_type_base: not called CC=1 SCAR=6.9
Pod undocumented
6686 0 my ($base)= @_;
6687 0 type_base($base, $self->{datatype});
6688 0 return $self;
6689 }
6690  
6691 sub colspec_type_property($$$)
6692 {
6693 0 ▶ my $self= pop @_;
Subroutine colspec_type_property: not called CC=1 SCAR=6.9
Pod undocumented
6694 0 my ($key, $value)= @_;
6695 0 type_property($key, $value, $self->{datatype});
6696 0 return $self;
6697 }
6698  
6699 sub colspec_type_basewlist($@)
6700 {
6701 0 ▶ my $self= pop @_;
Subroutine colspec_type_basewlist: not called CC=1 SCAR=6.9
Pod undocumented
6702 0 my ($base, @value)= @_;
6703 0 type_basewlist($base, @value, $self->{datatype});
6704 0 return $self;
6705 }
6706  
6707 sub colspec_type_length($$;$)
6708 {
6709 0 ▶ my $self= pop @_;
Subroutine colspec_type_length: not called CC=1 SCAR=6.9
Pod undocumented
6710 0 my ($prec1, $prec2)= @_;
6711 0 type_length($prec1, $prec2, $self->{datatype});
6712 0 return $self;
6713 }
6714  
6715 sub colspec_type_largelength($$$;$)
6716 {
6717 0 ▶ my $self= pop @_;
Subroutine colspec_type_largelength: not called CC=1 SCAR=6.9
Pod undocumented
6718 0 my ($coeff, $mul, $unit)= @_;
6719 0 type_largelength($coeff, $mul, $unit, $self->{datatype});
6720 0 return $self;
6721 }
6722  
6723 ####################
6724 # identifier interpolation, column and table:
6725  
6726 sub tabname($)
6727 {
6728 1 ▶ my ($x)= @_;
Subroutine tabname: called CC=3 SCAR=13.3
Pod undocumented
6729 1 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 0 1 1
elsif (defined $x) { } 1 0 1
6730 0 return $x->tabname;
6731 }
6732 elsif (defined $x) {
6733 1 return SQL::Yapp::TableName->obj(get_quote_id->($xlat_table->($x)));
6734 }
6735 else {
6736 0 croak "Error: Cannot use undef/NULL as a table name";
6737 }
6738 }
6739  
6740 # Schema-qualified names:
6741 sub schemaname1($$$)
6742 {
6743 122 ▶ my ($class,$xlat,$x)= @_;
Subroutine schemaname1: called CC=2 SCAR=7.6
Pod undocumented
6744 122 ▶ if (defined $x) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $x) { } 122 0 122
6745 122 return $class->obj(get_quote_id->($xlat->($x)));
6746 }
6747 else {
6748 0 croak "Error: Cannot use undef/NULL as a table name";
6749 }
6750 }
6751  
6752 sub schemaname2($$$$)
6753 {
6754 2 ▶ my ($class,$xlat,$x,$y)= @_;
Subroutine schemaname2: called CC=5 SCAR=17.0
Pod undocumented
6755  
6756 2 ▶ if (ref($x)) { croak_no_ref($x); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) 1 1 2
6757 1 ▶ if (ref($y)) { croak_no_ref($y); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $y) 0 1 1
6758 1 ▶ croak "Error: Cannot use undef/NULL as an identifier"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $y 0 1 1
6759 unless defined $y;
6760  
6761 1 ▶ return $class->obj(
Branch: 1 branch
BranchTrueFalseTotal
defined $x ? : 1 0 1
6762 get_quote_id->(
6763 undef,
6764 (defined $x ? $xlat_schema->($x) : undef),
6765 $xlat->($y)));
6766 }
6767  
6768 sub schemaname3($$$$$)
6769 {
6770 3 ▶ my ($class,$xlat,$x,$y,$z)= @_;
Subroutine schemaname3: called CC=7 SCAR=23.8
Pod undocumented
6771 3 ▶ if (ref($x)) { croak_no_ref($x); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) 0 3 3
6772 3 ▶ if (ref($y)) { croak_no_ref($y); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $y) 0 3 3
6773 3 ▶ if (ref($z)) { croak_no_ref($z); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $z) 0 3 3
6774 3 ▶ croak "Error: Cannot use undef/NULL as an identifier"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $z 0 3 3
6775 unless defined $z;
6776  
6777 3 ▶ return $class->obj(
Branch: 2 branches
BranchTrueFalseTotal
defined $x ? : 3 0 3
defined $y ? : 3 0 3
6778 get_quote_id->(
6779 (defined $x ? $xlat_catalog->($x) : undef),
6780 (defined $y ? $xlat_schema->($y) : undef),
6781 $xlat->($z)));
6782 }
6783  
6784  
6785 # Table:
6786 sub table1($)
6787 {
6788 124 ▶ my ($x)= @_;
Subroutine table1: called CC=2 SCAR=6.9
Pod undocumented
6789 124 ▶ return ref($x) ? $x->table1 : schemaname1('SQL::Yapp::Table', $xlat_table, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 5 119 124
6790 }
6791  
6792 sub table2($$)
6793 {
6794 2 ▶ my ($x,$y)= @_;
Subroutine table2: called CC=1 SCAR=0.0
Pod undocumented
6795 2 return schemaname2('SQL::Yapp::Table', $xlat_table, $x, $y);
6796 }
6797  
6798 sub table3($$$)
6799 {
6800 3 ▶ my ($x,$y,$z)= @_;
Subroutine table3: called CC=1 SCAR=0.0
Pod undocumented
6801 3 return schemaname3('SQL::Yapp::Table', $xlat_table, $x, $y, $z);
6802 }
6803  
6804  
6805 # Index:
6806 sub index1($)
6807 {
6808 0 ▶ my ($x)= @_;
Subroutine index1: not called CC=2 SCAR=17.9
Pod undocumented
6809 0 ▶ return ref($x) ? $x->index1 : schemaname1('SQL::Yapp::Index', $xlat_index, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6810 }
6811  
6812 sub index2($$)
6813 {
6814 0 ▶ my ($x,$y)= @_;
Subroutine index2: not called CC=1 SCAR=6.9
Pod undocumented
6815 0 return schemaname2('SQL::Yapp::Index', $xlat_index, $x, $y);
6816 }
6817  
6818 sub index3($$$)
6819 {
6820 0 ▶ my ($x,$y,$z)= @_;
Subroutine index3: not called CC=1 SCAR=6.9
Pod undocumented
6821 0 return schemaname3('SQL::Yapp::Index', $xlat_index, $x, $y, $z);
6822 }
6823  
6824  
6825 # CharSet:
6826 sub charset1($)
6827 {
6828 2 ▶ my ($x)= @_;
Subroutine charset1: called CC=2 SCAR=7.2
Pod undocumented
6829 2 ▶ return ref($x) ? $x->charset1 : schemaname1('SQL::Yapp::CharSet', $xlat_charset, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 2 2
6830 }
6831  
6832 sub charset2($$)
6833 {
6834 0 ▶ my ($x,$y)= @_;
Subroutine charset2: not called CC=1 SCAR=6.9
Pod undocumented
6835 0 return schemaname2('SQL::Yapp::CharSet', $xlat_charset, $x, $y);
6836 }
6837  
6838 sub charset3($$$)
6839 {
6840 0 ▶ my ($x,$y,$z)= @_;
Subroutine charset3: not called CC=1 SCAR=6.9
Pod undocumented
6841 0 return schemaname3('SQL::Yapp::CharSet', $xlat_charset, $x, $y, $z);
6842 }
6843  
6844  
6845 # Collate:
6846 sub collate1($)
6847 {
6848 0 ▶ my ($x)= @_;
Subroutine collate1: not called CC=2 SCAR=17.9
Pod undocumented
6849 0 ▶ return ref($x) ? $x->collate1 : schemaname1('SQL::Yapp::Collate', $xlat_collate, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6850 }
6851  
6852 sub collate2($$)
6853 {
6854 0 ▶ my ($x,$y)= @_;
Subroutine collate2: not called CC=1 SCAR=6.9
Pod undocumented
6855 0 return schemaname2('SQL::Yapp::Collate', $xlat_collate, $x, $y);
6856 }
6857  
6858 sub collate3($$$)
6859 {
6860 0 ▶ my ($x,$y,$z)= @_;
Subroutine collate3: not called CC=1 SCAR=6.9
Pod undocumented
6861 0 return schemaname3('SQL::Yapp::Collate', $xlat_collate, $x, $y, $z);
6862 }
6863  
6864  
6865 # Constraint:
6866 sub constraint1($)
6867 {
6868 0 ▶ my ($x)= @_;
Subroutine constraint1: not called CC=2 SCAR=17.9
Pod undocumented
6869 0 ▶ return ref($x) ? $x->constraint1 : schemaname1('SQL::Yapp::Constraint', $xlat_constraint, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6870 }
6871  
6872 sub constraint2($$)
6873 {
6874 0 ▶ my ($x,$y)= @_;
Subroutine constraint2: not called CC=1 SCAR=6.9
Pod undocumented
6875 0 return schemaname2('SQL::Yapp::Constraint', $xlat_constraint, $x, $y);
6876 }
6877  
6878 sub constraint3($$$)
6879 {
6880 0 ▶ my ($x,$y,$z)= @_;
Subroutine constraint3: not called CC=1 SCAR=6.9
Pod undocumented
6881 0 return schemaname3('SQL::Yapp::Constraint', $xlat_constraint, $x, $y, $z);
6882 }
6883  
6884  
6885 # Transliteration:
6886 sub transliteration1($)
6887 {
6888 0 ▶ my ($x)= @_;
Subroutine transliteration1: not called CC=2 SCAR=17.9
Pod undocumented
6889 0 ▶ return ref($x) ? $x->transliteration1 : schemaname1('SQL::Yapp::Transliteration', $xlat_transliteration, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6890 }
6891  
6892 sub transliteration2($$)
6893 {
6894 0 ▶ my ($x,$y)= @_;
Subroutine transliteration2: not called CC=1 SCAR=6.9
Pod undocumented
6895 0 return schemaname2('SQL::Yapp::Transliteration', $xlat_transliteration, $x, $y);
6896 }
6897  
6898 sub transliteration3($$$)
6899 {
6900 0 ▶ my ($x,$y,$z)= @_;
Subroutine transliteration3: not called CC=1 SCAR=6.9
Pod undocumented
6901 0 return schemaname3('SQL::Yapp::Transliteration', $xlat_transliteration, $x, $y, $z);
6902 }
6903  
6904  
6905 # Transcoding:
6906 sub transcoding1($)
6907 {
6908 0 ▶ my ($x)= @_;
Subroutine transcoding1: not called CC=2 SCAR=17.9
Pod undocumented
6909 0 ▶ return ref($x) ? $x->transcoding1 : schemaname1('SQL::Yapp::Transcoding', $xlat_transcoding, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 0 0
6910 }
6911  
6912 sub transcoding2($$)
6913 {
6914 0 ▶ my ($x,$y)= @_;
Subroutine transcoding2: not called CC=1 SCAR=6.9
Pod undocumented
6915 0 return schemaname2('SQL::Yapp::Transcoding', $xlat_transcoding, $x, $y);
6916 }
6917  
6918 sub transcoding3($$$)
6919 {
6920 0 ▶ my ($x,$y,$z)= @_;
Subroutine transcoding3: not called CC=1 SCAR=6.9
Pod undocumented
6921 0 return schemaname3('SQL::Yapp::Transcoding', $xlat_transcoding, $x, $y, $z);
6922 }
6923  
6924  
6925 # Engine:
6926 sub engine1($)
6927 {
6928 1 ▶ my ($x)= @_;
Subroutine engine1: called CC=2 SCAR=7.2
Pod undocumented
6929 1 ▶ return ref($x) ? $x->engine1 : schemaname1('SQL::Yapp::Engine', $xlat_engine, $x);
Branch: 1 branch
BranchTrueFalseTotal
ref $x ? : 0 1 1
6930 }
6931  
6932 sub engine2($$)
6933 {
6934 0 ▶ my ($x,$y)= @_;
Subroutine engine2: not called CC=1 SCAR=6.9
Pod undocumented
6935 0 return schemaname2('SQL::Yapp::Engine', $xlat_engine, $x, $y);
6936 }
6937  
6938 sub engine3($$$)
6939 {
6940 0 ▶ my ($x,$y,$z)= @_;
Subroutine engine3: not called CC=1 SCAR=6.9
Pod undocumented
6941 0 return schemaname3('SQL::Yapp::Engine', $xlat_engine, $x, $y, $z);
6942 }
6943  
6944  
6945 # Columns:
6946 sub colname($)
6947 {
6948 10 ▶ my ($x)= @_;
Subroutine colname: called CC=3 SCAR=13.3
Pod undocumented
6949 10 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 0 10 10
elsif (defined $x) { } 10 0 10
6950 0 return $x->colname;
6951 }
6952 elsif (defined $x) {
6953 10 return SQL::Yapp::ColumnName->obj(get_quote_id->($xlat_column->($x)));
6954 }
6955 else {
6956 0 croak "Error: Cannot use undef/NULL as a column name";
6957 }
6958 }
6959  
6960 sub column1($)
6961 {
6962 209 ▶ my ($x)= @_;
Subroutine column1: called CC=3 SCAR=11.3
Pod undocumented
6963 209 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 4 205 209
elsif (defined $x) { } 205 0 205
6964 4 return $x->column1;
6965 }
6966 elsif (defined $x) {
6967 205 return SQL::Yapp::Column->obj(get_quote_id->($xlat_column->($x)));
6968 }
6969 else {
6970 0 croak "Error: Cannot use undef/NULL as an identifier";
6971 }
6972 }
6973  
6974 sub column1_single($) #internal
6975 {
6976 25 ▶ my ($x)= @_;
Subroutine column1_single: called CC=3 SCAR=11.3
Pod undocumented
6977 25 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 1 24 25
elsif (defined $x) { } 24 0 24
6978 1 return $x->column1_single;
6979 }
6980 elsif (defined $x) {
6981 24 return get_quote_id->($xlat_column->($x));
6982 }
6983 else {
6984 0 croak "Error: Cannot use undef/NULL as an identifier";
6985 }
6986 }
6987  
6988 sub column2($$)
6989 {
6990 25 ▶ my ($x,$y)= @_;
Subroutine column2: called CC=1 SCAR=0.0
Pod undocumented
6991 25 return SQL::Yapp::Column->obj(table1($x).'.'.column1_single($y));
6992 }
6993  
6994 sub column3($$$)
6995 {
6996 0 ▶ my ($x,$y,$z)= @_;
Subroutine column3: not called CC=1 SCAR=6.9
Pod undocumented
6997 0 return SQL::Yapp::Column->obj(table2($x,$y).'.'.column1_single($z));
6998 }
6999  
7000 sub column4($$$$)
7001 {
7002 0 ▶ my ($w,$x,$y,$z)= @_;
Subroutine column4: not called CC=1 SCAR=6.9
Pod undocumented
7003 0 return SQL::Yapp::Column->obj(table3($w,$x,$y).'.'.column1_single($z));
7004 }
7005  
7006 # Generated with mkidentn.pl:
7007 0 ▶sub table1_n($) { map { table1 ($_ ) } @{ $_[0] } }
Subroutine table1_n: not called CC=1 SCAR=6.9
Pod undocumented
7008 0 ▶sub table2_1n($$) { map { table2 ($_[0], $_ ) } @{ $_[1] } }
Subroutine table2_1n: not called CC=1 SCAR=6.9
Pod undocumented
7009 0 ▶sub table2_n1($$) { map { table2 ($_ , $_[1]) } @{ $_[0] } }
Subroutine table2_n1: not called CC=1 SCAR=6.9
Pod undocumented
7010 0 ▶sub table2_nn($$) { map { table2_1n ($_ , $_[1]) } @{ $_[0] } }
Subroutine table2_nn: not called CC=1 SCAR=6.9
Pod undocumented
7011 0 ▶sub table3_11n($$$) { map { table3 ($_[0], $_[1], $_ ) } @{ $_[2] } }
Subroutine table3_11n: not called CC=1 SCAR=6.9
Pod undocumented
7012 0 ▶sub table3_1n1($$$) { map { table3 ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine table3_1n1: not called CC=1 SCAR=6.9
Pod undocumented
7013 0 ▶sub table3_1nn($$$) { map { table3_11n ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine table3_1nn: not called CC=1 SCAR=6.9
Pod undocumented
7014 0 ▶sub table3_n11($$$) { map { table3 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_n11: not called CC=1 SCAR=6.9
Pod undocumented
7015 0 ▶sub table3_n1n($$$) { map { table3_11n ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_n1n: not called CC=1 SCAR=6.9
Pod undocumented
7016 0 ▶sub table3_nn1($$$) { map { table3_1n1 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_nn1: not called CC=1 SCAR=6.9
Pod undocumented
7017 0 ▶sub table3_nnn($$$) { map { table3_1nn ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine table3_nnn: not called CC=1 SCAR=6.9
Pod undocumented
7018  
7019 0 ▶sub column1_n($) { map { column1 ($_ ) } @{ $_[0] } }
Subroutine column1_n: not called CC=1 SCAR=6.9
Pod undocumented
7020 4 ▶sub column2_1n($$) { map { column2 ($_[0], $_ ) } @{ $_[1] } }
Subroutine column2_1n: called CC=1 SCAR=0.0
Pod undocumented
7021 0 ▶sub column2_n1($$) { map { column2 ($_ , $_[1]) } @{ $_[0] } }
Subroutine column2_n1: not called CC=1 SCAR=6.9
Pod undocumented
7022 2 ▶sub column2_nn($$) { map { column2_1n ($_ , $_[1]) } @{ $_[0] } }
Subroutine column2_nn: called CC=1 SCAR=0.0
Pod undocumented
7023 0 ▶sub column3_11n($$$) { map { column3 ($_[0], $_[1], $_ ) } @{ $_[2] } }
Subroutine column3_11n: not called CC=1 SCAR=6.9
Pod undocumented
7024 0 ▶sub column3_1n1($$$) { map { column3 ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine column3_1n1: not called CC=1 SCAR=6.9
Pod undocumented
7025 0 ▶sub column3_1nn($$$) { map { column3_11n ($_[0], $_ , $_[2]) } @{ $_[1] } }
Subroutine column3_1nn: not called CC=1 SCAR=6.9
Pod undocumented
7026 0 ▶sub column3_n11($$$) { map { column3 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_n11: not called CC=1 SCAR=6.9
Pod undocumented
7027 0 ▶sub column3_n1n($$$) { map { column3_11n ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_n1n: not called CC=1 SCAR=6.9
Pod undocumented
7028 0 ▶sub column3_nn1($$$) { map { column3_1n1 ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_nn1: not called CC=1 SCAR=6.9
Pod undocumented
7029 0 ▶sub column3_nnn($$$) { map { column3_1nn ($_ , $_[1], $_[2]) } @{ $_[0] } }
Subroutine column3_nnn: not called CC=1 SCAR=6.9
Pod undocumented
7030 0 ▶sub column4_111n($$$$) { map { column4 ($_[0], $_[1], $_[2], $_ ) } @{ $_[3] } }
Subroutine column4_111n: not called CC=1 SCAR=6.9
Pod undocumented
7031 0 ▶sub column4_11n1($$$$) { map { column4 ($_[0], $_[1], $_ , $_[3]) } @{ $_[2] } }
Subroutine column4_11n1: not called CC=1 SCAR=6.9
Pod undocumented
7032 0 ▶sub column4_11nn($$$$) { map { column4_111n ($_[0], $_[1], $_ , $_[3]) } @{ $_[2] } }
Subroutine column4_11nn: not called CC=1 SCAR=6.9
Pod undocumented
7033 0 ▶sub column4_1n11($$$$) { map { column4 ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1n11: not called CC=1 SCAR=6.9
Pod undocumented
7034 0 ▶sub column4_1n1n($$$$) { map { column4_111n ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1n1n: not called CC=1 SCAR=6.9
Pod undocumented
7035 0 ▶sub column4_1nn1($$$$) { map { column4_11n1 ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1nn1: not called CC=1 SCAR=6.9
Pod undocumented
7036 0 ▶sub column4_1nnn($$$$) { map { column4_11nn ($_[0], $_ , $_[2], $_[3]) } @{ $_[1] } }
Subroutine column4_1nnn: not called CC=1 SCAR=6.9
Pod undocumented
7037 0 ▶sub column4_n111($$$$) { map { column4 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n111: not called CC=1 SCAR=6.9
Pod undocumented
7038 0 ▶sub column4_n11n($$$$) { map { column4_111n ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n11n: not called CC=1 SCAR=6.9
Pod undocumented
7039 0 ▶sub column4_n1n1($$$$) { map { column4_11n1 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n1n1: not called CC=1 SCAR=6.9
Pod undocumented
7040 0 ▶sub column4_n1nn($$$$) { map { column4_11nn ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_n1nn: not called CC=1 SCAR=6.9
Pod undocumented
7041 0 ▶sub column4_nn11($$$$) { map { column4_1n11 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nn11: not called CC=1 SCAR=6.9
Pod undocumented
7042 0 ▶sub column4_nn1n($$$$) { map { column4_1n1n ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nn1n: not called CC=1 SCAR=6.9
Pod undocumented
7043 0 ▶sub column4_nnn1($$$$) { map { column4_1nn1 ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nnn1: not called CC=1 SCAR=6.9
Pod undocumented
7044 0 ▶sub column4_nnnn($$$$) { map { column4_1nnn ($_ , $_[1], $_[2], $_[3]) } @{ $_[0] } }
Subroutine column4_nnnn: not called CC=1 SCAR=6.9
Pod undocumented
7045  
7046 ####################
7047 # stmt interpolation:
7048  
7049 sub stmt($)
7050 {
7051 3 ▶ my ($x)= @_;
Subroutine stmt: called CC=2 SCAR=7.6
Pod undocumented
7052 3 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 3 0 3
7053 3 return $x->stmt;
7054 }
7055 else {
7056 0 croak "Error: Expected 'Stmt' object, but found: ".my_dumper($x);
7057 }
7058 }
7059  
7060 sub subquery($)
7061 {
7062 1 ▶ my ($x1)= @_;
Subroutine subquery: called CC=1 SCAR=0.0
Pod undocumented
7063 1 my $x= SQL::Yapp::Stmt->obj($x1);
7064 1 return $x->subquery;
7065 }
7066  
7067 ####################
7068 # expr interpolation:
7069  
7070 sub exprparen($)
7071 {
7072 70 ▶ my ($x)= @_;
Subroutine exprparen: called CC=6 SCAR=18.6
Pod undocumented
7073 70 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 5 65 70
7074 5 ▶ die Dumper($x) if ref($x) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "HASH" 0 5 5
7075 5 ▶ die Dumper($x) if ref($x) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "ARRAY" 0 5 5
7076 5 ▶ die Dumper($x) if ref($x) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "CODE" 0 5 5
7077 5 ▶ die Dumper($x) if ref($x) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $x eq "SCALAR" 0 5 5
7078 5 return $x->exprparen;
7079 }
7080 else {
7081 65 return SQL::Yapp::Expr->obj(get_quote_val->($x)); # raw perl scalar: quote as value, no parens
7082 }
7083 }
7084  
7085 sub expr($)
7086 {
7087 153 ▶ my ($x)= @_;
Subroutine expr: called CC=3 SCAR=11.0
Pod undocumented
7088 153 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 21 132 153
7089 21 ▶ confess 'Error: Trying to invoke $x->expr() on unblessed reference $x ".
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($x) 0 21 21
7090 "(maybe missing nested sqlExpr{...} inside a block, or ".
7091 "additional () around {} interpolation?)'
7092 unless blessed($x);
7093 21 return $x->expr;
7094 }
7095 else {
7096 132 return SQL::Yapp::Expr->obj(get_quote_val->($x)); # raw perl scalar: quote as value
7097 }
7098 }
7099  
7100 sub expr_or_check($)
7101 {
7102 5 ▶ my ($x)= @_;
Subroutine expr_or_check: called CC=2 SCAR=6.9
Pod undocumented
7103 5 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 3 2 5
7104 3 return $x->expr_or_check;
7105 }
7106 else {
7107 2 return SQL::Yapp::Expr->obj(get_quote_val->($x)); # raw perl scalar: quote as value
7108 }
7109 }
7110  
7111 sub exprparen_hash(\%)
7112 {
7113 3 ▶ my ($x)= @_;
Subroutine exprparen_hash: called CC=3 SCAR=11.0
Pod undocumented
7114 return map {
7115 3 my $n= $_;
7116 6 my $e= $x->{$n};
7117 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
7118 '('.get_quote_id->($n).' '.$e->check.')'
7119 : '('.get_quote_id->($n).' = '.exprparen($e).')'
7120 )
7121 }
7122 sort keys %$x;
7123 }
7124  
7125 sub expr_hash(\%)
7126 {
7127 4 ▶ my ($x)= @_;
Subroutine expr_hash: called CC=3 SCAR=11.8
Pod undocumented
7128 return map {
7129 4 my $n= $_;
7130 7 my $e= $x->{$n};
7131 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
7132 '('.get_quote_id->($n).' '.$e->check.')'
7133 : SQL::Yapp::Infix->obj('=', get_quote_id->($n), exprparen($e))
7134 )
7135 }
7136 sort keys %$x;
7137 }
7138  
7139 ####################
7140 # order interpolation:
7141  
7142 sub asc($)
7143 {
7144 9 ▶ my ($x)= @_;
Subroutine asc: called CC=3 SCAR=11.3
Pod undocumented
7145 9 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 4 5 9
elsif (defined $x) { } 5 0 5
7146 4 return $x->asc;
7147 }
7148 elsif (defined $x) {
7149 5 return column1($x);
7150 }
7151 else {
7152 0 return NULL;
7153 }
7154 }
7155  
7156 sub desc($)
7157 {
7158 10 ▶ my ($x)= @_;
Subroutine desc: called CC=3 SCAR=11.3
Pod undocumented
7159 10 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 6 4 10
elsif (defined $x) { } 4 0 4
7160 6 return $x->desc;
7161 }
7162 elsif (defined $x) {
7163 4 return SQL::Yapp::Desc->obj(column1($x));
7164 }
7165 else {
7166 0 return NULL;
7167 }
7168 }
7169  
7170 ####################
7171 # table option:
7172  
7173 sub tableopt($)
7174 {
7175 2 ▶ my ($x)= @_;
Subroutine tableopt: called CC=2 SCAR=7.6
Pod undocumented
7176 2 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 2 0 2
7177 2 return $x->tableopt;
7178 }
7179 else {
7180 0 croak "Error: Expected 'TableOption' object, but found: ".my_dumper($x);
7181 }
7182 }
7183  
7184 ####################
7185 # join interpolation:
7186  
7187 sub joinclause($)
7188 {
7189 4 ▶ my ($x)= @_;
Subroutine joinclause: called CC=2 SCAR=7.6
Pod undocumented
7190 4 ▶ if (ref($x)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $x) { } 4 0 4
7191 4 return $x->joinclause;
7192 }
7193 else {
7194 0 croak "Error: Expected 'Join' object, but found: ".my_dumper($x);
7195 }
7196 }
7197  
7198 ####################
7199 # limit interpolation:
7200  
7201 sub limit_number($)
7202 {
7203 14 ▶ my ($x)= @_;
Subroutine limit_number: called CC=3 SCAR=13.3
Pod undocumented
7204 14 ▶ if (ref($x)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $x) { } 0 14 14
elsif (&looks_like_number($x)) { } 14 0 14
7205 0 return $x->limit_number;
7206 }
7207 elsif (looks_like_number $x) {
7208 14 return $x;
7209 }
7210 else {
7211 0 croak "Error: Expected number or ?, but found: ".my_dumper($x);
7212 }
7213 }
7214  
7215 sub limit($$)
7216 {
7217 2 ▶ my ($cnt, $offset)= @_;
Subroutine limit: called CC=5 SCAR=17.6
Pod undocumented
7218  
7219 # FIXME: if dialect is 'std' (or maybe 'std2008'), produce OFFSET/FETCH
7220 # clause (SQL-2008).
7221 2 ▶ if (defined $cnt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cnt) { } 1 1 2
7222 1 ▶ if (defined $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) { } 1 0 1
7223 1 return " LIMIT ".limit_number($cnt)." OFFSET ".limit_number($offset);
7224 }
7225 else {
7226 0 return " LIMIT ".limit_number($cnt);
7227 }
7228 }
7229 else {
7230 1 ▶ if (defined $offset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) { } 1 0 1
7231 1 ▶ if ($write_dialect eq 'postgresql') {
Branch: 1 branch
BranchTrueFalseTotal
if ($write_dialect eq 'postgresql') { } 0 1 1
7232 0 return " LIMIT ALL OFFSET ".limit_number($offset);
7233 }
7234 else {
7235 1 return " LIMIT ${\LARGE_LIMIT_CNT} OFFSET ".limit_number($offset);
7236 }
7237 }
7238 else {
7239 0 return '';
7240 }
7241 }
7242 }
7243  
7244 ####################
7245 # case:
7246  
7247 sub whenthen($$)
7248 {
7249 6 ▶ my ($expr, $then)= @_;
Subroutine whenthen: called CC=1 SCAR=0.0
Pod undocumented
7250 6 return 'WHEN '.$expr.' THEN '.$then;
7251 }
7252  
7253 sub caseswitch($$@)
7254 {
7255 #my ($switchval, $default, @whenthen)
7256 8 ▶ if (scalar(@_) == 2) { # @whenthen is empty => always use default
Subroutine caseswitch: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 2) 2 6 8
7257 2 return $_[1]; # return default
7258 }
7259 return
7260 6 join(' ',
7261 'CASE',
7262 $_[0],
7263 @_[2..$#_], # @whenthen
7264 'ELSE', # always generate default, it's easier.
7265 $_[1],
7266 'END'
7267 );
7268 }
7269  
7270 sub casecond($@)
7271 {
7272 #my ($default, @whenthen)
7273 0 ▶ if (scalar(@_) == 1) { # @whenthen is empty => always use default
Subroutine casecond: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) 0 0 0
7274 0 return $_[0]; # return default
7275 }
7276 return
7277 0 join(' ',
7278 'CASE',
7279 @_[1..$#_], # @whenthen
7280 'ELSE', # always generate default, it's easier.
7281 $_[0],
7282 'END'
7283 );
7284 }
7285  
7286 5 1;
7287  
7288 ######################################################################
7289 ######################################################################
7290 ######################################################################
7291  
7292 __END__
↑ Summary