| 1 | package YATT::Translator::Perl::macro_dbfetch; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | require YATT::Translator::Perl; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | YATT::Translator::Perl::make_arg_spec | |||||||||||||||||||||||||||
| 7 | (\ my %arg_dict, \ my @arg_order, qw(row sth table schema)); | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub macro { | ||||||||||||||||||||||||||
|
Subroutine
macro: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 0 | my ($trans, $scope, $args) = @_; | |||||||||||||||||||||||||||
| 11 | 0 | my $orig_node = $args->clone; | |||||||||||||||||||||||||||
| 12 | my @hash_spec | ||||||||||||||||||||||||||||
| 13 | 0 | = $trans->feed_arg_or_make_hash_of(text => $scope, $args | |||||||||||||||||||||||||||
| 14 | , \%arg_dict, \@arg_order | ||||||||||||||||||||||||||||
| 15 | , my ($rowVarName | ||||||||||||||||||||||||||||
| 16 | , $sth, $table, $schema)); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | unless ($table) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | die $trans->node_error($orig_node->parent, "table= is missing"); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my %local; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $sthVar = $sth ? node_body($sth) : 'sth'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | $local{$sthVar} = $trans->create_var('scalar' => $args | |||||||||||||||||||||||||||
| 25 | , varname => $sthVar); | ||||||||||||||||||||||||||||
| 26 | 0 | my ($loop, $else); | |||||||||||||||||||||||||||
| 27 | 0 | my $found = my $header = $args->variant_builder; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | for (; $args->readable; $args->next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | unless ($args->is_attribute) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | $found->add_node($args->current); | |||||||||||||||||||||||||||
| 31 | 0 | next; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($args->node_name eq 'row') { # XXX: body でも良いのでは? | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 34 | 0 | $loop = $args->open; | |||||||||||||||||||||||||||
| 35 | 0 | $found = $args->variant_builder; | |||||||||||||||||||||||||||
| 36 | } elsif ($args->node_name eq 'else') { | ||||||||||||||||||||||||||||
| 37 | 0 | $else = $args->open; | |||||||||||||||||||||||||||
| 38 | 0 | last; | |||||||||||||||||||||||||||
| 39 | } else { | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 0 | my @columns; | |||||||||||||||||||||||||||
| 43 | my %inner; | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | for (; $loop->readable && $loop->is_primary_attribute; $loop->next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$loop->readable and $loop->is_primary_attribute
MC/DC0%0/2
$loop->readable and $loop->is_primary_attribute
$loop->readable
$loop->is_primary_attribute
Truth table0%0/3
A and B
A= $loop->readableB= $loop->is_primary_attribute
| |||||||||||||||||||||||||||||
| 46 | 0 | my ($name, $typename) = $trans->arg_name_types($loop); | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | $inner{$name} = $trans->create_var | ||||||||||||||||||||||||||
|
Condition0%0/2
$typename || 'text'
MC/DC0%0/1
$typename || 'text'
$typename
Truth table0%0/2
A
A= $typename
| |||||||||||||||||||||||||||||
| 48 | ($typename || 'text', $loop, varname => $name); | ||||||||||||||||||||||||||||
| 49 | 0 | my $expr = $loop->node_body; | |||||||||||||||||||||||||||
| 50 | # [varName => columnExpr] | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | push @columns, [$name => defined $expr ? "$expr as $name" : $name]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my ($fetchMode, $rowVarExpr) = do { | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if (@columns) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | (array => '('.join(", ", map {'$'.$_->[0]} @columns).')') | |||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $name = $rowVarName ? node_body($rowVarName) : 'row'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $local{$name} = $trans->create_var('list' => $args | |||||||||||||||||||||||||||
| 62 | , varname => $name); | ||||||||||||||||||||||||||||
| 63 | 0 | (hashref => '$'.$name); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $loopBody = do { | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($loop) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | $trans->as_block | |||||||||||||||||||||||||||
| 70 | ($trans->as_statement_list | ||||||||||||||||||||||||||||
| 71 | ($trans->generate_body([\%inner, [\%local, $scope]], $loop))); | ||||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||
| 73 | 0 | die "NIMPL"; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # XXX: Static check! (But, to check, quoted expression is too much!) | ||||||||||||||||||||||||||||
| 78 | 0 | my $schemaExpr = $trans->default_gentype | |||||||||||||||||||||||||||
| 79 | (DBSchema => text => $scope, $args, $schema); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | my $tableExpr = $trans->faked_gentype | |||||||||||||||||||||||||||
| 82 | (text => $scope, $args, $table); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my $prepare = sprintf(q|my $%s = $this->%s->to_fetch(%s, %s, %s)| | ||||||||||||||||||||||||||||
| 85 | , $sthVar | ||||||||||||||||||||||||||||
| 86 | , $schemaExpr | ||||||||||||||||||||||||||||
| 87 | , $tableExpr | ||||||||||||||||||||||||||||
| 88 | , (@columns ? | ||||||||||||||||||||||||||||
| 89 | ('['.join(", ", map { | ||||||||||||||||||||||||||||
| 90 | 0 | YATT::Translator::Perl::qparen($_->[1]) | |||||||||||||||||||||||||||
| 91 | } @columns).']') | ||||||||||||||||||||||||||||
| 92 | : 'undef') | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | , join(", ", map {"$_->[0] => $_->[1]"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | @hash_spec)); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | my $if = sprintf(q|if (my %1$s) {%2$s; do %3$s while (%1$s); %4$s}| | |||||||||||||||||||||||||||
| 97 | , sprintf(q|%s = $%s->fetchrow_%s| | ||||||||||||||||||||||||||||
| 98 | , $rowVarExpr, $sthVar, $fetchMode) | ||||||||||||||||||||||||||||
| 99 | , $trans->as_statement_list | ||||||||||||||||||||||||||||
| 100 | ($trans->generate_body([\%local, $scope], $header)) | ||||||||||||||||||||||||||||
| 101 | , $loopBody | ||||||||||||||||||||||||||||
| 102 | , $trans->as_statement_list | ||||||||||||||||||||||||||||
| 103 | ($trans->generate_body([\%local, $scope], $found)) | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $if .= " else ".$trans->as_block | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | ($trans->as_statement_list | ||||||||||||||||||||||||||||
| 107 | ($trans->generate_body([\%local, $scope], $else))) if $else; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | \ "{$prepare; $if}"; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | 1; | |||||||||||||||||||||||||||