blib/lib/PMLTQ/SQLEvaluator.pm

filter: Statementstmt 3.3% 52 / 1566 Branchbran 0.0% 0 / 1116 Conditioncond 0.0% 0 / 686 MC/DCmcdc 0.0% 0 / 380 Subroutinesub 20.5% 16 / 78 Podpod 0.0% 0 / 53 totaltotal 1.7% 68 / 3879 CC 846 SCAR 105.4
CC
846
Cov
2%
serialize_expression_pt
104006.0
build_sql
8372.0
prepare_query
2352.0
CRAP 37629.6
↑ Summary blib/lib/PMLTQ/BtredEvaluator.pm »
1 package PMLTQ::SQLEvaluator;
2 2 our $AUTHORITY = 'cpan:MATY';
3 2 $PMLTQ::SQLEvaluator::VERSION = '1.2.2';
4 # ABSTRACT: SQL evaluator of PML-TQ queries which can use PostreSQL as a backend
5  
6 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 our $SEPARATE_TREES=0;
10  
11 2 ▶use Benchmark;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Treex::PML::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # flags stored for a PML schema in the #PML table
17 2 ▶use constant HYBRID=>1; # create both separate node table and node table with attributes
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use constant NO_TREE_TABLE=>2; # don't create one common common node table for all node types
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use constant MAX_MIN_ORD=>4; # node tables have #max_ord and #min_ord columns
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use constant TOP_TREE_FLAG=>8; # The <root>__#files table has a 'top' column indicating that
Subroutine BEGIN: called CC=1 SCAR=0.0
21 # a given root node belongs to the top-level tree list
22 # of a file (i.e. it is not a nested #NODE within
23 # some non-#NODE and non-#TREES data structure)
24  
25  
26 2 ▶use PMLTQ::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 BEGIN {
28 2 ▶ import PMLTQ::Common qw(:tredmacro :constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 }
30  
31 2 ▶use constant {PREFER_LEFT_JOINS => 1};
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use constant USE_PLANNER => 'never'; #'forests'; # 'always', 'never', 'forests'
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use PMLTQ::Planner;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35  
36 2 our $MIN_CLIENT_VERSION = '0.2';
37 2 our $ALLOW_MISPLACED_PG_JOIN = 1;
38  
39 # BEGIN { import TredMacro qw(first SeqV AltV ListV) }
40  
41  
42  
43  
44 sub check_client_version {
45 0 ▶ my ($self,$version)=@_;
Subroutine check_client_version: not called CC=4 SCAR=30.0
Pod undocumented
46 0 ▶ return (defined($version) && length($version) && Treex::PML::Schema::cmp_revisions($MIN_CLIENT_VERSION,$version)<=0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $version && length $version && Treex::PML::Schema::cmp_revisions($PMLTQ::SQLEvaluator::MIN_CLIENT_VERSION, $version) <= 0 ? : 0 0 0
Condition0%0/6
defined $version and length $version and Treex::PML::Schema::cmp_revisions($PMLTQ::SQLEvaluator::MIN_CLIENT_VERSION, $version) <= 0
!ll&&!rl&&r
000
defined $version and length $version
!ll&&!rl&&r
000
MC/DC0%0/3
defined $version and length $version and Treex::PML::Schema::cmp_revisions($PMLTQ::SQLEvaluator::MIN_CLIENT_VERSION, $version) <= 0
defined $version length $version Treex::PML::Schema::cmp_revisions($PMLTQ::SQLEvaluator::MIN_CLIENT_VERSION, $version) <= 0
Truth table0%0/4
A and B and C
A= defined $versionB= length $versionC= Treex::PML::Schema::cmp_revisions($PMLTQ::SQLEvaluator::MIN_CLIENT_VERSION, $version) <= 0
ABCresult
0XX0
10X0
1100
1111
47 }
48  
49 sub new {
50 0 ▶ my ($class,$query_tree,$opts)=@_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
51 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
52 0 die "Not supported OS, PMLTQ::SQLEvaluator requires Sys::SigAction\n";
53 } else {
54 0 require Sys::SigAction;
55 }
56  
57 my $self = bless {
58 dbi => $opts->{dbi},
59 connect => $opts->{connect},
60 debug => $opts->{debug},
61 0 results => undef,
62 query_nodes=>undef,
63 type_decls => {},
64 schema_types => {},
65 schemas => {},
66 returns_nodes => 1,
67 }, $class;
68 0 ▶ $self->prepare_query($query_tree,$opts) if $query_tree;
Branch: 1 branch
BranchTrueFalseTotal
if $query_tree 0 0 0
69 0 return $self;
70 }
71  
72 sub get_results {
73 0 ▶ my $self = shift;
Subroutine get_results: not called CC=2 SCAR=17.9
Pod undocumented
74 0 ▶ return $self->{results} || [];
Condition0%0/2
$self->{'results'} || []
l!l
00
MC/DC0%0/1
$self->{'results'} || []
$self->{'results'}
Truth table0%0/2
A
A= $self->{'results'}
Aresult
11
00
75 }
76  
77 sub get_query_nodes {
78 0 ▶ my $self = shift;
Subroutine get_query_nodes: not called CC=1 SCAR=6.9
Pod undocumented
79 0 return $self->{query_nodes};
80 }
81  
82 sub get_sql {
83 0 ▶ my $self = shift;
Subroutine get_sql: not called CC=1 SCAR=6.9
Pod undocumented
84 0 return $self->{sql};
85 }
86  
87 sub prepare_sql {
88 0 ▶ my ($self,$sql,$opts)=@_;
Subroutine prepare_sql: not called CC=3 SCAR=24.8
Pod undocumented
89 0 $self->{sth} = undef;
90 0 $self->{sql} = $sql;
91 0 ▶ my $dbi = $self->{dbi} || $self->connect();
Condition0%0/3
$self->{'dbi'} || $self->connect
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'dbi'} || $self->connect
$self->{'dbi'} $self->connect
Truth table0%0/3
A || B
A= $self->{'dbi'}B= $self->connect
ABresult
1X1
011
000
92 0 ▶ print STDERR "$sql\n" if $opts->{debug_sql};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"debug_sql"} 0 0 0
93 return $self->run_sql_query($sql,{
94 use_cursor => $opts->{use_cursor},
95 limit => $opts->{limit},
96 prepare_only => 1,
97 return_sth => 1,
98 no_distinct => $opts->{no_distinct},
99 RaiseError=>1,
100 timeout => $opts->{timeout},
101 0 });
102 }
103  
104 sub get_pmlrf_relation_map {
105 0 ▶ my ($self)=@_;
Subroutine get_pmlrf_relation_map: not called CC=1 SCAR=6.9
Pod undocumented
106 0 $self->init_relation_maps;
107 0 return $self->{pmlrf_relations_map};
108 }
109  
110 sub init_relation_maps {
111 0 ▶ my ($self)=@_;
Subroutine init_relation_maps: not called CC=11 SCAR=48.8
Pod undocumented
112 0 ▶ return if ref $self->{pmlrf_relations_map};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"pmlrf_relations_map"} 0 0 0
113 0 my @types = @{$self->get_node_types};
114 0 my %pmlrf_relations;
115 my @pmlrf_relations;
116 0 my @user_relations;
117 {
118 0 my %pmlref_map;
119 0 foreach my $node_type (@types) {
120 0 my $schema_name = $self->get_schema_name_for($node_type);
121 0 ▶ if (!exists $pmlref_map{$schema_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $pmlref_map{$schema_name}) 0 0 0
122 0 my $results = $self->run_sql_query(qq(SELECT "ref_type", "target_layer", "target_type" FROM "${schema_name}__#pmlref_map"),{ RaiseError=>1 });
123 0 my $pmlref_map = $pmlref_map{$schema_name} = {};
124 0 for my $r (@$results) {
125 # PMLREF based relation
126 0 $pmlref_map->{$r->[0]} = $r;
127 }
128 }
129 0 my $decl = $self->get_decl_for($node_type);
130 0 my @attributes = $decl->get_attribute_paths({no_nodes=>1,no_childnodes => 1});
131 0 foreach my $p (@attributes) {
132 0 my $attr_decl_path = $decl->find($p)->get_decl_path;
133 0 $attr_decl_path=~s{^!([^/]*?)(?:\.type)?(/|$)}{$1$2};
134 0 my $target = $pmlref_map{$schema_name}{$attr_decl_path};
135 0 ▶ if (defined $target) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target) 0 0 0
136 # $p =~ s/#content/content()/g;
137 0 push @pmlrf_relations, $p;
138 0 $pmlrf_relations{$node_type}{$p}=$target;
139 }
140 }
141 }
142 }
143 {
144 0 my %usr_rel;
145 0 my $usr_rels = $self->run_sql_query(qq(SELECT "relname", "reverse", "node_type", "target_node_type", "tbl" FROM "#PML_USR_REL"),
146 { RaiseError=>1 });
147 0 for my $r (@$usr_rels) {
148 0 push @user_relations, $r->[0];
149 0 ▶ push @user_relations, $r->[1] if $r->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $r->[1] 0 0 0
150 0 ▶ $usr_rel{ $r->[2] }{ $r->[0] } = [ $r->[4], undef, $r->[3] ] if $r->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $r->[0] 0 0 0
151 0 ▶ $usr_rel{ $r->[3] }{ $r->[1] } = [ undef, $r->[0], $r->[2] ] if $r->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $r->[1] 0 0 0
152 }
153 0 $self->{user_defined_relations} = \@user_relations;
154 0 $self->{user_defined_relations_map} = \%usr_rel;
155 }
156 0 my @relations = sort(uniq(@user_relations,@pmlrf_relations));
157 0 $self->{specific_relations} = \@relations;
158 0 $self->{pmlrf_relations} = [sort(uniq(@pmlrf_relations))];
159 0 $self->{pmlrf_relations_map} = \%pmlrf_relations;
160 0 return;
161 }
162  
163 sub get_pmlrf_relation_map_for_type {
164 0 ▶ my ($self,$type)=@_;
Subroutine get_pmlrf_relation_map_for_type: not called CC=7 SCAR=40.3
Pod undocumented
165 0 my $map = $self->get_pmlrf_relation_map;
166  
167 0 ▶ return $map->{$type} if exists $map->{$type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $map->{$type} 0 0 0
168 0 my %rels;
169 0 for my $nt (keys %$map) {
170 0 for my $rel (@{$self->{pmlrf_relations}}) {
171 0 ▶ if ($rel and exists($map->{$nt}{$rel}) and (($nt.'/'.$rel) =~ m{^\Q$type\E/(.*)$})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel and exists $map->{$nt}{$rel} and ($nt . '/' . $rel) =~ m[^\Q$type\E/(.*)$]) 0 0 0
Condition0%0/6
$rel and exists $map->{$nt}{$rel} and ($nt . '/' . $rel) =~ m[^\Q$type\E/(.*)$]
!ll&&!rl&&r
000
$rel and exists $map->{$nt}{$rel}
!ll&&!rl&&r
000
MC/DC0%0/3
$rel and exists $map->{$nt}{$rel} and ($nt . '/' . $rel) =~ m[^\Q$type\E/(.*)$]
$rel exists $map->{$nt}{$rel} ($nt . '/' . $rel) =~ m[^\Q$type\E/(.*)$]
Truth table0%0/4
A and B and C
A= $relB= exists $map->{$nt}{$rel}C= ($nt . '/' . $rel) =~ m[^\Q$type\E/(.*)$]
ABCresult
0XX0
10X0
1100
1111
172 0 $rels{$1}=$map->{$nt}{$rel};
173 }
174 }
175 }
176 0 return $map->{$type}=\%rels;
177 }
178  
179 sub get_user_defined_relations {
180 0 ▶ my ($self,$type)=@_;
Subroutine get_user_defined_relations: not called CC=4 SCAR=30.0
Pod undocumented
181 0 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 0 0 0
182 0 my $map = $self->get_user_defined_relation_map();
183 0 ▶ $map = ref($map) && $map->{$type};
Condition0%0/3
ref $map && $map->{$type}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $map && $map->{$type}
ref $map $map->{$type}
Truth table0%0/3
A && B
A= ref $mapB= $map->{$type}
ABresult
0X0
100
111
184 0 ▶ return $map ? [sort keys %$map] : [];
Branch: 1 branch
BranchTrueFalseTotal
$map ? : 0 0 0
185 } else {
186 0 $self->init_relation_maps;
187 0 return $self->{user_defined_relations};
188 }
189 }
190  
191 sub get_pmlrf_relations {
192 0 ▶ my ($self,$type)=@_;
Subroutine get_pmlrf_relations: not called CC=7 SCAR=40.3
Pod undocumented
193 0 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) { } 0 0 0
194 0 my $map = $self->get_pmlrf_relation_map();
195 0 ▶ return [] unless ref $map;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $map 0 0 0
196 0 my $rels = $map->{$type};
197  
198 # the type may be of the form <node-type>/<member-path>
199 # in which case we attempt to locate node-type and
200 # then select just those relations that start with member-path
201 0 my $path='';
202 0 ▶ while (!$rels and $type=~s{/([^/]+)$}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $rels and $type =~ s[/([^/]+)$][]) 0 0 0
Condition0%0/3
not $rels and $type =~ s[/([^/]+)$][]
!ll&&!rl&&r
000
MC/DC0%0/2
not $rels and $type =~ s[/([^/]+)$][]
not $rels $type =~ s[/([^/]+)$][]
Truth table0%0/3
not(A) and B
A= not $relsB= $type =~ s[/([^/]+)$][]
ABresult
0X0
100
111
203 0 $path = $1.'/'.$path;
204 0 $rels = $map->{$type};
205 }
206 0 ▶ return $rels ? [ map { /^\Q$path\E(.*)/ ? $1 : () } sort keys %$rels ] : [];
Branch: 2 branches
BranchTrueFalseTotal
$rels ? : 0 0 0
/^\Q$path\E(.*)/ ? : 0 0 0
207 } else {
208 0 $self->init_relation_maps;
209 0 return $self->{pmlrf_relations};
210 }
211 }
212  
213 sub get_specific_relations {
214 0 ▶ my $self = shift;
Subroutine get_specific_relations: not called CC=1 SCAR=6.9
Pod undocumented
215 return [uniq(
216 0 @{$self->get_pmlrf_relations(@_)},
217 0 @{$self->get_user_defined_relations(@_)},
218 )];
219 }
220  
221 sub get_user_defined_relation_map {
222 0 ▶ my ($self)=@_;
Subroutine get_user_defined_relation_map: not called CC=1 SCAR=6.9
Pod undocumented
223 0 $self->init_relation_maps;
224 0 return $self->{user_defined_relations_map};
225 }
226  
227 sub get_user_defined_relation_map_for_type {
228 0 ▶ my ($self,$type)=@_;
Subroutine get_user_defined_relation_map_for_type: not called CC=2 SCAR=17.9
Pod undocumented
229 0 my $map = $self->get_user_defined_relation_map;
230 0 ▶ return $map->{$type} if exists $map->{$type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $map->{$type} 0 0 0
231 0 return;
232 }
233  
234  
235 sub get_relation_target_type {
236 0 ▶ my ($self,$node_type,$relation,$full)=@_;
Subroutine get_relation_target_type: not called CC=5 SCAR=34.0
Pod undocumented
237 0 my $i=0;
238 0 for my $map ({ $node_type => $self->get_pmlrf_relation_map_for_type($node_type) },
239 $self->get_user_defined_relation_map) {
240 0 ▶ my $target = $map->{$node_type} && $map->{$node_type}{$relation};
Condition0%0/3
$map->{$node_type} && $map->{$node_type}{$relation}
!ll&&!rl&&r
000
MC/DC0%0/2
$map->{$node_type} && $map->{$node_type}{$relation}
$map->{$node_type} $map->{$node_type}{$relation}
Truth table0%0/3
A && B
A= $map->{$node_type}B= $map->{$node_type}{$relation}
ABresult
0X0
100
111
241 0 ▶ if ($target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target) 0 0 0
242 0 ▶ return $full ? [$i,$target] : $target->[2];
Branch: 1 branch
BranchTrueFalseTotal
$full ? : 0 0 0
243 }
244 0 $i++;
245 }
246 0 return;
247 }
248  
249 sub prepare_query {
250 0 ▶ my ($self,$query_tree,$opts)=@_;
Subroutine prepare_query: not called CC=48 SCAR=77.6
Pod undocumented
251 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
252 0 ▶ unless (ref($query_tree)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $query_tree) 0 0 0
253 0 $query_tree = PMLTQ::Common::parse_query($query_tree,{
254 pmlrf_relations => $self->get_pmlrf_relations,
255 user_defined_relations => $self->get_user_defined_relations,
256 });
257 }
258  
259 0 my $use_planner =
260 USE_PLANNER eq 'always' ? 1
261 : USE_PLANNER eq 'forests' ? ( ($query_tree->children > 0) ? 1 : 0 )
262 : 0;
263  
264 0 ▶ $self->{id} = $query_tree->{id} || 'no_ID';
Condition0%0/2
$query_tree->{'id'} || 'no_ID'
l!l
00
MC/DC0%0/1
$query_tree->{'id'} || 'no_ID'
$query_tree->{'id'}
Truth table0%0/2
A
A= $query_tree->{'id'}
Aresult
11
00
265 0 $self->{query_nodes} = [PMLTQ::Common::FilterQueryNodes($query_tree)];
266 {
267 0 my %id;
268 my %name2node_hash;
269 0 my @nodes = grep { $_->{'#name'} =~ /^(?:node|subquery)$/ } $query_tree->descendants;
270 # try to complete missing node-types
271 0 my %node_types = map { $_=> 1 } @{$self->get_node_types};
272 0 my %schema_names = map { $_=> 1 } @{$self->get_schema_names};
273 0 my $default_type = $query_tree->{'node-type'};
274 0 ▶ if ($default_type and !$node_types{$default_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default_type and not $node_types{$default_type}) 0 0 0
Condition0%0/3
$default_type and not $node_types{$default_type}
!ll&&!rl&&r
000
MC/DC0%0/2
$default_type and not $node_types{$default_type}
$default_type not $node_types{$default_type}
Truth table0%0/3
A and not(B)
A= $default_typeB= not $node_types{$default_type}
ABresult
0X0
100
111
275 0 die "The query specifies an invalid type '$default_type' as default node type!";
276 }
277 0 for my $node (@nodes) {
278 {
279 0 my $n=$node->{name};
280 0 ▶ if (defined($n) and length($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n and length $n) 0 0 0
Condition0%0/3
defined $n and length $n
!ll&&!rl&&r
000
MC/DC0%0/2
defined $n and length $n
defined $n length $n
Truth table0%0/3
A and B
A= defined $nB= length $n
ABresult
0X0
100
111
281 0 ▶ if (exists $name2node_hash{$n}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $name2node_hash{$n}) 0 0 0
282 0 die "Name \$$n used for more than one selector!\n";
283 }
284 0 $name2node_hash{$n}=$node;
285 }
286 }
287 0 ▶ if (PMLTQ::Common::IsMemberNode($node)) {
Branch: 4 branches
BranchTrueFalseTotal
if (PMLTQ::Common::IsMemberNode($node)) { } 0 0 0
elsif ($node->{'node-type'} eq '*') { } 0 0 0
elsif ($node->{'node-type'} =~ m[^([^/]+):\*$]) { } 0 0 0
elsif ($node->{'node-type'}) { } 0 0 0
288 0 ▶ if ($node->{'node-type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{'node-type'}) { } 0 0 0
289 # FIXME: we should check that the member is a valid member for
290 # its parent (member or node) node-type
291 0 my $type = PMLTQ::Common::GetMemberNodeType($node,$self);
292 0 ▶ unless ($self->get_decl_for($type)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_decl_for($type)) 0 0 0
293 0 die "Invalid type attribute path '$type' for member ".PMLTQ::Common::as_text($node)."\n";
294 }
295 } else {
296 0 die "Member must specify attribute name: ".PMLTQ::Common::as_text($node)."\n";
297 }
298 0 next;
299 } elsif ($node->{'node-type'} eq '*') {
300 0 ▶ if (keys(%schema_names)>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %schema_names > 1) 0 0 0
301 0 my ($rel) = SeqV($node->{relation});
302 0 ▶ $rel = $rel ? $rel->name : '';
Branch: 1 branch
BranchTrueFalseTotal
$rel ? : 0 0 0
303 0 die "Node-type wildcard '*' cannot be used for data with multiple layers: ".PMLTQ::Common::as_text($node)." in relation $rel\n".
304 "\nHint: try one of ".join(" ",map "$_:*", sort keys(%schema_names))."\n";
305 }
306 } elsif ($node->{'node-type'} =~ m{^([^/]+):\*$}) {
307 0 my $schema_name = $1;
308 0 ▶ if (!$schema_names{$schema_name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($schema_names{$schema_name}) 0 0 0
309 0 my ($rel) = SeqV($node->{relation});
310 0 ▶ $rel = $rel ? $rel->name : '';
Branch: 1 branch
BranchTrueFalseTotal
$rel ? : 0 0 0
311 0 die "The query specifies an invalid schema name '$schema_name' for node: ".PMLTQ::Common::as_text($node)." in relation $rel\n";
312 }
313 } elsif ($node->{'node-type'}) {
314 0 ▶ if (!$node_types{$node->{'node-type'}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node_types{$node->{"node-type"}}) 0 0 0
315 0 my ($rel) = SeqV($node->{relation});
316 0 ▶ $rel = $rel ? $rel->name : '';
Branch: 1 branch
BranchTrueFalseTotal
$rel ? : 0 0 0
317 0 die "The query specifies an invalid type '$node->{'node-type'}' for node: ".PMLTQ::Common::as_text($node)." in relation $rel\n";
318 }
319 } else {
320 0 my $parent = $node->parent;
321 0 ▶ while ($parent and ($parent->{'#name'}||'') !~/^(?:node|subquery)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and not +($parent->{"#name"} || "") =~ /^(?:node|subquery)$/) 0 0 0
Condition0%0/5
$parent and not +($parent->{"#name"} || "") =~ /^(?:node|subquery)$/
!ll&&!rl&&r
000
$parent->{'#name'} || ''
l!l
00
MC/DC0%0/2
$parent and not +($parent->{"#name"} || "") =~ /^(?:node|subquery)$/
$parent $parent->{'#name'}
Truth table0%0/3
A and not(B)
A= $parentB= $parent->{'#name'}
ABresult
0X0
110
101
322 0 $parent=$parent->parent;
323 }
324 0 my ($rel) = SeqV($node->{relation});
325 my @types =
326 ($parent && $rel) ?
327 (PMLTQ::Common::GetRelativeQueryNodeType(
328 $parent->{'node-type'},
329 $self,
330 $rel)
331 0 ▶ ) : @{$self->get_node_types};
Branch: 1 branch
BranchTrueFalseTotal
$parent && $rel ? : 0 0 0
Condition0%0/3
$parent and $rel
!ll&&!rl&&r
000
MC/DC0%0/2
$parent and $rel
$parent $rel
Truth table0%0/3
A and B
A= $parentB= $rel
ABresult
0X0
100
111
332 0 ▶ if (@types == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@types == 1) { } 0 0 0
elsif ($default_type) { } 0 0 0
333 0 $node->{'node-type'} = $types[0];
334 } elsif ($default_type) {
335 0 $node->{'node-type'} = $default_type;
336 } else {
337 die "Could not determine node type of node in ".($rel ?
338 'the '.($rel->name eq 'user-defined' ?
339 $rel->value->{label} :
340 0 ▶ $rel->name)
Branch: 3 branches
BranchTrueFalseTotal
$rel ? : 0 0 0
$rel->name eq 'user-defined' ? : 0 0 0
$parent ? : 0 0 0
341 : 'an unknown')." relation "
342 .($parent ? "to $parent->{'#name'} $parent->{'node-type'}:" : ':')
343 .PMLTQ::Common::as_text($node)."\n"
344 ."Possible types are: ".join(',',@types)." !\n";
345 }
346 }
347 }
348 # hash IDs
349 %id = map {
350 0 my $n=$_->{name};
351 0 ▶ (defined($n) and length($n)) ? ($_=>$n) : ()
Branch: 1 branch
BranchTrueFalseTotal
defined $n && length $n ? : 0 0 0
Condition0%0/3
defined $n and length $n
!ll&&!rl&&r
000
MC/DC0%0/2
defined $n and length $n
defined $n length $n
Truth table0%0/3
A and B
A= defined $nB= length $n
ABresult
0X0
100
111
352 } @nodes;
353 0 my $id = 'n0';
354 0 my %occup; @occup{values %id}=();
355 0 for my $n (@nodes) {
356 0 ▶ unless (defined $id{$n} and length $id{$n}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id{$n} and length $id{$n}) 0 0 0
Condition0%0/3
defined $id{$n} and length $id{$n}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $id{$n} and length $id{$n}
defined $id{$n} length $id{$n}
Truth table0%0/3
A and B
A= defined $id{$n}B= length $id{$n}
ABresult
0X0
100
111
357 0 ▶ $id++ while exists $occup{$id}; # just for sure
Branch: 1 branch
BranchTrueFalseTotal
exists $occup{$id} and do { ++$id } 0 0 0
358 0 $id{$n}=$id; # generate id;
359 0 ▶ if ($use_planner) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_planner) 0 0 0
360 0 $n->{name}=$id; # need for planning
361 }
362 0 $occup{$id}=1;
363 0 $name2node_hash{$id}=$n;
364 }
365 }
366 0 $self->{id_map}=\%id;
367 0 $self->{name2node}=\%name2node_hash;
368  
369  
370 }
371  
372 0 $self->{query_node_order}=undef;
373 0 ▶ if ($use_planner) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_planner) 0 0 0
374 0 Treex::PML::Document->determine_node_type($_) for ($query_tree, $query_tree->descendants);
375 0 my $query_nodes=$self->{query_nodes};
376 0 $self->{query_node_order} = { map { $query_nodes->[$_] => $_ } 0..$#$query_nodes };
377 0 my $roots = PMLTQ::Planner::plan($query_nodes,$query_tree);
378 0 for my $root (@$roots) {
379 0 for my $subquery (grep { $_->{'#name'} eq 'subtree' } $root->descendants) {
380 0 my $subquery_roots = PMLTQ::Planner::plan(
381 [PMLTQ::Common::FilterQueryNodes($subquery)],
382 $subquery->parent,
383 $subquery
384 );
385 }
386 }
387 0 $self->{query_nodes} = [PMLTQ::Common::FilterQueryNodes($query_tree)]; # reordered
388 }
389  
390 0 $self->{sql}=undef;
391 0 $self->{join_id}=0;
392 my $sql = $self->serialize_conditions($query_tree,
393 { %$opts,
394 #no_filters => $opts->{no_filters},
395 #node_limit=>$opts->{node_limit},
396 #row_limit=>$opts->{row_limit},
397 #select_first=>$opts->{select_first},
398 returns_nodes=>\$self->{returns_nodes},
399 0 });
400 $self->prepare_sql($sql,
401 {
402 use_cursor => $opts->{use_cursor},
403 limit => ($self->{returns_nodes} ? abs($opts->{node_limit}||0)||undef : abs($opts->{row_limit}||0)||undef),
404 timeout => $opts->{timeout},
405 no_distinct => $opts->{no_distinct},
406 },
407 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'returns_nodes'} ? : 0 0 0
Condition0%0/8
abs($opts->{"node_limit"} || 0) or undef
l!l
00
$opts->{'node_limit'} || 0
l!l
00
abs($opts->{"row_limit"} || 0) or undef
l!l
00
$opts->{'row_limit'} || 0
l!l
00
MC/DC0%0/1
abs($opts->{"node_limit"} || 0) or undef
$opts->{'node_limit'}
MC/DC0%0/1
abs($opts->{"row_limit"} || 0) or undef
$opts->{'row_limit'}
Truth table0%0/2
A
A= $opts->{'node_limit'}
Aresult
11
00
Truth table0%0/2
A
A= $opts->{'row_limit'}
Aresult
11
00
408 0 return $query_tree;
409 }
410  
411 sub type_mapper {
412 0 ▶ my ($self)=@_;
Subroutine type_mapper: not called CC=1 SCAR=6.9
Pod undocumented
413 0 return $self;
414 }
415  
416 sub get_type_of_node {
417 0 ▶ my ($self,$name)=@_;
Subroutine get_type_of_node: not called CC=2 SCAR=17.9
Pod undocumented
418 0 my $n = $self->{name2node}{$name};
419 0 ▶ return $n && ( PMLTQ::Common::GetQueryNodeType($n,$self) );
Condition0%0/3
$n && PMLTQ::Common::GetQueryNodeType($n, $self)
!ll&&!rl&&r
000
MC/DC0%0/2
$n && PMLTQ::Common::GetQueryNodeType($n, $self)
$n PMLTQ::Common::GetQueryNodeType($n, $self)
Truth table0%0/3
A && B
A= $nB= PMLTQ::Common::GetQueryNodeType($n, $self)
ABresult
0X0
100
111
420 }
421  
422 sub get_type_decl_for_node {
423 0 ▶ my ($self,$name)=@_;
Subroutine get_type_decl_for_node: not called CC=3 SCAR=24.8
Pod undocumented
424 0 my $n = $self->{name2node}{$name};
425 0 ▶ my $node_type = $n && ( PMLTQ::Common::GetQueryNodeType($n,$self) );
Condition0%0/3
$n && PMLTQ::Common::GetQueryNodeType($n, $self)
!ll&&!rl&&r
000
MC/DC0%0/2
$n && PMLTQ::Common::GetQueryNodeType($n, $self)
$n PMLTQ::Common::GetQueryNodeType($n, $self)
Truth table0%0/3
A && B
A= $nB= PMLTQ::Common::GetQueryNodeType($n, $self)
ABresult
0X0
100
111
426 0 ▶ return $node_type && $self->get_decl_for($node_type);
Condition0%0/3
$node_type && $self->get_decl_for($node_type)
!ll&&!rl&&r
000
MC/DC0%0/2
$node_type && $self->get_decl_for($node_type)
$node_type $self->get_decl_for($node_type)
Truth table0%0/3
A && B
A= $node_typeB= $self->get_decl_for($node_type)
ABresult
0X0
100
111
427 }
428  
429 sub connect {
430 0 ▶ my ($self)=@_;
Subroutine connect: not called CC=8 SCAR=42.8
Pod undocumented
431 0 ▶ return $self->{dbi} if $self->{dbi};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbi"} 0 0 0
432 0 my $cfg = $self->{connect};
433 0 require DBI;
434 # this is taken from http://search.cpan.org/~lbaxter/Sys-SigAction/dbd-oracle-timeout.POD
435 0 eval {
436 #note that if you ask for safe, it will not work...
437 my $h = Sys::SigAction::set_sig_handler( 'ALRM',
438 sub {
439 0 ▶ die "timed out connecting to database on $cfg->{host}\n";
Subroutine __ANON__: not called CC=1 SCAR=6.9
440 },
441 0 { flags=>0 ,safe=>0 } );
442 0 alarm(20);
443 0 ▶ $self->{layout_version} = $cfg->{layout_version}||0;
Condition0%0/2
$cfg->{'layout_version'} || 0
l!l
00
MC/DC0%0/1
$cfg->{'layout_version'} || 0
$cfg->{'layout_version'}
Truth table0%0/2
A
A= $cfg->{'layout_version'}
Aresult
11
00
444  
445 0 require DBD::Pg;
446 0 import DBD::Pg qw(:async);
447  
448 my $string = 'dbi:Pg:'
449 .($cfg->{host} ? 'host='.$cfg->{host}.';' : '' )
450 .($cfg->{database} ? "database=".$cfg->{database}.';' : '')
451 0 ▶ .($cfg->{port} ? "port=".$cfg->{port} : '');
Branch: 3 branches
BranchTrueFalseTotal
$cfg->{'host'} ? : 0 0 0
$cfg->{'database'} ? : 0 0 0
$cfg->{'port'} ? : 0 0 0
452 $self->{dbi} = DBI->connect($string,
453 $cfg->{username},
454 $cfg->{password},
455 0 { RaiseError => 1,
456 AutoCommit=>0,
457 ReadOnly => 1
458 }
459 );
460 0 alarm(0);
461 0 ▶ die "Connection failed" if not $self->{dbi};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dbi"} 0 0 0
462 };
463 0 alarm(0);
464 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
465 0 print STDERR "$@";
466 0 undef $self->{dbi};
467 0 die "Unable to connect to the database.";
468 }
469 0 return $self->{dbi};
470 }
471  
472 sub run {
473 0 ▶ my ($self,$opts)=@_;
Subroutine run: not called CC=13 SCAR=52.0
Pod undocumented
474 0 delete $self->{results};
475 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
476 my $dbi = $self->{dbi} ||
477 0 ▶ $self->connect ||
Condition0%0/5
$self->{'dbi'} || $self->connect || die("Not connected to DBI!\n")
l!l
00
$self->{"dbi"} or $self->connect
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'dbi'} || $self->connect || die("Not connected to DBI!\n")
$self->{"dbi"} $self->connect
Truth table0%0/3
A or B
A= $self->{"dbi"}B= $self->connect
ABresult
1X1
011
000
478 die("Not connected to DBI!\n");
479 0 my $timeout = $opts->{timeout};
480 0 my $t0 = new Benchmark;
481 # my $limit = abs(int( $self->{returns_nodes} ? $opts->{node_limit} : $opts->{row_limit} ));
482 0 my $results = eval {
483 0 ▶ if ($opts->{use_cursor}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'use_cursor'}) { } 0 0 0
484 0 my $buffer = $self->cursor_next(1); # just pre-fill the buffer
485 0 ▶ $opts->{return_sth} ? $self->{sth} : $buffer;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'return_sth'} ? : 0 0 0
486 } else {
487 $self->run_sql_query($self->{sth},{
488 # ($limit ? (limit=> $limit) : ()),
489 timeout => $timeout,
490 timeout_callback => $opts->{timeout_callback},
491 RaiseError => 1,
492 return_sth => $opts->{return_sth},
493 use_cursor => $opts->{use_cursor},
494 })
495 0 }
496 };
497 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
498 0 my $err = $@;
499 0 $err=~s/\n/ /g;
500 0 ▶ if ($err =~ /^TIMEOUT /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err =~ /^TIMEOUT /) { } 0 0 0
501 0 die "$self->{id}\tTIMEOUT\t".($timeout)."s\n";
502 } else {
503 0 die "$self->{id}\tFAIL\t$err\n";
504 }
505 0 return;
506 }
507 0 my $t1 = new Benchmark;
508 0 my $time = timestr(timediff($t1,$t0));
509 0 ▶ unless ($opts->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"quiet"}) 0 0 0
510 my $no_results =
511 $opts->{return_sth} ? '?'
512 0 ▶ : $opts->{count} ? $results->[0][0]
Branch: 2 branches
BranchTrueFalseTotal
$opts->{'return_sth'} ? : 0 0 0
$opts->{'count'} ? : 0 0 0
513 : scalar(@$results);
514 0 ▶ print STDERR "$self->{id}\tOK\tPg\t$no_results\t$time\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
515 }
516 0 ▶ if ($opts->{return_sth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'return_sth'}) { } 0 0 0
517 0 return $results;
518 } else {
519 0 return $self->{results}=$results;
520 }
521 }
522  
523 sub find_special_attribute {
524 0 ▶ my ($self,$decl,$role)=@_;
Subroutine find_special_attribute: not called CC=4 SCAR=30.0
Pod undocumented
525 0 ▶ if ($decl->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_decl_type == 13) 0 0 0
526 0 $decl = $decl->get_content_decl;
527 }
528 0 ▶ my ($m)=$decl->can('find_members_by_role') && $decl->find_members_by_role($role);
Condition0%0/3
$decl->can('find_members_by_role') && $decl->find_members_by_role($role)
!ll&&!rl&&r
000
MC/DC0%0/2
$decl->can('find_members_by_role') && $decl->find_members_by_role($role)
$decl->can('find_members_by_role') $decl->find_members_by_role($role)
Truth table0%0/3
A && B
A= $decl->can('find_members_by_role')B= $decl->find_members_by_role($role)
ABresult
0X0
100
111
529 0 ▶ return $m && $m->get_name;
Condition0%0/3
$m && $m->get_name
!ll&&!rl&&r
000
MC/DC0%0/2
$m && $m->get_name
$m $m->get_name
Truth table0%0/3
A && B
A= $mB= $m->get_name
ABresult
0X0
100
111
530 }
531  
532 sub idx_to_pos {
533 0 ▶ my ($self,$idx_list,$force_id)=@_;
Subroutine idx_to_pos: not called CC=9 SCAR=45.0
Pod undocumented
534 0 my @res;
535 my %id_attr;
536 0 my $layout = $self->{layout_version};
537 0 for my $ident (@$idx_list) {
538 0 my ($idx,$type)=split '/',$ident,2;
539 0 $idx=int($idx);
540 0 my $node_id;
541 0 ▶ if ($type=~s{[+@](.*)$}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ s/[+\@](.*)$//) 0 0 0
542 0 $node_id = $1;
543 }
544 0 my $basename = $self->get_schema_name_for($type);
545 0 my $node_tab = $self->get_node_table_for($type);
546 0 my $id_attrs='';
547 0 ▶ if ($layout>1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($layout > 1) 0 0 0
548 0 ▶ unless (exists($id_attr{$type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $id_attr{$type}) 0 0 0
549 0 my $decl = $self->get_decl_for($type);
550 0 $id_attr{$type} = $self->find_special_attribute($decl,'#ID');
551 }
552 0 ▶ $id_attrs=$id_attr{$type} ? qq{, "n"."$id_attr{$type}", "f"."top"} : q{, null, "f"."top"};
Branch: 1 branch
BranchTrueFalseTotal
$id_attr{$type} ? : 0 0 0
553 }
554 0 my $sql=<<"EOF". "LIMIT 1;";
555 SELECT "f"."file", "f"."tree_no", "n"."#idx"-"n"."#root_idx" $id_attrs
556 FROM "${node_tab}" "n" JOIN "${basename}__#files" "f" ON "n"."#root_idx"="f"."#idx"
557 WHERE "n"."#idx" = ${idx}
558 EOF
559 # print STDERR "$sql\n";
560 0 my $result = $self->run_sql_query($sql,{ MaxRows=>1, RaiseError=>1 });
561 0 $result = $result->[0];
562 0 my ($fn,$tn,$nn,$id,$is_top) = @$result;
563 0 ▶ if (defined($id) and (!$is_top || $force_id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and !$is_top || $force_id) { } 0 0 0
Condition0%0/6
defined $id and !$is_top || $force_id
!ll&&!rl&&r
000
not $is_top or $force_id
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $id and !$is_top || $force_id
defined $id not $is_top $force_id
Truth table0%0/4
A and not(B) or C
A= defined $idB= not $is_topC= $force_id
ABCresult
0XX0
1000
11X1
1011
564 0 push @res, $fn.'#'.$id;
565 } else {
566 0 push @res, $fn.'##'.($tn+1).'.'.$nn;
567 }
568 }
569 0 return @res;
570 }
571  
572 sub ids_to_pos {
573 0 ▶ my ($self, $ids,$id_suffix)=@_;
Subroutine ids_to_pos: not called CC=9 SCAR=45.0
Pod undocumented
574 0 my $resolved = 0;
575 0 my @sql;
576 my $top_col;
577 0 ▶ if ($self->{layout_version}>1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'layout_version'} > 1) { } 0 0 0
578 0 $top_col = q{, "f"."top"};
579 } else {
580 0 $top_col = q{, 1};
581 }
582 0 foreach my $node_type (@{$self->get_node_types}) {
583 0 my $decl = $self->get_decl_for($node_type);
584 0 my $id_attr = $self->find_special_attribute($decl,'#ID');
585 0 ▶ next unless $id_attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $id_attr 0 0 0
586 0 my $node_tab = $self->get_node_table_for($node_type);
587 0 my $basename = $self->get_schema_name_for($node_type);
588 my $id_tests = join(' OR ',map {
589 0 my $id = $_;
590 0 $id=~s{'}{}g; $id=~s{\\}{}g; # these characters are NOT allowed
591 0 qq{"n"."$id_attr" = '$id'}
592 } @$ids);
593 0 my $sql;
594 0 $sql=<<"EOF";
595 SELECT "f"."file", "f"."tree_no", "n"."#idx"-"n"."#root_idx", "n"."$id_attr"$top_col
596 FROM "${node_tab}" "n" JOIN "${basename}__#files" "f" ON "n"."#root_idx"="f"."#idx"
597 WHERE $id_tests
598 EOF
599 0 push @sql,$sql;
600 }
601 0 my $sql = join(" UNION\n",@sql);
602 # print STDERR "$sql\n";
603 0 my $rows = $self->run_sql_query($sql,{ MaxRows=>scalar(@$ids), RaiseError=>1 });
604 my %result = map {
605 0 $_->[3] => $_,
606 } @$rows;
607 0 my @res;
608 0 for my $id (@$ids) {
609 0 my $row = $result{$id};
610 0 ▶ if ($row) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row) { } 0 0 0
611 0 my ($fn,$tn,$nn,undef,$is_top) = @$row;
612 0 ▶ if ($id_suffix or !(lc($is_top) eq 'true' or $is_top==1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id_suffix or not lc $is_top eq 'true' || $is_top == 1) { } 0 0 0
Condition0%0/6
$id_suffix or not lc $is_top eq "true" || $is_top == 1
l!l&&r!l&&!r
000
lc $is_top eq 'true' || $is_top == 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$id_suffix or not lc $is_top eq "true" || $is_top == 1
$id_suffix lc $is_top eq 'true' $is_top == 1
Truth table0%0/4
A or not(B || C)
A= $id_suffixB= lc $is_top eq 'true'C= $is_top == 1
ABCresult
1XX1
0001
01X0
0010
613 0 push @res, $fn.'#'.$id;
614 } else {
615 0 push @res, $fn.'##'.($tn+1).'.'.$nn;
616 }
617 } else {
618 0 push @res, undef;
619 }
620 }
621 0 return @res;
622 }
623  
624 # sub first_x_distinct_postgres {
625 # $dbi->do("DECLARE csr CURSOR FOR SELECT $select");
626 # my $total=0;
627 # my $count=0;
628 # my %seen;
629 # CUR: while (1) {
630 # my $sth = $dbi->prepare("FETCH $limit FROM CSR");
631 # $sth->execute;
632 # last if 0 == $sth->rows;
633 # while (my $row = $sth->fetchrow_arrayref) {
634 # $total++;
635 # my $key = join("\t",@$row);
636 # next if exists $seen{$key};
637 # $seen{$key}=undef;
638 # $count++;
639 # # print "$key\n";
640 # last CUR if $count>=$limit;
641 # }
642 # }
643 # $dbi->do("CLOSE csr");
644 # print "counted ",$count," distinct rows, fetched $total\n";
645 # }
646  
647 sub close_cursor {
648 0 ▶ my ($self)=@_;
Subroutine close_cursor: not called CC=4 SCAR=30.0
Pod undocumented
649 0 ▶ my $dbi = $self->{dbi} || die "Not connected to DBI!\n";
Condition0%0/2
$self->{'dbi'} || die("Not connected to DBI!\n")
l!l
00
MC/DC0%0/1
$self->{'dbi'} || die("Not connected to DBI!\n")
$self->{'dbi'}
Truth table0%0/2
A
A= $self->{'dbi'}
Aresult
11
00
650 0 my $cursor = delete $self->{cursor};
651 0 ▶ return unless $cursor;
Branch: 1 branch
BranchTrueFalseTotal
unless $cursor 0 0 0
652 0 my $close = delete $cursor->{close};
653 0 ▶ $close->($self) if $close;
Branch: 1 branch
BranchTrueFalseTotal
if $close 0 0 0
654 0 delete $cursor->{distinct};
655 0 return $cursor;
656 }
657 sub cursor_sth {
658 0 ▶ my ($self)=@_;
Subroutine cursor_sth: not called CC=2 SCAR=17.9
Pod undocumented
659 0 ▶ return $self->{cursor} ? $self->{cursor}{sth} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'cursor'} ? : 0 0 0
660 }
661 sub cursor_next {
662 0 ▶ my ($self,$keep)=@_;
Subroutine cursor_next: not called CC=27 SCAR=65.4
Pod undocumented
663  
664 # print STDERR "cursor_next\n";
665 0 my $cursor = $self->{cursor};
666 0 my $csr = $cursor->{name};
667 0 ▶ my $buffer = $cursor->{buffer}||=[];
Condition0%0/2
$cursor->{"buffer"} ||= []
l!l
00
MC/DC0%0/1
$cursor->{"buffer"} ||= []
$cursor->{"buffer"}
Truth table0%0/2
A
A= $cursor->{"buffer"}
Aresult
11
00
668 0 my $sth = $cursor->{sth};
669 0 my $distinct = $cursor->{distinct};
670 0 ▶ if (!@$buffer and (!defined($cursor->{limit}) or $cursor->{limit}>0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @$buffer and !defined($cursor->{"limit"}) || $cursor->{"limit"} > 0) 0 0 0
Condition0%0/6
not @$buffer and !defined($cursor->{"limit"}) || $cursor->{"limit"} > 0
!ll&&!rl&&r
000
not defined $cursor->{"limit"} or $cursor->{"limit"} > 0
l!l&&r!l&&!r
000
MC/DC0%0/3
not @$buffer and !defined($cursor->{"limit"}) || $cursor->{"limit"} > 0
not @$buffer not defined $cursor->{"limit"} $cursor->{"limit"} > 0
Truth table0%0/4
not(A) and not(B) or C
A= not @$bufferB= not defined $cursor->{"limit"}C= $cursor->{"limit"} > 0
ABCresult
0XX0
1000
11X1
1011
671 0 $cursor->{buffer}=[];
672 0 my $size = $cursor->{buffer_size};
673 # print STDERR "refilling buffer: $size\n";
674 0 while (1) {
675 0 ▶ if ($csr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($csr) { } 0 0 0
676 0 ▶ if (defined($cursor->{limit}) and $cursor->{limit}<$size) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cursor->{"limit"} and $cursor->{"limit"} < $size) 0 0 0
Condition0%0/3
defined $cursor->{"limit"} and $cursor->{"limit"} < $size
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cursor->{"limit"} and $cursor->{"limit"} < $size
defined $cursor->{"limit"} $cursor->{"limit"} < $size
Truth table0%0/3
A and B
A= defined $cursor->{"limit"}B= $cursor->{"limit"} < $size
ABresult
0X0
100
111
677 0 $size = $cursor->{buffer_size} = $cursor->{limit};
678 0 ▶ if ($distinct) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distinct) 0 0 0
679 0 ▶ my $ratio = $cursor->{ratio} ? ($cursor->{ratio}[0]/$cursor->{ratio}[1]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$cursor->{'ratio'} ? : 0 0 0
680 0 ▶ $size=$ratio ? int($size/$ratio)+1 : $size;
Branch: 1 branch
BranchTrueFalseTotal
$ratio ? : 0 0 0
681 }
682 0 $sth = $cursor->{sth} = $self->{dbi}->prepare(qq{FETCH $size FROM "$csr"},{ pg_async => 1 });
683 # print STDERR "New sth for $size: $sth\n";
684 }
685 0 my $opts = { timeout => $cursor->{timeout}, update_timeout=>1 };
686 0 $buffer = $self->run_sql_query($sth,$opts);
687 0 $cursor->{timeout} = $opts->{timeout};
688 } else {
689 0 ▶ if (defined($cursor->{limit}) and $cursor->{limit}<$size) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cursor->{"limit"} and $cursor->{"limit"} < $size) 0 0 0
Condition0%0/3
defined $cursor->{"limit"} and $cursor->{"limit"} < $size
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cursor->{"limit"} and $cursor->{"limit"} < $size
defined $cursor->{"limit"} $cursor->{"limit"} < $size
Truth table0%0/3
A and B
A= defined $cursor->{"limit"}B= $cursor->{"limit"} < $size
ABresult
0X0
100
111
690 0 $size = $cursor->{buffer_size} = $cursor->{limit};
691 }
692 0 $buffer = $sth->fetchall_arrayref(undef,$size);
693 }
694 0 ▶ if ($buffer and @$buffer and $distinct) {
Branch: 2 branches
BranchTrueFalseTotal
if ($buffer and @$buffer and $distinct) { } 0 0 0
elsif ($distinct) { } 0 0 0
Condition0%0/6
$buffer and @$buffer and $distinct
!ll&&!rl&&r
000
$buffer and @$buffer
!ll&&!rl&&r
000
MC/DC0%0/3
$buffer and @$buffer and $distinct
$buffer @$buffer $distinct
Truth table0%0/4
A and B and C
A= $bufferB= @$bufferC= $distinct
ABCresult
0XX0
10X0
1100
1111
695 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
696 0 foreach my $row (@$buffer) {
697 0 my $key = join("\x0",@$row);
698 0 ▶ unless (exists $distinct->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $distinct->{$key}) 0 0 0
699 0 push @{$cursor->{buffer}},$row;
700 0 $distinct->{$key}=undef;
701 }
702 }
703 0 $buffer = $cursor->{buffer};
704 0 ▶ $cursor->{ratio}||=[0,0];
Condition0%0/2
$cursor->{"ratio"} ||= [0, 0]
l!l
00
MC/DC0%0/1
$cursor->{"ratio"} ||= [0, 0]
$cursor->{"ratio"}
Truth table0%0/2
A
A= $cursor->{"ratio"}
Aresult
11
00
705 0 $cursor->{ratio}[0]+=scalar(@$buffer);
706 0 $cursor->{ratio}[1]+=$size;
707 0 ▶ next if !@$buffer;
Branch: 1 branch
BranchTrueFalseTotal
unless @$buffer 0 0 0
708 } elsif ($distinct) {
709 0 $cursor->{buffer} = $buffer;
710 } else {
711 # print STDERR "got ".scalar(@$buffer)." rows\n";
712 0 $cursor->{buffer} = $buffer;
713 }
714 0 last;
715 }
716 0 ▶ if (defined($cursor->{limit}) and $buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cursor->{"limit"} and $buffer) 0 0 0
Condition0%0/3
defined $cursor->{"limit"} and $buffer
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cursor->{"limit"} and $buffer
defined $cursor->{"limit"} $buffer
Truth table0%0/3
A and B
A= defined $cursor->{"limit"}B= $buffer
ABresult
0X0
100
111
717 0 ▶ splice(@$buffer,$cursor->{limit}) if (@$buffer>$cursor->{limit});
Branch: 1 branch
BranchTrueFalseTotal
if @$buffer > $cursor->{"limit"} 0 0 0
718 0 $cursor->{limit} -= scalar(@$buffer);
719 }
720 }
721 0 ▶ if ($buffer and @$buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer and @$buffer) { } 0 0 0
Condition0%0/3
$buffer and @$buffer
!ll&&!rl&&r
000
MC/DC0%0/2
$buffer and @$buffer
$buffer @$buffer
Truth table0%0/3
A and B
A= $bufferB= @$buffer
ABresult
0X0
100
111
722 0 ▶ return $keep ? $buffer : shift(@$buffer);
Branch: 1 branch
BranchTrueFalseTotal
$keep ? : 0 0 0
723 } else {
724 0 return;
725 }
726 }
727  
728 sub run_sql_query {
729 0 ▶ my ($self, $sql_or_sth, $opts)=@_;
Subroutine run_sql_query: not called CC=28 SCAR=67.0
Pod undocumented
730 # print STDERR "run_sql_query: $sql_or_sth\n" if ($self->{debug} and !ref($sql_or_sth));
731  
732 0 ▶ my $dbi = $self->{dbi} || die "Not connected to DBI!\n";
Condition0%0/2
$self->{'dbi'} || die("Not connected to DBI!\n")
l!l
00
MC/DC0%0/1
$self->{'dbi'} || die("Not connected to DBI!\n")
$self->{'dbi'}
Truth table0%0/2
A
A= $self->{'dbi'}
Aresult
11
00
733 0 local $dbi->{RaiseError} = $opts->{RaiseError};
734 0 ▶ local $dbi->{LongReadLen} = $opts->{LongReadLen} if exists($opts->{LongReadLen});
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"LongReadLen"} 0 0 0
735 0 require Time::HiRes;
736 0 my $canceled = 0;
737 0 ▶ if ($opts->{use_cursor}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"use_cursor"}) 0 0 0
738 # print STDERR "Use cursor\n";
739 0 ▶ $self->close_cursor if $self->{cursor};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cursor"} 0 0 0
740 0 my $cursor = $self->{cursor} = {};
741 0 ▶ my $size = $opts->{cursor_buffer_size} || 10_000;
Condition0%0/2
$opts->{'cursor_buffer_size'} || 10000
l!l
00
MC/DC0%0/1
$opts->{'cursor_buffer_size'} || 10000
$opts->{'cursor_buffer_size'}
Truth table0%0/2
A
A= $opts->{'cursor_buffer_size'}
Aresult
11
00
742 0 ▶ $cursor->{limit} = $opts->{limit} || $size;
Condition0%0/3
$opts->{'limit'} || $size
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{'limit'} || $size
$opts->{'limit'} $size
Truth table0%0/3
A || B
A= $opts->{'limit'}B= $size
ABresult
1X1
011
000
743 0 ▶ $size = $cursor->{limit} if $cursor->{limit} < $size;
Branch: 1 branch
BranchTrueFalseTotal
if $cursor->{"limit"} < $size 0 0 0
744 0 $cursor->{buffer_size} = $size;
745 0 ▶ $cursor->{distinct}={} if ($opts->{no_distinct} and $self->{returns_nodes});
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"no_distinct"} and $self->{"returns_nodes"} 0 0 0
Condition0%0/3
$opts->{"no_distinct"} and $self->{"returns_nodes"}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"no_distinct"} and $self->{"returns_nodes"}
$opts->{"no_distinct"} $self->{"returns_nodes"}
Truth table0%0/3
A and B
A= $opts->{"no_distinct"}B= $self->{"returns_nodes"}
ABresult
0X0
100
111
746 0 $cursor->{timeout} = $opts->{timeout};
747 0 my $csr = "pmltq_".$$;
748 0 $cursor->{name}=$csr;
749 0 eval {
750 0 $dbi->do(qq{DECLARE "$csr" CURSOR FOR }.$sql_or_sth);
751 };
752 0 my $err = $@;
753 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
754 0 $dbi->rollback();
755 0 die $err;
756 }
757  
758 $cursor->{close} = sub {
759 0 ▶ eval { $dbi->do(qq{CLOSE "$csr"}) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
760 0 ▶ $dbi->rollback() if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
761 0 };
762 0 ▶ if ($opts->{return_sth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'return_sth'}) { } 0 0 0
763 0 $cursor->{sth} = $dbi->prepare(qq{FETCH $size FROM "$csr"},{ pg_async => 1 });
764 0 ▶ if ($opts->{prepare_only}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"prepare_only"}) 0 0 0
765 0 $self->{sth} = $cursor->{sth};
766 }
767 # print STDERR "Created sth for $size: $cursor->{sth}\n";
768 0 return $cursor->{sth};
769 } else {
770 0 return;
771 }
772 }
773 0 ▶ my $sth = ref($sql_or_sth) ? $sql_or_sth : $dbi->prepare( $sql_or_sth,{ pg_async => 1 } );
Branch: 1 branch
BranchTrueFalseTotal
ref $sql_or_sth ? : 0 0 0
774 0 ▶ if ($opts->{use_cursor}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"use_cursor"}) 0 0 0
775 0 $self->{cursor}{sth}=$sth;
776 }
777 0 ▶ if ($opts->{prepare_only}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"prepare_only"}) 0 0 0
778 0 ▶ if ( $opts->{return_sth} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'return_sth'}) { } 0 0 0
779 0 return $self->{sth} = $sth;
780 } else {
781 0 return;
782 }
783 }
784  
785 0 my $step=0.05;
786 0 my $time=$opts->{timeout};
787 0 eval {
788 0 ▶ $sth->execute(ref($opts->{Bind}) ? @{$opts->{Bind}} : ());
Branch: 1 branch
BranchTrueFalseTotal
ref $opts->{'Bind'} ? : 0 0 0
789 0 ▶ if (defined $time) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time) 0 0 0
790 0 ▶ while (!$sth->pg_ready) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->pg_ready) 0 0 0
791 0 $time-=$step;
792 0 Time::HiRes::sleep($step);
793 0 ▶ if ($time<=0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time <= 0) 0 0 0
794 0 ▶ if ($opts->{'timeout_callback'} and $opts->{'timeout_callback'}->($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'timeout_callback'} and $opts->{'timeout_callback'}->($self)) { } 0 0 0
Condition0%0/3
$opts->{"timeout_callback"} and $opts->{"timeout_callback"}->($self)
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"timeout_callback"} and $opts->{"timeout_callback"}->($self)
$opts->{"timeout_callback"} $opts->{"timeout_callback"}->($self)
Truth table0%0/3
A and B
A= $opts->{"timeout_callback"}B= $opts->{"timeout_callback"}->($self)
ABresult
0X0
100
111
795 0 $time=$opts->{timeout};
796 } else {
797 0 $sth->pg_cancel();
798 0 ▶ $opts->{timeout} = 0 if $opts->{update_timeout};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"update_timeout"} 0 0 0
799 0 die "TIMEOUT\n"
800 }
801 }
802 }
803 }
804 0 $sth->pg_result;
805 };
806 0 my $err = $@;
807 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
808 0 $dbi->rollback();
809 0 die $err;
810 #} else {
811 #$dbi->commit();
812 }
813 0 ▶ $opts->{timeout} = $time if $opts->{update_timeout};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"update_timeout"} 0 0 0
814  
815 0 ▶ if ($opts->{return_sth}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'return_sth'}) { } 0 0 0
elsif ($opts->{'use_cursor'}) { } 0 0 0
816 0 return $sth;
817 } elsif ($opts->{use_cursor}) {
818 0 return;
819 } else {
820 0 return $sth->fetchall_arrayref(undef,$opts->{limit});
821 }
822 }
823  
824 # serialize to SQL (or SQL fragment)
825 sub serialize_conditions {
826 0 ▶ my ($self,$node,$opts)=@_;
Subroutine serialize_conditions: not called CC=4 SCAR=30.0
Pod undocumented
827 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
828 0 ▶ if ($node->parent or $opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->parent or $opts->{'output_filter'}) { } 0 0 0
Condition0%0/3
$node->parent or $opts->{"output_filter"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$node->parent or $opts->{"output_filter"}
$node->parent $opts->{"output_filter"}
Truth table0%0/3
A or B
A= $node->parentB= $opts->{"output_filter"}
ABresult
1X1
011
000
829 0 return [$self->serialize_element({
830 %$opts,
831 name => 'and',
832 condition => $node,
833 is_positive_conjunct => 1,
834 })];
835 } else {
836 return $self->build_sql($node,{
837 node_IDs=>$opts->{node_IDs},
838 returns_nodes=>$opts->{returns_nodes},
839 no_filters => $opts->{no_filters},
840 count=>$opts->{count},
841 node_limit => $opts->{node_limit},
842 row_limit => $opts->{row_limit},
843 select_first => $opts->{select_first},
844 no_distinct => $opts->{no_distinct},
845 0 });
846 }
847 }
848  
849 sub relation {
850 0 ▶ my ($self,$id,$rel,$target,$opts)=@_;
Subroutine relation: not called CC=48 SCAR=77.6
Pod undocumented
851 0 my $relation = $rel->name;
852 0 my $params = $rel->value;
853 0 ▶ if ($relation eq 'ancestor') {
Branch: 4 branches
BranchTrueFalseTotal
if ($relation eq 'ancestor') { } 0 0 0
elsif ($relation eq 'parent') { } 0 0 0
elsif ($relation eq 'order-follows') { } 0 0 0
elsif ($relation eq 'depth-first-follows') { } 0 0 0
854 0 $relation = 'descendant';
855 0 ($id,$target)=($target,$id);
856 } elsif ($relation eq 'parent') {
857 0 $relation = 'child';
858 0 ($id,$target)=($target,$id);
859 } elsif ($relation eq 'order-follows') {
860 0 $relation = 'order-precedes';
861 0 ($id,$target)=($target,$id);
862 } elsif ($relation eq 'depth-first-follows') {
863 0 $relation = 'depth-first-precedes';
864 0 ($id,$target)=($target,$id);
865 }
866 0 my $cond;
867 0 ▶ if ($relation eq 'user-defined') {
Branch: 9 branches
BranchTrueFalseTotal
if ($relation eq 'user-defined') { } 0 0 0
elsif ($relation eq 'descendant') { } 0 0 0
elsif ($relation eq 'sibling') { } 0 0 0
elsif ($relation eq 'child') { } 0 0 0
elsif ($relation eq 'depth-first-precedes') { } 0 0 0
elsif ($relation eq 'same-tree-as') { } 0 0 0
elsif ($relation eq 'same-document-as') { } 0 0 0
elsif ($relation eq 'order-precedes') { } 0 0 0
elsif ($relation eq 'member') { } 0 0 0
868 0 return $self->user_defined_relation($id,$params,$target,$opts);
869 } elsif ($relation eq 'descendant') {
870 0 $cond = qq{"$id"."#root_idx"="$target"."#root_idx" AND "$id"."#idx"!="$target"."#idx" AND }.
871 qq{"$target"."#idx" BETWEEN "$id"."#idx" AND "$id"."#r"};
872 0 ▶ my $min = $params->{min_length}||0;
Condition0%0/2
$params->{'min_length'} || 0
l!l
00
MC/DC0%0/1
$params->{'min_length'} || 0
$params->{'min_length'}
Truth table0%0/2
A
A= $params->{'min_length'}
Aresult
11
00
873 0 ▶ my $max = $params->{max_length}||0;
Condition0%0/2
$params->{'max_length'} || 0
l!l
00
MC/DC0%0/1
$params->{'max_length'} || 0
$params->{'max_length'}
Truth table0%0/2
A
A= $params->{'max_length'}
Aresult
11
00
874 0 ▶ if ($min>0 and $max>0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($min > 0 and $max > 0) { } 0 0 0
elsif ($min > 0) { } 0 0 0
elsif ($max > 0) { } 0 0 0
Condition0%0/3
$min > 0 and $max > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$min > 0 and $max > 0
$min > 0 $max > 0
Truth table0%0/3
A and B
A= $min > 0B= $max > 0
ABresult
0X0
100
111
875 0 $cond.=qq{ AND "$target"."#lvl"-"$id"."#lvl" BETWEEN $min AND $max};
876 } elsif ($min>0) {
877 0 $cond.=qq{ AND "$target"."#lvl"-"$id"."#lvl">=$min}
878 } elsif ($max>0) {
879 0 $cond.=qq{ AND "$target"."#lvl"-"$id"."#lvl"<=$max}
880 }
881 } elsif ($relation eq 'sibling') {
882 0 $cond = qq{"$id"."#parent_idx"="$target"."#parent_idx" AND "$id"."#idx"!="$target"."#idx"};
883 0 my $min = $params->{min_length};
884 0 my $max = $params->{max_length};
885 0 ▶ if ($min and $max) {
Branch: 3 branches
BranchTrueFalseTotal
if ($min and $max) { } 0 0 0
elsif ($min) { } 0 0 0
elsif ($max) { } 0 0 0
Condition0%0/3
$min and $max
!ll&&!rl&&r
000
MC/DC0%0/2
$min and $max
$min $max
Truth table0%0/3
A and B
A= $minB= $max
ABresult
0X0
100
111
886 0 $cond.=qq{ AND "$target"."#chord"-"$id"."#chord" BETWEEN $min AND $max};
887 } elsif ($min) {
888 0 $cond.=qq{ AND "$target"."#chord"-"$id"."#chord">=$min}
889 } elsif ($max) {
890 0 $cond.=qq{ AND "$target"."#chord"-"$id"."#chord"<=$max}
891 }
892 } elsif ($relation eq 'child') {
893 0 $cond = qq{"$id"."#idx"="$target"."#parent_idx"};
894 } elsif ($relation eq 'depth-first-precedes') {
895 0 $cond = qq{"$id"."#root_idx"="$target"."#root_idx"};
896 0 ▶ my $min = $params->{min_length}||0;
Condition0%0/2
$params->{'min_length'} || 0
l!l
00
MC/DC0%0/1
$params->{'min_length'} || 0
$params->{'min_length'}
Truth table0%0/2
A
A= $params->{'min_length'}
Aresult
11
00
897 0 ▶ my $max = $params->{max_length}||0;
Condition0%0/2
$params->{'max_length'} || 0
l!l
00
MC/DC0%0/1
$params->{'max_length'} || 0
$params->{'max_length'}
Truth table0%0/2
A
A= $params->{'max_length'}
Aresult
11
00
898 0 ▶ if ($min!=0 and $max!=0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($min != 0 and $max != 0) { } 0 0 0
elsif ($min != 0) { } 0 0 0
elsif ($max != 0) { } 0 0 0
Condition0%0/3
$min != 0 and $max != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$min != 0 and $max != 0
$min != 0 $max != 0
Truth table0%0/3
A and B
A= $min != 0B= $max != 0
ABresult
0X0
100
111
899 0 ▶ $cond.=qq{ AND "$target"."#idx"-"$id"."#idx" BETWEEN $min AND $max}.
Branch: 1 branch
BranchTrueFalseTotal
$min > 0 || $max < 0 ? : 0 0 0
Condition0%0/3
$min > 0 or $max < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$min > 0 or $max < 0
$min > 0 $max < 0
Truth table0%0/3
A or B
A= $min > 0B= $max < 0
ABresult
1X1
011
000
900 (($min>0 or $max<0) ? q{} : qq{ AND "$target"."#idx"!="$id"."#idx"})
901 } elsif ($min!=0) {
902 0 ▶ $cond.=qq{ AND "$target"."#idx"-"$id"."#idx">=$min}.($min>0 ? q{} : qq{ AND "$target"."#idx"!="$id"."#idx"});
Branch: 1 branch
BranchTrueFalseTotal
$min > 0 ? : 0 0 0
903 } elsif ($max!=0) {
904 0 ▶ $cond.=qq{ AND "$target"."#idx"-"$id"."#idx"<=$max}.($max<0 ? q{} : qq{ AND "$target"."#idx"!="$id"."#idx"});
Branch: 1 branch
BranchTrueFalseTotal
$max < 0 ? : 0 0 0
905 } else {
906 0 $cond.=qq{ AND "$target"."#idx">"$id"."#idx"}
907 }
908 } elsif ($relation eq 'same-tree-as') {
909 0 $cond = qq{"$id"."#root_idx"="$target"."#root_idx"};
910 } elsif ($relation eq 'same-document-as') {
911 $cond = $self->serialize_predicate(
912 {
913 id=>$opts->{id},
914 type=>$opts->{type},
915 join=>$opts->{join},
916 is_positive_conjunct=>$opts->{is_positive_conjunct},
917 expression => qq{file(\$$target)},
918 },
919 {
920 id=>$opts->{id},
921 type=>$opts->{type},
922 join=>$opts->{join},
923 is_positive_conjunct=>$opts->{is_positive_conjunct},
924 0 expression => qq{file(\$$id)},
925 },
926 '=',$opts # there should be no ambiguity here, treat expressoins as positive
927 );
928 } elsif ($relation eq 'order-precedes') {
929 0 my $flags = $self->get_schema_flags($self->get_schema_name_for($opts->{type}));
930 0 my ($S,$T);
931 0 ▶ if (defined($flags) and ($flags & MAX_MIN_ORD)>0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flags and ($flags & 4) > 0) { } 0 0 0
Condition0%0/3
defined $flags and ($flags & 4) > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $flags and ($flags & 4) > 0
defined $flags ($flags & 4) > 0
Truth table0%0/3
A and B
A= defined $flagsB= ($flags & 4) > 0
ABresult
0X0
100
111
932 0 $S = {
933 sql => qq{"$id"."#max_ord"},
934 col_type => COL_NUMERIC,
935 };
936 0 $T = {
937 sql => qq{"$target"."#min_ord"},
938 col_type => COL_NUMERIC,
939 };
940 } else {
941 0 my $decl = $self->get_decl_for($opts->{type});
942 0 my $order = $self->find_special_attribute($decl,'#ORDER');
943 0 ▶ if ($order) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order) 0 0 0
944 $T = {
945 id=>$opts->{id},
946 type=>$opts->{type},
947 join=>$opts->{join},
948 is_positive_conjunct=>$opts->{is_positive_conjunct},
949 0 expression => qq{\$$target.$order},
950 };
951 $S = {
952 id=>$opts->{id},
953 type=>$opts->{type},
954 join=>$opts->{join},
955 is_positive_conjunct=>$opts->{is_positive_conjunct},
956 0 expression => qq{\$$id.$order},
957 };
958 }
959 }
960 0 ▶ if (not defined($S)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $S) 0 0 0
961 0 die "No ordering is defined on nodes of type '$opts->{type}'!\n";
962 }
963 my ($min,$max)=
964 0 ▶ map { (defined($_) and length($_)) ? $_ : undef }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && length $_ ? : 0 0 0
Condition0%0/3
defined $_ and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and length $_
defined $_ length $_
Truth table0%0/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
965 0 map { $params->{$_} }
966 qw(min_length max_length);
967 0 $cond =qq{"$id"."#root_idx"="$target"."#root_idx" AND };
968 0 ▶ if (defined($min) and defined($max)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $min and defined $max) { } 0 0 0
elsif (defined $min) { } 0 0 0
elsif (defined $max) { } 0 0 0
Condition0%0/3
defined $min and defined $max
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and defined $max
defined $min defined $max
Truth table0%0/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
969 0 ▶ $cond.=$self->serialize_predicate( $T,$S, qq{<$min,$max>},$opts)
Branch: 1 branch
BranchTrueFalseTotal
$min > 0 || $max < 0 ? : 0 0 0
Condition0%0/3
$min > 0 or $max < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$min > 0 or $max < 0
$min > 0 $max < 0
Truth table0%0/3
A or B
A= $min > 0B= $max < 0
ABresult
1X1
011
000
970 .(($min>0 or $max<0) ? q{} : qq{ AND "$target"."#idx"!="$id"."#idx"});
971 } elsif (defined($min)) {
972 0 ▶ $cond.=$self->serialize_predicate( $T,$S, qq{<$min,>},$opts)
Branch: 1 branch
BranchTrueFalseTotal
$min > 0 ? : 0 0 0
973 .($min>0 ? q{} : qq{ AND "$target"."#idx"!="$id"."#idx"});
974 } elsif (defined($max)) {
975 0 ▶ $cond.=$self->serialize_predicate( $T,$S, qq{<,$max>},$opts)
Branch: 1 branch
BranchTrueFalseTotal
$max < 0 ? : 0 0 0
976 .($max<0 ? q{} : qq{ AND "$target"."#idx"!="$id"."#idx"});
977 } else {
978 0 $cond.=$self->serialize_predicate( $T,$S, '>',$opts); # there should be no ambiguity here, treat expressions as positive
979 }
980 # print STDERR $cond,"\n";
981 } elsif ($relation eq 'member') {
982 # take parent's type,
983 # use this type as a
984 # use \$$target.#idx as b
985 0 my $path = $self->{name2node}{$target}{'node-type'};
986 $cond =
987 $self->serialize_predicate(
988 {
989 id=>$opts->{id},
990 type=>$opts->{type},
991 join=>$opts->{join},
992 is_positive_conjunct=>$opts->{is_positive_conjunct},
993 0 expression => qq{\$$id.$path},
994 allow_non_atomic => 1,
995 },
996 qq{"$target"."#idx"},
997 q(=),$opts,
998 );
999 } else {
1000 0 die "Unsupported relation: $relation between nodes $id and $target\n";
1001 }
1002 0 return $cond;
1003 }
1004  
1005 # Given min_length and max_length of a relation, determine
1006 # whether to treat the relation as transitive or not (faster).
1007 # If neither min or max is defined or if max==1, we treat the relation as non-transitive.
1008 sub _is_transitive {
1009 0 ▶ my ($min,$max)=@_;
Subroutine _is_transitive: not called CC=7 SCAR=40.3
1010 0 ▶ return ((!(defined($min) && length($min))
Branch: 1 branch
BranchTrueFalseTotal
!(defined $min && length $min || defined $max && length $max) || defined $max && $max == 1 ? : 0 0 0
Condition0%0/15
not defined $min && length $min || defined $max && length $max or defined $max and $max == 1
l!l&&r!l&&!r
000
defined $min && length $min || defined $max && length $max
l!l&&r!l&&!r
000
defined $min and length $min
!ll&&!rl&&r
000
defined $max and length $max
!ll&&!rl&&r
000
defined $max and $max == 1
!ll&&!rl&&r
000
MC/DC0%0/6
not defined $min && length $min || defined $max && length $max or defined $max and $max == 1
defined $min length $min defined $max length $max defined $max $max == 1
Truth table0%0/13
not(A and B || C and D) or E and F
A= defined $minB= length $minC= defined $maxD= length $maxE= defined $maxF= $max == 1
ABCDEFresult
0X0XXX1
0X10XX1
100XXX1
1010XX1
11XX111
0X11111
1011111
11XX0X0
11XX100
0X110X0
0X11100
10110X0
1011100
1011 && !(defined($max) && length($max))) || (defined($max) && $max==1)) ? 0 : 1;
1012  
1013 }
1014  
1015 sub user_defined_relation {
1016 0 ▶ my ($self,$id,$params,$target,$opts)=@_;
Subroutine user_defined_relation: not called CC=24 SCAR=64.0
Pod undocumented
1017 0 my $relation=$params->{label};
1018 0 my $type = $opts->{type};
1019 0 my $cond;
1020 0 my $from_id = $opts->{id}; # view point
1021  
1022 0 my $target_spec = $self->get_relation_target_type($type,$relation,1);
1023 0 ▶ if ($target_spec
Branch: 1 branch
BranchTrueFalseTotal
if ($target_spec and $target_spec->[0] == 1 and not $target_spec->[1][0]) 0 0 0
Condition0%0/6
$target_spec and $target_spec->[0] == 1 and not $target_spec->[1][0]
!ll&&!rl&&r
000
$target_spec and $target_spec->[0] == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$target_spec and $target_spec->[0] == 1 and not $target_spec->[1][0]
$target_spec $target_spec->[0] == 1 not $target_spec->[1][0]
Truth table0%0/4
A and B and not(C)
A= $target_specB= $target_spec->[0] == 1C= not $target_spec->[1][0]
ABCresult
0XX0
10X0
1100
1111
1024 and $target_spec->[0] == 1 # user defined
1025 and !$target_spec->[1][0]) { # revered
1026 0 ($id,$target)=($target,$id);
1027 0 $target_spec = $self->get_relation_target_type($type,$target_spec->[1][1],1);
1028 0 ▶ $relation = $target_spec->[1][1] if $target_spec;
Branch: 1 branch
BranchTrueFalseTotal
if $target_spec 0 0 0
1029 }
1030 0 ▶ unless ($target_spec) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target_spec) 0 0 0
1031 die "Relation '$relation' not defined for nodes of type '$type'. ".
1032 "\nPossible PMLREF relations: ".
1033 0 join(', ',@{$self->get_pmlrf_relations($type)}).
1034 "\nPossible user-defined relations: ".
1035 0 join(', ',@{$self->get_user_defined_relations($type)});
1036 }
1037  
1038 0 my $min = $params->{min_length};
1039 0 my $max = $params->{max_length};
1040 0 ▶ if (defined($min) && length($min) && defined($max) && length($min) && ($min>$max)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and length $min and defined $max and length $min and $min > $max) 0 0 0
Condition0%0/12
defined $min and length $min and defined $max and length $min and $min > $max
!ll&&!rl&&r
000
defined $min and length $min and defined $max and length $min
!ll&&!rl&&r
000
defined $min and length $min and defined $max
!ll&&!rl&&r
000
defined $min and length $min
!ll&&!rl&&r
000
MC/DC0%0/5
defined $min and length $min and defined $max and length $min and $min > $max
defined $min length $min defined $max length $min $min > $max
Truth table0%0/6
A and B and C and D and E
A= defined $minB= length $minC= defined $maxD= length $minE= $min > $max
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1041 0 die "Invalid bounds for transitive relation '$relation\{$min,$max}'\n";
1042 }
1043 0 ▶ if ((defined($min) && length($min) || defined($max) && length($min)) and $type ne $target_spec->[1][2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min && length $min || defined $max && length $min and $type ne $target_spec->[1][2]) 0 0 0
Condition0%0/12
defined $min && length $min || defined $max && length $min and $type ne $target_spec->[1][2]
!ll&&!rl&&r
000
defined $min and length $min or defined $max and length $min
l!l&&r!l&&!r
000
defined $min and length $min
!ll&&!rl&&r
000
defined $max and length $min
!ll&&!rl&&r
000
MC/DC0%0/5
defined $min && length $min || defined $max && length $min and $type ne $target_spec->[1][2]
defined $min length $min defined $max length $min $type ne $target_spec->[1][2]
Truth table0%0/10
A and B or C and D and E
A= defined $minB= length $minC= defined $maxD= length $minE= $type ne $target_spec->[1][2]
ABCDEresult
0X0XX0
0X10X0
100XX0
1010X0
11XX00
0X1100
101100
11XX11
0X1111
101111
1044 0 die "Cannot create transitive closure for relation with different start-node and end-node types: '$type' -> '$target_spec->[1][2]'\n";
1045 }
1046 0 my $transitive = _is_transitive($min,$max);
1047  
1048 0 ▶ if ($target_spec->[0]==0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_spec->[0] == 0) { } 0 0 0
1049 # specfic (i.e. PMLREF -based) relation
1050 0 my $path = $relation;
1051 # # fixup:
1052 # if ($relation =~ /^(coref_text|coref_gram|compl)$/) {
1053 # $relation .= '.rf';
1054 # }
1055 0 ▶ if ($path=~/\.rf$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /\.rf$/) 0 0 0
1056 0 my $decl = $self->get_decl_for($type);
1057 0 ▶ $decl = $decl && $decl->find($relation);
Condition0%0/3
$decl && $decl->find($relation)
!ll&&!rl&&r
000
MC/DC0%0/2
$decl && $decl->find($relation)
$decl $decl->find($relation)
Truth table0%0/3
A && B
A= $declB= $decl->find($relation)
ABresult
0X0
100
111
1058 0 ▶ if ($decl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl) 0 0 0
1059 0 ▶ if ($decl->get_decl_type == PML_CDATA_DECL and $decl->get_format eq 'PMLREF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_decl_type == 8 and $decl->get_format eq "PMLREF") 0 0 0
Condition0%0/3
$decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
!ll&&!rl&&r
000
MC/DC0%0/2
$decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
$decl->get_decl_type == 8 $decl->get_format eq "PMLREF"
Truth table0%0/3
A and B
A= $decl->get_decl_type == 8B= $decl->get_format eq "PMLREF"
ABresult
0X0
100
111
1060 0 $path=~s/\.rf$//;
1061 }
1062 }
1063 }
1064 # print STDERR qq{RELATION: \$$id.$path = "$target"."#idx" ($opts->{is_positive_conjunct})\n};
1065  
1066 0 ▶ if ($transitive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transitive) { } 0 0 0
1067 0 my $rec_table = $self->precompute_table({type=>$type,path=>$path,recursive=>1,max=>$max});
1068 0 $cond = $self->tabular_relation($opts,"#rec_".$rec_table->{name},$id,$target,$min,$max);
1069 } else {
1070 $cond =
1071 $self->serialize_predicate(
1072 {
1073 id=>$from_id,
1074 type=>$type,
1075 join=>$opts->{join},
1076 expression => qq{\$$id.$path},
1077 is_positive_conjunct=>$opts->{is_positive_conjunct},
1078 },
1079 0 qq{"$target"."#idx"},
1080 q(=),$opts,
1081 );
1082 }
1083 } else {
1084 # user-defined relation
1085 0 my $table = $target_spec->[1][0];
1086 0 ▶ if ($transitive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($transitive) { } 0 0 0
1087 0 my $rec_table = $self->precompute_table({type=>$type,table=>$table,recursive=>1,max=>$max});
1088 0 $table = "#rec_".$rec_table->{name};
1089 0 $cond = $self->tabular_relation($opts,$table,$id,$target,$min,$max);
1090 } else {
1091 0 $cond = $self->tabular_relation($opts,$table,$id,$target,undef,undef);
1092 }
1093 }
1094 0 return $cond;
1095 }
1096  
1097 sub precompute_table {
1098 0 ▶ my ($self,$spec)=@_;
Subroutine precompute_table: not called CC=10 SCAR=47.0
Pod undocumented
1099 0 ▶ my $precomputed = $self->{precompute_recursive_relation}||={};
Condition0%0/2
$self->{"precompute_recursive_relation"} ||= {}
l!l
00
MC/DC0%0/1
$self->{"precompute_recursive_relation"} ||= {}
$self->{"precompute_recursive_relation"}
Truth table0%0/2
A
A= $self->{"precompute_recursive_relation"}
Aresult
11
00
1100 0 my $rec_table;
1101 my $table;
1102 0 ▶ if ($spec->{table}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'table'}) { } 0 0 0
1103 $table = $spec->{table}
1104 0 } else {
1105 0 $table = $spec->{type}.'/'.$spec->{path};
1106 }
1107 0 ▶ if (exists($precomputed->{$table})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $precomputed->{$table}) { } 0 0 0
1108 0 $rec_table = $precomputed->{$table};
1109 # in future we may want to try precomputing non-recursive relations as well
1110 0 ▶ if ($spec->{recursive} and !$rec_table->{recursive}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($spec->{'recursive'} and not $rec_table->{'recursive'}) { } 0 0 0
elsif ($spec->{'recursive'}) { } 0 0 0
Condition0%0/3
$spec->{"recursive"} and not $rec_table->{"recursive"}
!ll&&!rl&&r
000
MC/DC0%0/2
$spec->{"recursive"} and not $rec_table->{"recursive"}
$spec->{"recursive"} not $rec_table->{"recursive"}
Truth table0%0/3
A and not(B)
A= $spec->{"recursive"}B= not $rec_table->{"recursive"}
ABresult
0X0
100
111
1111 0 $rec_table->{recursive}=1;
1112 $rec_table->{max}=$spec->{max}
1113 0 } elsif ($spec->{recursive}) {
1114 0 ▶ if (defined($spec->{max})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{'max'}) { } 0 0 0
1115 0 ▶ $rec_table->{max} = $spec->{max} if defined($rec_table->{max}) and $spec->{max}>$rec_table->{max};
Branch: 1 branch
BranchTrueFalseTotal
if defined $rec_table->{"max"} and $spec->{"max"} > $rec_table->{"max"} 0 0 0
Condition0%0/3
defined $rec_table->{"max"} and $spec->{"max"} > $rec_table->{"max"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rec_table->{"max"} and $spec->{"max"} > $rec_table->{"max"}
defined $rec_table->{"max"} $spec->{"max"} > $rec_table->{"max"}
Truth table0%0/3
A and B
A= defined $rec_table->{"max"}B= $spec->{"max"} > $rec_table->{"max"}
ABresult
0X0
100
111
1116 } else {
1117 0 $rec_table->{max}=undef; # unbounded
1118 }
1119 }
1120 } else {
1121 0 $rec_table = $spec;
1122 0 $rec_table->{name}=scalar(keys(%$precomputed));
1123 0 $precomputed->{$table} = $rec_table;
1124 }
1125 0 return $rec_table;
1126 }
1127  
1128 sub tabular_relation {
1129 0 ▶ my ($self,$opts,$table,$id,$target,$min,$max)=@_;
Subroutine tabular_relation: not called CC=11 SCAR=48.8
Pod undocumented
1130 0 my $join=$opts->{join};
1131 0 my $depth='';
1132 0 ▶ if (defined($min) and defined($max)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $min and defined $max) { } 0 0 0
elsif (defined $min) { } 0 0 0
elsif (defined $max) { } 0 0 0
Condition0%0/3
defined $min and defined $max
!ll&&!rl&&r
000
MC/DC0%0/2
defined $min and defined $max
defined $min defined $max
Truth table0%0/3
A and B
A= defined $minB= defined $max
ABresult
0X0
100
111
1133 0 $depth = " AND %s.depth BETWEEN $min AND $max"
1134 } elsif (defined($min)) {
1135 0 $depth = " AND %s.depth >= $min"
1136 } elsif (defined($max)) {
1137 0 $depth = " AND %s.depth <= $max"
1138 }
1139 0 ▶ if ($opts->{is_positive_conjunct}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'is_positive_conjunct'}) { } 0 0 0
1140 0 my $join_to;
1141 0 ▶ if ($opts->{subquery}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'subquery'}) { } 0 0 0
1142 0 ▶ $join_to = $opts->{id} eq $id ? $id : $target;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'id'} eq $id ? : 0 0 0
1143 } else {
1144 0 ▶ $join_to = $opts->{id} eq $id ? $target : $id;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'id'} eq $id ? : 0 0 0
1145 }
1146 0 ▶ my $J = ($join->{$join_to}||=[]);
Condition0%0/2
$join->{$join_to} ||= []
l!l
00
MC/DC0%0/1
$join->{$join_to} ||= []
$join->{$join_to}
Truth table0%0/2
A
A= $join->{$join_to}
Aresult
11
00
1147 0 my $i = @$J;
1148 0 my $eid=$join_to."/U-$i";
1149 0 $depth=sprintf($depth,qq{"$eid"});
1150 0 ▶ if ($join_to eq $target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($join_to eq $target) { } 0 0 0
1151 0 push @$J,[$eid,$table, qq{"$eid"."#value"="$target"."#idx"}.$depth];
1152 0 return qq("$eid"."#idx" = "$id"."#idx");
1153 } else {
1154 0 push @$J,[$eid,$table, qq("$eid"."#idx" = "$id"."#idx").$depth];
1155 0 return qq{"$eid"."#value"="$target"."#idx"};
1156 }
1157 } else {
1158 0 $depth=sprintf($depth,'x');
1159 0 return qq{ EXISTS (SELECT 1 FROM "$table" x WHERE x."#idx" = "$id"."#idx" AND x."#value"="$target"."#idx"${depth}) };
1160 }
1161 }
1162  
1163 sub get_tabspec {
1164 0 ▶ my ($self, $id, $node_type, $n)=@_;
Subroutine get_tabspec: not called CC=2 SCAR=17.9
Pod undocumented
1165 0 my $tabspec;
1166 0 ▶ if (PMLTQ::Common::IsMemberNode($n,$self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PMLTQ::Common::IsMemberNode($n, $self)) { } 0 0 0
1167 0 my $query_type = PMLTQ::Common::DeclPathToQueryType($self->get_decl_for($node_type)->get_decl_path);
1168 0 $tabspec = [
1169 $self->get_real_table_name( $query_type ),
1170 $id,
1171 $n
1172 ];
1173 } else {
1174 0 $tabspec = [$self->get_node_table_for($node_type),$id,$n];
1175 }
1176 0 return $tabspec;
1177 }
1178  
1179 sub build_sql {
1180 0 ▶ my ($self,$tree,$opts)=@_;
Subroutine build_sql: not called CC=91 SCAR=90.3
Pod undocumented
1181 0 ▶ $opts||={};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1182 0 my ($format,$count,$tree_parent_id) = map {$opts->{$_}} qw(format count parent_id);
1183 0 ▶ $count||=0;
Condition0%0/2
$count ||= 0
l!l
00
MC/DC0%0/1
$count ||= 0
$count
Truth table0%0/2
A
A= $count
Aresult
11
00
1184 # we rely on depth first order!
1185 0 my @nodes = PMLTQ::Common::FilterQueryNodes($tree);
1186 0 my @select;
1187 my @table;
1188 0 my @where;
1189 0 my %conditions;
1190 0 ▶ my $extra_joins = $opts->{join} || {};
Condition0%0/2
$opts->{'join'} || {}
l!l
00
MC/DC0%0/1
$opts->{'join'} || {}
$opts->{'join'}
Truth table0%0/2
A
A= $opts->{'join'}
Aresult
11
00
1191 0 ▶ local $self->{precompute_recursive_relation} unless $tree->parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $tree->parent 0 0 0
1192 # my $default_type = $opts->{type}||$tree->root->{'node-type'}||'UNKNOWN';
1193 0 ▶ for (my $i=0; $i<@nodes; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @nodes) 0 0 0
1194 0 my $n = $nodes[$i];
1195 0 my $node_type = PMLTQ::Common::GetQueryNodeType($n,$self);
1196 0 my $id = $self->{id_map}{$n};
1197  
1198 0 push @select, $id;
1199 0 my $parent = $n->parent;
1200 0 ▶ while ($parent and ($parent->{'#name'}||'') !~/^(?:node|subquery)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and not +($parent->{"#name"} || "") =~ /^(?:node|subquery)$/) 0 0 0
Condition0%0/5
$parent and not +($parent->{"#name"} || "") =~ /^(?:node|subquery)$/
!ll&&!rl&&r
000
$parent->{'#name'} || ''
l!l
00
MC/DC0%0/2
$parent and not +($parent->{"#name"} || "") =~ /^(?:node|subquery)$/
$parent $parent->{'#name'}
Truth table0%0/3
A and not(B)
A= $parentB= $parent->{'#name'}
ABresult
0X0
110
101
1201 0 $parent=$parent->parent;
1202 }
1203 0 ▶ my $parent_id = defined($parent) && $self->{id_map}{$parent};
Condition0%0/3
defined $parent && $self->{'id_map'}{$parent}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parent && $self->{'id_map'}{$parent}
defined $parent $self->{'id_map'}{$parent}
Truth table0%0/3
A && B
A= defined $parentB= $self->{'id_map'}{$parent}
ABresult
0X0
100
111
1204 0 $conditions{$id} = PMLTQ::Common::as_text($n);
1205 0 my @conditions;
1206 {
1207 0 my $tabspec = $self->get_tabspec($id,$node_type,$n);
1208 0 ▶ if ($parent && $parent->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and $parent->parent) { } 0 0 0
Condition0%0/3
$parent and $parent->parent
!ll&&!rl&&r
000
MC/DC0%0/2
$parent and $parent->parent
$parent $parent->parent
Truth table0%0/3
A and B
A= $parentB= $parent->parent
ABresult
0X0
100
111
1209 # print STDERR "EXTRA JOINS: $extra_joins\n";
1210 0 my $parent_type = PMLTQ::Common::GetQueryNodeType($parent,$self);
1211 0 my ($rel) = SeqV($n->{relation});
1212 0 ▶ $rel ||= PMLTQ::Common::SetRelation($n,'child');
Condition0%0/3
$rel ||= PMLTQ::Common::SetRelation($n, "child")
l!l&&r!l&&!r
000
MC/DC0%0/2
$rel ||= PMLTQ::Common::SetRelation($n, "child")
$rel PMLTQ::Common::SetRelation($n, "child")
Truth table0%0/3
A ||= B
A= $relB= PMLTQ::Common::SetRelation($n, "child")
ABresult
1X1
011
000
1213  
1214 my $relation = $self->relation($parent_id,$rel,$id, {
1215 %$opts,
1216 id=>$id,
1217 join => $extra_joins,
1218 0 ▶ subquery => ($n->{'#name'} eq 'subquery' ? 1 : 0),
Branch: 1 branch
BranchTrueFalseTotal
$n->{'#name'} eq 'subquery' ? : 0 0 0
1219 type=>PMLTQ::Common::GetQueryNodeType($parent,$self), # ($parent->{'node-type'}||$default_type),
1220 is_positive_conjunct=>1, #($n->{'#name'} eq 'subquery' ? 0 : 1),
1221 });
1222  
1223 0 ▶ if (($n->{optional} && $parent_type eq $node_type) or $n->{'#name'} eq 'subquery' or $rel->name eq 'same-document-as') {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{'optional'} and $parent_type eq $node_type or $n->{'#name'} eq 'subquery' or $rel->name eq 'same-document-as') { } 0 0 0
Condition0%0/9
$n->{"optional"} and $parent_type eq $node_type or $n->{"#name"} eq "subquery" or $rel->name eq "same-document-as"
l!l&&r!l&&!r
000
$n->{"optional"} and $parent_type eq $node_type or $n->{"#name"} eq "subquery"
l!l&&r!l&&!r
000
$n->{"optional"} and $parent_type eq $node_type
!ll&&!rl&&r
000
MC/DC0%0/4
$n->{"optional"} and $parent_type eq $node_type or $n->{"#name"} eq "subquery" or $rel->name eq "same-document-as"
$n->{"optional"} $parent_type eq $node_type $n->{"#name"} eq "subquery" $rel->name eq "same-document-as"
Truth table0%0/7
A and B or C or D
A= $n->{"optional"}B= $parent_type eq $node_typeC= $n->{"#name"} eq "subquery"D= $rel->name eq "same-document-as"
ABCDresult
11XX1
0X1X1
101X1
0X011
10011
0X000
10000
1224 0 push @table,$tabspec;
1225 0 push @conditions, [$relation, $n];
1226 } else {
1227 0 ▶ push @{$extra_joins->{ $parent_id }}, [ $tabspec->[1], $tabspec->[0], $relation, $n->{optional} ? 'LEFT' : '' ];
Branch: 1 branch
BranchTrueFalseTotal
$n->{'optional'} ? : 0 0 0
1228 }
1229 } else {
1230 0 push @table,$tabspec;
1231 }
1232 }
1233  
1234 0 ▶ unless ($n->{overlapping}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n->{"overlapping"}) 0 0 0
1235 # overlapping nodes, denoted as ' +relation type [ ... ] ' do not
1236 # have to be disjoint from other nodes matched by the query
1237 push @conditions,
1238 (map {
1239 [qq{"$self->{id_map}{$_}"."#idx"}.
1240 (
1241 (($_->parent == $n->parent) &&
1242 0 ▶ $conditions{$id} eq $conditions{$self->{id_map}{$_}}) ? '<' : '!=' ).
Branch: 1 branch
BranchTrueFalseTotal
$_->parent == $n->parent && $conditions{$id} eq $conditions{$self->{'id_map'}{$_}} ? : 0 0 0
Condition0%0/3
$_->parent == $n->parent and $conditions{$id} eq $conditions{$self->{"id_map"}{$_}}
!ll&&!rl&&r
000
MC/DC0%0/2
$_->parent == $n->parent and $conditions{$id} eq $conditions{$self->{"id_map"}{$_}}
$_->parent == $n->parent $conditions{$id} eq $conditions{$self->{"id_map"}{$_}}
Truth table0%0/3
A and B
A= $_->parent == $n->parentB= $conditions{$id} eq $conditions{$self->{"id_map"}{$_}}
ABresult
0X0
100
111
1243 qq{"${id}"."#idx"},$n] }
1244 grep { #$_->parent == $n->parent
1245 # or
1246 0 my $type=PMLTQ::Common::GetQueryNodeType($_,$self); # $_->{'node-type'}||$default_type;
1247 0 ▶ !$_->{overlapping} and ($type eq $node_type)
Branch: 1 branch
BranchTrueFalseTotal
not $_->{"overlapping"} and $type eq $node_type 0 0 0
1248 }
1249 0 map { $nodes[$_] } 0..($i-1));
1250 }
1251 {
1252 0 my $conditions = $self->serialize_conditions($n,{
1253 type=>$node_type,
1254 id=>$id,
1255 parent_id=>$parent_id,
1256 join => $extra_joins,
1257 });
1258 0 ▶ push @conditions, [$conditions,$n] if @$conditions;
Branch: 1 branch
BranchTrueFalseTotal
if @$conditions 0 0 0
1259 }
1260 # where could also be obtained by replacing ___SELF___ with $id
1261 0 ▶ if ($n->{optional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"optional"}) 0 0 0
1262 # identify with parent
1263 0 ▶ if (@conditions) {
Branch: 1 branch
BranchTrueFalseTotal
if (@conditions) 0 0 0
1264 0 @conditions = ( [ [['(('], @{PMLTQ::Common::_group(\@conditions,["\n AND "])}, [qq{) OR "$id"."#idx"="$parent_id"."#idx")}]], $n] );
1265 }
1266 }
1267 0 push @where, @conditions;
1268 }
1269  
1270 0 my @sql = (['SELECT ']);
1271 0 ▶ my @outputs = ($opts->{no_filters} || $tree->parent) ? () : PMLTQ::Common::merge_filters($tree->{'output-filters'});
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'no_filters'} || $tree->parent ? : 0 0 0
Condition0%0/3
$opts->{"no_filters"} or $tree->parent
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"no_filters"} or $tree->parent
$opts->{"no_filters"} $tree->parent
Truth table0%0/3
A or B
A= $opts->{"no_filters"}B= $tree->parent
ABresult
1X1
011
000
1272 0 ▶ my $returns_nodes = $opts->{returns_nodes} || \ my $dummy;
Condition0%0/2
$opts->{'returns_nodes'} || \my $dummy
l!l
00
MC/DC0%0/1
$opts->{'returns_nodes'} || \my $dummy
$opts->{'returns_nodes'}
Truth table0%0/2
A
A= $opts->{'returns_nodes'}
Aresult
11
00
1273 0 ▶ if ($count == 2) {
Branch: 4 branches
BranchTrueFalseTotal
if ($count == 2) { } 0 0 0
elsif ($count == 3) { } 0 0 0
elsif ($count) { } 0 0 0
elsif (@outputs) { } 0 0 0
1274 0 $$returns_nodes=0;
1275 0 push @sql,['count(DISTINCT "'.$self->{id_map}{$tree}.'"."#idx")','space'];
1276 } elsif ($count == 3) { # exists
1277 0 $$returns_nodes=0;
1278 0 push @sql,['1','space'];
1279 } elsif ($count) {
1280 0 $$returns_nodes=0;
1281 0 push @sql,['count(1)','space'];
1282 } elsif (@outputs) {
1283 0 $$returns_nodes=0;
1284 push @sql, (
1285 ($opts->{select_first} ? () : (["DISTINCT\n "])),
1286 map {
1287 0 ▶ my $n = $nodes[$_];
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'select_first'} ? : 0 0 0
1288 0 ▶ (($_==0 ? () : [",\n ",'space']),
Branch: 1 branch
BranchTrueFalseTotal
$_ == 0 ? : 0 0 0
1289 [qq{"$select[$_]"."#idx"},$n],
1290 [' AS "'.$select[$_].'.#idx"',$n],
1291 )
1292 } 0..$#nodes);
1293 } else {
1294 0 $$returns_nodes=1;
1295 0 ▶ my @order = $self->{query_node_order} ? @{$self->{query_node_order}}{@nodes} : (0..$#nodes);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'query_node_order'} ? : 0 0 0
1296 0 ▶ die "Internal error: cannot recover query_node_order" if @order!=@nodes;
Branch: 1 branch
BranchTrueFalseTotal
if @order != @nodes 0 0 0
1297 0 my $i=0;
1298 push @sql, (
1299 (($opts->{select_first} || $opts->{no_distinct}) ? () : (["DISTINCT\n "])),
1300 map {
1301 0 ▶ my $o = $_;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'select_first'} || $opts->{'no_distinct'} ? : 0 0 0
Condition0%0/3
$opts->{"select_first"} or $opts->{"no_distinct"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"select_first"} or $opts->{"no_distinct"}
$opts->{"select_first"} $opts->{"no_distinct"}
Truth table0%0/3
A or B
A= $opts->{"select_first"}B= $opts->{"no_distinct"}
ABresult
1X1
011
000
1302 0 my $n = $nodes[$o];
1303 0 ▶ my $sep = PMLTQ::Common::IsMemberNode($n) ? '//' : '/';
Branch: 1 branch
BranchTrueFalseTotal
PMLTQ::Common::IsMemberNode($n) ? : 0 0 0
1304 0 my $node_type = PMLTQ::Common::GetQueryNodeType($n,$self);
1305 (($i++==0 ? () : [",\n ",'space']),
1306 [qq{"$select[$o]"."#idx" || '$sep$node_type' }
1307 .(
1308 $opts->{node_IDs} ?
1309 0 ▶ do {
Branch: 2 branches
BranchTrueFalseTotal
$i++ == 0 ? : 0 0 0
$opts->{'node_IDs'} ? : 0 0 0
1310 0 my @types;
1311 0 ▶ if ($node_type=~m{^(?:([^/]+):)?\*$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node_type =~ m[^(?:([^/]+):)?\*$]) { } 0 0 0
1312 0 @types=@{$self->get_node_types($1)};
1313 } else {
1314 0 @types=($node_type);
1315 }
1316 0 my @col;
1317 0 ▶ if ($SEPARATE_TREES==1 or @types>1 or (@types and $types[0] ne $node_type)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 or @types > 1 or @types and $types[0] ne $node_type) { } 0 0 0
Condition0%0/9
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 or @types > 1 or @types and $types[0] ne $node_type
l!l&&r!l&&!r
000
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 or @types > 1
l!l&&r!l&&!r
000
@types and $types[0] ne $node_type
!ll&&!rl&&r
000
MC/DC0%0/4
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 or @types > 1 or @types and $types[0] ne $node_type
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 @types > 1 @types $types[0] ne $node_type
Truth table0%0/5
A or B or C and D
A= $PMLTQ::SQLEvaluator::SEPARATE_TREES == 1B= @types > 1C= @typesD= $types[0] ne $node_type
ABCDresult
1XXX1
01XX1
00111
000X0
00100
1318 0 my $name = $self->{id_map}{$n};
1319 0 ▶ @col = map [ $_, $self->join_table_for_type_cast({
Branch: 1 branch
BranchTrueFalseTotal
@types > 1 ? : 0 0 0
1320 id=>$name,
1321 cast=> $_,
1322 join => $extra_joins,
1323 left=>(@types>1 ? 1 : 0),
1324 }) ], @types;
1325 } else {
1326 0 @col=([$node_type,$select[$o]]);
1327 }
1328 0 for my $col (@col) {
1329 0 my $decl = $self->get_decl_for($col->[0]);
1330 0 $col->[2] = $self->find_special_attribute($decl,'#ID');
1331 }
1332 0 @col = grep $_->[2], @col;
1333 0 ▶ if (@col==1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@col == 1) { } 0 0 0
elsif (@col > 1) { } 0 0 0
1334 0 qq{ || '\@' || "$col[0]->[1]"."$col[0]->[2]" }
1335 } elsif (@col>1) {
1336 0 qq{ || '\@' || COALESCE(}.join(',',map qq{"$_->[1]"."$_->[2]"}, @col).qq{)}
1337 } else {
1338 0 q{}
1339 }
1340 }
1341 : ''
1342 ),$n],
1343 [' AS "'.$select[$_].'.#addr"',$n],
1344 )
1345 } @order
1346 );
1347 }
1348  
1349 # joins
1350 # print STDERR Data::Dumper::Dumper($extra_joins);
1351 {
1352 0 my $i=0;
1353 0 my %seen;
1354 0 for my $t (@table) {
1355 0 my ($tab, $name, $node)=@$t;
1356 0 ▶ push @sql, ($i++)==0 ? ["\nFROM\n ",'space'] : [",\n ",'space'];
Branch: 1 branch
BranchTrueFalseTotal
$i++ == 0 ? : 0 0 0
1357 0 push @sql, [qq{"$tab" "$name"},$node];
1358 0 $self->serialize_joins(\@sql, $extra_joins, $name, $node, \%seen);
1359 }
1360 # serialize joins for which we have no table here
1361 0 for my $name (grep { $_ ne '..' } keys %$extra_joins) {
1362 0 $self->serialize_joins(\@sql,$extra_joins,$name, undef, \%seen);
1363 }
1364 }
1365 0 my $have_where=0;
1366 {
1367 0 my @w=@{PMLTQ::Common::_group(\@where,["\n AND "])};
1368 0 ▶ push @sql, [ "\nWHERE\n ",'space'],@w if @w;
Branch: 1 branch
BranchTrueFalseTotal
if @w 0 0 0
1369 0 ▶ $have_where = 1 if @w;
Branch: 1 branch
BranchTrueFalseTotal
if @w 0 0 0
1370 }
1371 0 ▶ if (defined $opts->{select_first}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"select_first"}) 0 0 0
1372 0 my $limit = 'LIMIT 1';
1373 0 push @sql, ["\n".$limit,'space'];
1374 }
1375 0 ▶ if (@outputs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@outputs) 0 0 0
1376 0 my $output_opts;
1377 0 $$returns_nodes=0;
1378 0 ▶ my $first = first { $_->{'#name'} eq 'node' } $tree->children;
Subroutine __ANON__: not called CC=1 SCAR=6.9
1379 $output_opts = {
1380 0 id => $self->{id_map}{$first},
1381 join => {},
1382 referred_nodes => {},
1383 };
1384 0 my (@f_sql,@f_where);
1385 0 push @f_sql, ['SELECT '];
1386 0 ▶ push @f_sql, ['DISTINCT '] if $outputs[0]->{distinct};
Branch: 1 branch
BranchTrueFalseTotal
if $outputs[0]{"distinct"} 0 0 0
1387 0 $output_opts->{group_by} = $self->serialize_columns($outputs[0]->{'group-by'},0,$output_opts,'group_by');
1388 0 push @f_where, @{$self->serialize_conditions($outputs[0]->{'where'},
1389 {%$output_opts, output_filter=>1, output_filter_where_clause=>1})}
1390 0 ▶ if ref $outputs[0]->{'where'};
Branch: 1 branch
BranchTrueFalseTotal
if ref $outputs[0]{"where"} 0 0 0
1391 0 push @f_sql,[$self->serialize_columns($outputs[0]->{return},0,$output_opts,'select'),'space'];
1392 0 $output_opts->{prev_columns}=$outputs[0]->{return};
1393 $output_opts->{column_types} = [
1394 0 map $self->compute_data_type($_,{%$output_opts, output_filter=>1}), @{$output_opts->{prev_columns}}
1395 ];
1396 0 push @f_sql, [" FROM (\n"];
1397 0 unshift @sql, @f_sql;
1398 0 push @sql, [ qq{\n) "#qnodes"\n} ];
1399  
1400 {
1401 0 my %seen;
1402 my @f_table =
1403 map {
1404 0 my $n = $self->{name2node}{$_};
1405 0 $self->get_tabspec($_,PMLTQ::Common::GetQueryNodeType($n,$self),$n)
1406 0 } sort keys %{$output_opts->{referred_nodes}};
1407 0 for my $t (@f_table) {
1408 0 my ($tab, $name, $node)=@$t;
1409 0 ▶ my $left = $node->{optional} && $node->parent
Condition0%0/6
$node->{'optional'} && $node->parent && PMLTQ::Common::GetQueryNodeType($node, $self) ne PMLTQ::Common::GetQueryNodeType($node->parent, $self)
!ll&&!rl&&r
000
$node->{"optional"} and $node->parent
!ll&&!rl&&r
000
MC/DC0%0/3
$node->{'optional'} && $node->parent && PMLTQ::Common::GetQueryNodeType($node, $self) ne PMLTQ::Common::GetQueryNodeType($node->parent, $self)
$node->{"optional"} $node->parent PMLTQ::Common::GetQueryNodeType($node, $self) ne PMLTQ::Common::GetQueryNodeType($node->parent, $self)
Truth table0%0/4
A and B && C
A= $node->{"optional"}B= $node->parentC= PMLTQ::Common::GetQueryNodeType($node, $self) ne PMLTQ::Common::GetQueryNodeType($node->parent, $self)
ABCresult
0XX0
10X0
1100
1111
1410 && PMLTQ::Common::GetQueryNodeType($node, $self) ne PMLTQ::Common::GetQueryNodeType($node->parent, $self);
1411 0 ▶ push @sql, [($left ? ' LEFT ' : ' ').qq{JOIN "$tab" "$name" ON "$name"."#idx"="#qnodes"."$name.#idx"\n},$node];
Branch: 1 branch
BranchTrueFalseTotal
$left ? : 0 0 0
1412 0 $self->serialize_joins(\@sql, $output_opts->{join}, $name, $node, \%seen);
1413 }
1414 0 for my $name (grep { $_ ne '..' } keys %{$output_opts->{join}}) {
1415 0 $self->serialize_joins(\@sql,$output_opts->{join},$name, undef, \%seen);
1416 }
1417 }
1418  
1419 0 my @f_w=@{PMLTQ::Common::_group(\@f_where,["\n AND "])};
1420 0 ▶ push @sql, [ "\nWHERE\n ",'space'],@f_w if @f_w;
Branch: 1 branch
BranchTrueFalseTotal
if @f_w 0 0 0
1421 0 my $group_by = delete $output_opts->{group_by};
1422 push @sql,
1423 (@$group_by ?
1424 ["\n GROUP BY ".join(', ',@$group_by)."\n",$tree] : ()),
1425 ($outputs[0]->{'sort-by'} ?
1426 0 ▶ ["\n ORDER BY ".$self->serialize_columns($outputs[0]->{'sort-by'},1,$output_opts,'order_by'),$tree] : ());
Branch: 2 branches
BranchTrueFalseTotal
@$group_by ? : 0 0 0
$outputs[0]{'sort-by'} ? : 0 0 0
1427 0 shift @outputs;
1428 0 my $i=1;
1429 0 for my $out (@outputs) {
1430 #print "===============\n";
1431 #print STDERR "for:\n";
1432 0 $output_opts->{group_by} = $self->serialize_columns($out->{'group-by'},$i,$output_opts,'group_by');
1433 # $output_opts->{prev_columns}=$out->{'group-by'};
1434 #print STDERR "give:\n";
1435 unshift @sql, ['SELECT '
1436 .($out->{distinct} ? 'DISTINCT ' : '')
1437 0 ▶ .$self->serialize_columns($out->{'return'},$i,$output_opts,'select')." FROM (\n",$tree];
Branch: 1 branch
BranchTrueFalseTotal
$out->{'distinct'} ? : 0 0 0
1438 0 push @sql,
1439 [qq{) "#filter_$i" \n},$tree];
1440 0 ▶ if ($out->{where}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out->{"where"}) 0 0 0
1441 push @sql, ["\nWHERE\n",'space'],
1442 0 @{ $self->serialize_conditions($out->{'where'},{%$output_opts, output_filter=>$i+1, output_filter_where_clause=>1}) };
1443 }
1444 0 $output_opts->{prev_columns}=$out->{'return'};
1445 $output_opts->{column_types} = [
1446 0 map $self->compute_data_type($_,{%$output_opts, output_filter=>$i+1}), @{$output_opts->{prev_columns}}
1447 ];
1448 #print STDERR "sort:\n";
1449 0 my $group_by = delete $output_opts->{group_by};
1450 push @sql,
1451 (@$group_by ?
1452 ["\n GROUP BY ".join(', ',@$group_by)."\n",$tree] : ()),
1453 ($out->{'sort-by'} ?
1454 0 ▶ ["\n ORDER BY ".$self->serialize_columns($out->{'sort-by'},$i+1,$output_opts,'order_by')."\n",$tree] : ());
Branch: 2 branches
BranchTrueFalseTotal
@$group_by ? : 0 0 0
$out->{'sort-by'} ? : 0 0 0
1455 0 $i++;
1456 }
1457 }
1458 0 ▶ unless (defined($tree_parent_id) and defined($self->{id_map}{$tree})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tree_parent_id and defined $self->{"id_map"}{$tree}) 0 0 0
Condition0%0/3
defined $tree_parent_id and defined $self->{"id_map"}{$tree}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $tree_parent_id and defined $self->{"id_map"}{$tree}
defined $tree_parent_id defined $self->{"id_map"}{$tree}
Truth table0%0/3
A and B
A= defined $tree_parent_idB= defined $self->{"id_map"}{$tree}
ABresult
0X0
100
111
1459 0 ▶ if ($$returns_nodes) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$returns_nodes) { } 0 0 0
elsif ($opts->{'row_limit'}) { } 0 0 0
1460 # push @sql, ["\n".$self->serialize_limit($opts->{node_limit},$have_where ? 0 : 1)."\n",'space'] if defined $opts->{node_limit};
1461  
1462 # if ($opts->{syntax} eq 'oracle') {
1463 0 ▶ unless ($opts->{no_distinct}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"no_distinct"}) 0 0 0
1464 0 ▶ if ($opts->{node_limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"node_limit"}) 0 0 0
1465 0 ▶ if ($opts->{node_limit}<0 or $opts->{node_limit}==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'node_limit'} < 0 or $opts->{'node_limit'} == 1) { } 0 0 0
Condition0%0/3
$opts->{"node_limit"} < 0 or $opts->{"node_limit"} == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"node_limit"} < 0 or $opts->{"node_limit"} == 1
$opts->{"node_limit"} < 0 $opts->{"node_limit"} == 1
Truth table0%0/3
A or B
A= $opts->{"node_limit"} < 0B= $opts->{"node_limit"} == 1
ABresult
1X1
011
000
1466 0 push @sql, [' '.'LIMIT '.abs($opts->{node_limit}).';'];
1467 } else {
1468 0 unshift @sql, ['SELECT * FROM ('];
1469 0 push @sql, [qq{\n) "results" }.'LIMIT '.$opts->{node_limit}.';'];
1470 }
1471 }
1472 }
1473 # } else {
1474 # push @sql, [' '.$self->serialize_limit($opts->{node_limit},1)];
1475 # }
1476  
1477 } elsif ($opts->{row_limit}) {
1478 # if ($opts->{syntax} eq 'oracle') {
1479 0 unshift @sql, ['SELECT * FROM ('];
1480 0 push @sql, [qq{) "#count" }.'LIMIT '.$opts->{row_limit}.';'];
1481 # } else {
1482 # push @sql, [' '.$self->serialize_limit($opts->{row_limit},1)];
1483 # }
1484 }
1485 0 ▶ if ($self->{precompute_recursive_relation}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"precompute_recursive_relation"}) 0 0 0
1486 0 my @with;
1487 0 my $tables = delete $self->{precompute_recursive_relation};
1488 my $next_with_clause =
1489 0 ▶ (grep ({ !$_->{recursive} } values(%$tables)))
Branch: 1 branch
BranchTrueFalseTotal
grep({not $_->{'recursive'};} values %$tables) ? : 0 0 0
1490 ? qq{WITH\n} : qq{WITH RECURSIVE\n};
1491 0 for my $key (reverse sort keys %$tables) {
1492 0 my $spec = $tables->{$key};
1493 0 my $out;
1494 my %joins;
1495 0 my $rel_table;
1496  
1497 0 ▶ if ($spec->{table}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'table'}) { } 0 0 0
1498 # my $id = '#n';
1499 # my $J = $joins{$id}=[ ['u',$spec->{table}, qq(u."#idx" = "$id"."#idx")] ];
1500 # $out = q{u."#value"};
1501 0 $rel_table = $spec->{table};
1502 } else {
1503 0 my $pt = PMLTQ::Common::parse_expression($spec->{path});
1504 my $out = $self->serialize_expression_pt($pt,{
1505 id => '#n', # just a fake node ID
1506 join => \%joins,
1507 type=>$spec->{type},
1508 expression=>$spec->{path},
1509 0 is_positive_conjunct=>1
1510 },\%joins); # do not copy $opts here!
1511 0 $rel_table = "#rel_".$spec->{name};
1512 0 push @with, [$next_with_clause.
1513 qq{ "$rel_table" AS (\n}.
1514 qq{ SELECT "#n"."#idx" "#idx", $out "#value" FROM "$spec->{type}" "#n" }];
1515  
1516 0 $next_with_clause = qq{),\n};
1517 }
1518 0 for my $name (grep { $_ ne '..' } keys %joins) {
1519 0 for my $join_spec (@{$joins{$name}}) {
1520 0 my ($join_as,$join_tab,$join_on,$join_type)=@{$join_spec};
1521 0 $join_tab = $self->get_real_table_name($join_tab);
1522 0 ▶ $join_type||='';
Condition0%0/2
$join_type ||= ""
l!l
00
MC/DC0%0/1
$join_type ||= ""
$join_type
Truth table0%0/2
A
A= $join_type
Aresult
11
00
1523 0 push @with, ["\n ",'space'], [qq($join_type JOIN "$join_tab" "$join_as" ON $join_on)]
1524 }
1525 }
1526 0 ▶ if ($spec->{recursive}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"recursive"}) 0 0 0
1527 # recursive version of $rel_table
1528 0 my $select;
1529 0 my $max_depth='';
1530 $select =
1531 qq{ SELECT "#idx" "#idx", "#value" "#value", 1 depth, '['||"#idx"||']' path FROM "$rel_table"\n}.
1532 qq{ UNION\n}.
1533 qq{ SELECT r."#idx", c."#value", r.depth+1, r.path || '[' || c."#idx"||']'\n}.
1534 qq{ FROM "#rec_$spec->{name}" r\n}.
1535 qq{ JOIN "$rel_table" c ON r."#value" = c."#idx"\n}.
1536 qq{ WHERE r."#idx" != c."#value" and strpos(path,'[' || c."#idx" || ']')=0\n}.
1537 0 ▶ (defined($spec->{max}) ? qq{ AND r.depth <= $spec->{max}\n} : q{});
Branch: 1 branch
BranchTrueFalseTotal
defined $spec->{'max'} ? : 0 0 0
1538 0 push @with, [ qq{$next_with_clause "#rec_$spec->{name}" AS (\n}.$select ];
1539 }
1540 0 push @with, [qq{)\n}];
1541 0 $next_with_clause = qq{,\n};
1542 }
1543 0 unshift @sql, @with;
1544 }
1545 }
1546  
1547 0 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) { } 0 0 0
1548 0 return PMLTQ::Common::make_string_with_tags(\@sql,[$tree]);
1549 } else {
1550 0 return PMLTQ::Common::make_string(\@sql);
1551 }
1552 }
1553  
1554 sub serialize_joins {
1555 0 ▶ my ($self, $sql, $extra_joins, $name, $node, $seen)=@_;
Subroutine serialize_joins: not called CC=8 SCAR=42.8
Pod undocumented
1556 0 ▶ return if $seen->{$name} or $name eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$name} or $name eq ".." 0 0 0
Condition0%0/3
$seen->{$name} or $name eq ".."
l!l&&r!l&&!r
000
MC/DC0%0/2
$seen->{$name} or $name eq ".."
$seen->{$name} $name eq ".."
Truth table0%0/3
A or B
A= $seen->{$name}B= $name eq ".."
ABresult
1X1
011
000
1557 0 $seen->{$name}=1;
1558 0 for my $join_spec (@{$extra_joins->{$name}}) {
1559 0 my ($join_as,$join_tab,$join_on,$join_type)=@{$join_spec};
1560 0 $join_tab = $self->get_real_table_name($join_tab);
1561 0 ▶ $join_type||='';
Condition0%0/2
$join_type ||= ""
l!l
00
MC/DC0%0/1
$join_type ||= ""
$join_type
Truth table0%0/2
A
A= $join_type
Aresult
11
00
1562 0 ▶ push @$sql, ["\n ",'space'], [qq($join_type JOIN "$join_tab" "$join_as" ON $join_on),($node ? $node : ())];
Branch: 1 branch
BranchTrueFalseTotal
$node ? : 0 0 0
1563 0 ▶ unless ($node) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($node) 0 0 0
1564 0 print STDERR qq{MISPLACED_JOIN: $join_type JOIN "$join_tab" "$join_as" ON $join_on\n};
1565 }
1566 }
1567 0 for my $join_spec (@{$extra_joins->{$name}}) {
1568 0 $self->serialize_joins($sql, $extra_joins, $join_spec->[0], $node, $seen);
1569 }
1570 }
1571  
1572 sub serialize_columns {
1573 0 ▶ my ($self,$col_list,$j,$opts,$type,$prev_columns)=@_;
Subroutine serialize_columns: not called CC=7 SCAR=40.3
Pod undocumented
1574 0 my @cols;
1575 0 my $i=1;
1576 0 for my $col (ListV($col_list)) {
1577 0 my $dir;
1578 0 ▶ if ($type eq 'order_by') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "order_by") 0 0 0
1579 0 ▶ if ($col=~s{\s+(asc|desc)}{}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col =~ s/\s+(asc|desc)//) 0 0 0
1580 0 $dir = uc($1);
1581 }
1582 }
1583 0 my ($str,$wrap,$cal_be_null)=$self->serialize_expression({%$opts,expression=>$col,output_filter=>$j+1,is_positive_conjunct=>1});
1584 0 ▶ push @cols, $str.($type eq 'select' ? ' AS c'.($j+1).'_'.($i++) : '').
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'select' ? : 0 0 0
$dir ? : 0 0 0
1585 ($dir ? ' '.$dir : '')
1586 }
1587 0 ▶ return $type eq 'group_by' ? \@cols : join(', ', @cols);
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'group_by' ? : 0 0 0
1588 }
1589  
1590 sub get_real_table_name {
1591 0 ▶ my ($self,$path)=@_;
Subroutine get_real_table_name: not called CC=5 SCAR=34.0
Pod undocumented
1592 0 ▶ croak("No table!") unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
1593 0 ▶ if (exists $self->{pml_tables}{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"pml_tables"}{$path}) 0 0 0
1594 0 return $self->{pml_tables}{$path};
1595 }
1596 # HACK(pajas): element tables are named in PML2BASE by '#e_'.table_name($decl),
1597 # therefore we need to strip #e_, resolve and prepend.
1598 0 my $p = $path;
1599 0 ▶ my $prefix = ($p=~s/^(#e_)//) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$p =~ s/^(#e_)// ? : 0 0 0
1600 0 my $results = $self->run_sql_query(qq(SELECT "table" FROM "#PMLTABLES" WHERE "type" = ? ),{ MaxRows=>1, RaiseError=>1, Bind=>[$p] });
1601 0 my $table = $results->[0][0];
1602 0 ▶ return $self->{pml_tables}{$path} = $table ? $prefix.$table : $path;
Branch: 1 branch
BranchTrueFalseTotal
$table ? : 0 0 0
1603 }
1604  
1605 sub get_node_table_for {
1606 0 ▶ my ($self,$type)=@_;
Subroutine get_node_table_for: not called CC=4 SCAR=30.0
Pod undocumented
1607 0 my $table;
1608 0 ▶ if ($type eq '*') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '*') { } 0 0 0
elsif ($type =~ m[^([^/]+):\*$]) { } 0 0 0
1609 0 $table = $self->get_schema_names->[0].'__#trees';
1610 } elsif ($type=~m{^([^/]+):\*$}) {
1611 0 $table = $1.'__#trees';
1612 } else {
1613 0 ▶ $table = $SEPARATE_TREES==1 ?
Branch: 1 branch
BranchTrueFalseTotal
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 ? : 0 0 0
1614 $self->get_schema_name_for($type).'__#trees' : $type;
1615 }
1616 0 return $self->get_real_table_name($table);
1617 }
1618 sub get_schema_name_for {
1619 0 ▶ my ($self,$type)=@_;
Subroutine get_schema_name_for: not called CC=9 SCAR=45.0
Pod undocumented
1620 0 ▶ if ($type eq '*') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '*') { } 0 0 0
elsif ($type =~ m[^([^/]+):\*$]) { } 0 0 0
1621 0 return $self->get_schema_names->[0];
1622 } elsif ($type=~m{^([^/]+):\*$}) {
1623 0 return $1;
1624 }
1625  
1626 0 ▶ if (exists $self->{schema_types}{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"schema_types"}{$type}) 0 0 0
1627 0 ▶ if (defined $self->{schema_types}{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'schema_types'}{$type}) { } 0 0 0
1628 0 return $self->{schema_types}{$type};
1629 } else {
1630 0 confess("Did not find schema name for type $type (0)\n");
1631 }
1632 }
1633 0 ▶ croak("No type!") unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
1634 0 my $results = $self->run_sql_query(qq(SELECT "root" FROM "#PMLTYPES" WHERE "type" = ? OR ? LIKE ("type" || '/%')),{ MaxRows=>1, RaiseError=>1, Bind=>[$type,$type] });
1635 0 my $schema_name = $results->[0][0];
1636  
1637 0 ▶ if ($schema_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_name) { } 0 0 0
1638 0 return $self->{schema_types}{$type} = $schema_name
1639 } else {
1640 # fallback: try all schemas:
1641 0 $results = $self->run_sql_query(qq(SELECT DISTINCT "root" FROM "#PMLTYPES"),{RaiseError=>1});
1642 0 for $schema_name (map $_->[0], @$results) {
1643 0 my $schema = $self->get_schema($schema_name);
1644 0 ▶ if (PMLTQ::Common::QueryTypeToDecl($type,$schema)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PMLTQ::Common::QueryTypeToDecl($type, $schema)) 0 0 0
1645 0 return $self->{schema_types}{$type} = $schema_name
1646 }
1647 }
1648 0 $self->{schema_types}{$type} = undef;
1649 0 confess("Did not find schema name for type $type\n");
1650 }
1651 }
1652 sub get_schema {
1653 0 ▶ my ($self,$name)=@_;
Subroutine get_schema: not called CC=6 SCAR=37.4
Pod undocumented
1654 0 ▶ return unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
1655 0 ▶ if ($self->{schemas}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"schemas"}{$name}) 0 0 0
1656 0 return $self->{schemas}{$name};
1657 }
1658 0 my $results = $self->run_sql_query(qq(SELECT "schema" FROM "#PML" WHERE "root" = ? ),
1659 { MaxRows=>1, RaiseError=>1, LongReadLen=> 512*1024, Bind=>[$name] });
1660 0 ▶ unless (ref($results) and ref($results->[0]) and $results->[0][0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $results and ref $results->[0] and $results->[0][0]) 0 0 0
Condition0%0/6
ref $results and ref $results->[0] and $results->[0][0]
!ll&&!rl&&r
000
ref $results and ref $results->[0]
!ll&&!rl&&r
000
MC/DC0%0/3
ref $results and ref $results->[0] and $results->[0][0]
ref $results ref $results->[0] $results->[0][0]
Truth table0%0/4
A and B and C
A= ref $resultsB= ref $results->[0]C= $results->[0][0]
ABCresult
0XX0
10X0
1100
1111
1661 0 die "Failed to obtain PML schema $name\n";
1662 }
1663 0 return $self->{schemas}{$name} = Treex::PML::Schema->new({string => $results->[0][0]});
1664 }
1665 sub get_node_types {
1666 0 ▶ my ($self,$schema_name)=@_;
Subroutine get_node_types: not called CC=5 SCAR=34.0
Pod undocumented
1667 0 ▶ if ($schema_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($schema_name) { } 0 0 0
1668 0 ▶ return $self->{schema_node_types}{$schema_name} if defined $self->{schema_node_types};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"schema_node_types"} 0 0 0
1669 0 my $results = $self->run_sql_query(qq(SELECT "type","root" FROM "#PMLTYPES" ORDER BY "type"),{ MaxRows=>1, RaiseError=>1 });
1670 0 my $cached = $self->{schema_node_types} = {};
1671 0 for my $row (@$results) {
1672 0 push @{$cached->{$row->[1]}},$row->[0];
1673 }
1674 0 return $self->{schema_node_types}{$schema_name};
1675 } else {
1676 0 ▶ return $self->{node_types} if defined $self->{node_types};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"node_types"} 0 0 0
1677 0 my $results = $self->run_sql_query(qq(SELECT "type" FROM "#PMLTYPES" ORDER BY "type"),{ MaxRows=>1, RaiseError=>1 });
1678 0 return $self->{node_types} = [ map $_->[0], @$results ];
1679 }
1680 }
1681 sub get_schema_names {
1682 0 ▶ my ($self)=@_;
Subroutine get_schema_names: not called CC=2 SCAR=17.9
Pod undocumented
1683 0 ▶ return $self->{schema_names} if defined $self->{schema_names};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"schema_names"} 0 0 0
1684 0 my $results = $self->run_sql_query(qq(SELECT "root" FROM "#PML" ORDER BY "root"),{ MaxRows=>1, RaiseError=>1 });
1685 0 return $self->{schema_names} = [ map $_->[0], @$results ];
1686 }
1687  
1688 sub get_decl_for {
1689 0 ▶ my ($self,$type)=@_;
Subroutine get_decl_for: not called CC=3 SCAR=24.8
Pod undocumented
1690 0 ▶ return unless $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
1691 0 ▶ return $self->{type_decls}{$type} ||= PMLTQ::Common::QueryTypeToDecl($type,$self->get_schema_for_type($type));
Condition0%0/3
$self->{"type_decls"}{$type} ||= PMLTQ::Common::QueryTypeToDecl($type, $self->get_schema_for_type($type))
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"type_decls"}{$type} ||= PMLTQ::Common::QueryTypeToDecl($type, $self->get_schema_for_type($type))
$self->{"type_decls"}{$type} PMLTQ::Common::QueryTypeToDecl($type, $self->get_schema_for_type($type))
Truth table0%0/3
A ||= B
A= $self->{"type_decls"}{$type}B= PMLTQ::Common::QueryTypeToDecl($type, $self->get_schema_for_type($type))
ABresult
1X1
011
000
1692 }
1693  
1694 sub get_schema_for_type {
1695 0 ▶ my ($self,$type)=@_;
Subroutine get_schema_for_type: not called CC=1 SCAR=6.9
Pod undocumented
1696 0 return $self->get_schema($self->get_schema_name_for($type));
1697 }
1698  
1699 sub get_schema_flags {
1700 0 ▶ my ($self,$schema_name)=@_;
Subroutine get_schema_flags: not called CC=3 SCAR=24.8
Pod undocumented
1701 0 ▶ return $self->{schema_flags}{$schema_name} if exists($self->{schema_flags});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"schema_flags"} 0 0 0
1702 0 my $rows = eval {
1703 0 $self->run_sql_query(qq(SELECT "root","flags" FROM "#PML"),{ RaiseError=>1 });
1704 };
1705 $self->{schema_flags} = {
1706 0 ▶ map { $_->[0] => $_->[1] } @{$rows || []}
Branch: 1 branch
BranchTrueFalseTotal
$rows or [] 0 0 0
1707 };
1708 0 return $self->{schema_flags}{$schema_name};
1709 }
1710  
1711 sub join_table_for_type_cast {
1712 0 ▶ my ($self, $opts)=@_;
Subroutine join_table_for_type_cast: not called CC=4 SCAR=30.0
Pod undocumented
1713 0 my ($node_id,$cast,$ref_join,$check_joins, $left) = @$opts{qw(id cast join check_joins left)};
1714 0 my $id=$node_id."/#n_".$cast;
1715 0 ▶ unless (first {$_->[0] eq $id} (@{$ref_join->{$node_id}}, map { @{$_->{$node_id}} } @{$check_joins||[]})) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
unless (&first(sub { $_->[0] eq $id; } , @{$$ref_join{$node_id};}, map({@{$_->{$node_id};};} @{$check_joins or [];}))) 0 0 0
$check_joins or [] 0 0 0
1716 0 ▶ push @{$ref_join->{$node_id}},
Branch: 1 branch
BranchTrueFalseTotal
$left ? : 0 0 0
1717 [$id,$cast, qq("$node_id"."#type"='$cast' AND "$id"."#idx" = "$node_id"."#idx"), $left ? 'LEFT' : () ];
1718 }
1719 0 return $id;
1720 }
1721 2 my %asoc_precedence = (
1722 div => 1,
1723 mod => 1,
1724 '*' => 1,
1725 '&' => 0, #concat
1726 '-' => 0,
1727 '+' => 0,
1728 );
1729 sub serialize_expression_pt {# pt stands for parse tree
1730 0 ▶ my ($self,$pt,$opts,$extra_joins)=@_;
Subroutine serialize_expression_pt: not called CC=322 SCAR=115.5
Pod undocumented
1731 0 my $this_node_id = $opts->{id};
1732  
1733 0 ▶ if (ref($pt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pt) { } 0 0 0
1734 0 my $type = shift @$pt;
1735 0 ▶ if ($type eq 'ATTR' or $type eq 'REF_ATTR') {
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 'ATTR' or $type eq 'REF_ATTR') { } 0 0 0
elsif ($type eq 'FUNC') { } 0 0 0
elsif ($type eq 'EVERY') { } 0 0 0
elsif ($type eq 'IF') { } 0 0 0
elsif ($type eq 'ANALYTIC_FUNC') { } 0 0 0
elsif ($type eq 'EXP') { } 0 0 0
elsif ($type eq 'SET') { } 0 0 0
Condition0%0/3
$type eq "ATTR" or $type eq "REF_ATTR"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "ATTR" or $type eq "REF_ATTR"
$type eq "ATTR" $type eq "REF_ATTR"
Truth table0%0/3
A or B
A= $type eq "ATTR"B= $type eq "REF_ATTR"
ABresult
1X1
011
000
1736 0 ▶ if (defined($opts->{output_filter}) and $opts->{output_filter}>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"output_filter"} and $opts->{"output_filter"} > 1) 0 0 0
Condition0%0/3
defined $opts->{"output_filter"} and $opts->{"output_filter"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"output_filter"} and $opts->{"output_filter"} > 1
defined $opts->{"output_filter"} $opts->{"output_filter"} > 1
Truth table0%0/3
A and B
A= defined $opts->{"output_filter"}B= $opts->{"output_filter"} > 1
ABresult
0X0
100
111
1737 0 die "Attribute reference cannot be used in output filter columns whose input is not the body of the query: '$opts->{expression}'"
1738 }
1739 0 my ($id,$attr,$cmp,$node_type,$cast,$decl);
1740 0 ▶ if ($type eq 'REF_ATTR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'REF_ATTR') { } 0 0 0
1741 0 $id = $pt->[0];
1742 0 $pt=$pt->[1];
1743 0 ▶ die "Error in attribute reference of node $id in expression $opts->{expression} of node '$this_node_id'"
Branch: 1 branch
BranchTrueFalseTotal
unless shift @$pt eq "ATTR" 0 0 0
1744 unless shift(@$pt) eq 'ATTR'; # not likely
1745 0 ▶ if ($id eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($id eq '$') { } 0 0 0
1746 0 $cmp=0;
1747 0 $id=$this_node_id;
1748 0 $node_type = $opts->{type};
1749 } else {
1750 0 $cmp = $self->cmp_subquery_scope($this_node_id,$id);
1751 # print "Comparing $this_node_id and $id scope: $cmp\n";
1752 0 ▶ if ($cmp<0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp < 0) 0 0 0
1753 0 die "Node '$id' belongs to a sub-query and cannot be referred from the scope of node '$this_node_id' ($opts->{expression})\n";
1754 }
1755 0 $node_type = $self->get_type_of_node($id);
1756 }
1757 } else {
1758 0 $cmp=0;
1759 0 $id=$this_node_id;
1760 0 $node_type = $opts->{type};
1761 }
1762 0 ▶ if($pt->[0] =~ /^(.+)\?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pt->[0] =~ /^(.+)\?$/) { } 0 0 0
elsif ($node_type =~ m[^(?:([^/]+):)?\*$]) { } 0 0 0
1763 0 $cast = $1; shift @$pt;
1764 } elsif ($node_type=~m{^(?:([^/]+):)?\*$}) {
1765 0 my $node_types = $self->get_node_types($1);
1766 0 my @possibilities;
1767 0 ▶ my $path = join '/',map { ($_ eq '[]' or $_ eq 'content()') ? '#content' : $_ } @$pt;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '[]' || $_ eq 'content()' ? : 0 0 0
Condition0%0/3
$_ eq "[]" or $_ eq "content()"
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "[]" or $_ eq "content()"
$_ eq "[]" $_ eq "content()"
Truth table0%0/3
A or B
A= $_ eq "[]"B= $_ eq "content()"
ABresult
1X1
011
000
1768 0 for my $nt (@$node_types) {
1769 0 my $decl = $self->get_decl_for($nt);
1770 0 ▶ my $attr_decl = $decl && $decl->find($path);
Condition0%0/3
$decl && $decl->find($path)
!ll&&!rl&&r
000
MC/DC0%0/2
$decl && $decl->find($path)
$decl $decl->find($path)
Truth table0%0/3
A && B
A= $declB= $decl->find($path)
ABresult
0X0
100
111
1771 0 ▶ $attr_decl=$attr_decl->get_content_decl
Branch: 1 branch
BranchTrueFalseTotal
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7 and do { $attr_decl = $attr_decl->get_content_decl } 0 0 0
Condition0%0/6
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7
!ll&&!rl&&r
000
$attr_decl->get_decl_type == 6 or $attr_decl->get_decl_type == 7
l!l&&r!l&&!r
000
MC/DC0%0/3
$attr_decl and $attr_decl->get_decl_type == 6 || $attr_decl->get_decl_type == 7
$attr_decl $attr_decl->get_decl_type == 6 $attr_decl->get_decl_type == 7
Truth table0%0/4
A and B or C
A= $attr_declB= $attr_decl->get_decl_type == 6C= $attr_decl->get_decl_type == 7
ABCresult
0XX0
1000
11X1
1011
1772 while ($attr_decl and ($attr_decl->get_decl_type == PML_LIST_DECL or
1773 $attr_decl->get_decl_type == PML_ALT_DECL));
1774  
1775 0 ▶ push @possibilities,
Branch: 2 branches
BranchTrueFalseTotal
if $attr_decl and $attr_decl->is_atomic 0 0 0
$type eq 'REF_ATTR' ? : 0 0 0
Condition0%0/3
$attr_decl and $attr_decl->is_atomic
!ll&&!rl&&r
000
MC/DC0%0/2
$attr_decl and $attr_decl->is_atomic
$attr_decl $attr_decl->is_atomic
Truth table0%0/3
A and B
A= $attr_declB= $attr_decl->is_atomic
ABresult
0X0
100
111
1776 $type eq 'REF_ATTR' ? ['REF_ATTR',$id,['ATTR',$nt.'?',@$pt]] : ['ATTR',$nt.'?',@$pt]
1777 if ($attr_decl and $attr_decl->is_atomic);
1778 }
1779 0 ▶ if (!@possibilities) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @possibilities) { } 0 0 0
elsif (@possibilities == 1) { } 0 0 0
1780 0 die "The attribute path '$path' is not valid for any node type matched by the '$node_type' wildcard: @$node_types\n";
1781 } elsif (@possibilities == 1) {
1782 0 return $self->serialize_expression_pt($possibilities[0],$opts,$extra_joins);
1783 } else {
1784 0 return $self->serialize_expression_pt(['FUNC','first_defined',\@possibilities],$opts,$extra_joins);
1785 }
1786 }
1787 0 ▶ $decl = $self->get_decl_for($cast || $node_type);
Condition0%0/3
$cast || $node_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$cast || $node_type
$cast $node_type
Truth table0%0/3
A || B
A= $castB= $node_type
ABresult
1X1
011
000
1788 0 ▶ if (!$decl) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($decl) 0 0 0
1789 0 die "Couldn't determine node type of node '$id' to evaluate $opts->{expression}\n";
1790 }
1791 # ??? why not just $table = ($cast || $node_type) ?? members?
1792 0 my $table=PMLTQ::Common::DeclPathToQueryType($decl->get_decl_path);
1793 0 ▶ $opts->{referred_nodes}{$id}=1 if ref($opts->{referred_nodes});
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts->{"referred_nodes"} 0 0 0
1794  
1795 0 my $node_id = $id;
1796 0 my $j;
1797 # if (!$opts->{is_positive_conjunct} or $cmp) {
1798 # print "extra joins\n";
1799 # $opts->{use_exists}=1;
1800 # $j=$extra_joins;
1801 # } else {
1802 # print "normal joins\n";
1803 0 $j=$opts->{join};
1804 # }
1805 0 ▶ $extra_joins->{$node_id}||=[];
Condition0%0/2
$extra_joins->{$node_id} ||= []
l!l
00
MC/DC0%0/1
$extra_joins->{$node_id} ||= []
$extra_joins->{$node_id}
Truth table0%0/2
A
A= $extra_joins->{$node_id}
Aresult
11
00
1806  
1807 0 my $ref_join = $opts->{join};
1808 0 $ref_join = $ref_join->{'..'} for 1..$cmp;
1809 0 ▶ $ref_join->{$node_id}||=[];
Condition0%0/2
$ref_join->{$node_id} ||= []
l!l
00
MC/DC0%0/1
$ref_join->{$node_id} ||= []
$ref_join->{$node_id}
Truth table0%0/2
A
A= $ref_join->{$node_id}
Aresult
11
00
1810 0 ▶ if ($SEPARATE_TREES==1 or ($cast and $cast ne $node_type)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 or $cast and $cast ne $node_type) { } 0 0 0
Condition0%0/6
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 or $cast and $cast ne $node_type
l!l&&r!l&&!r
000
$cast and $cast ne $node_type
!ll&&!rl&&r
000
MC/DC0%0/3
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 or $cast and $cast ne $node_type
$PMLTQ::SQLEvaluator::SEPARATE_TREES == 1 $cast $cast ne $node_type
Truth table0%0/4
A or B and C
A= $PMLTQ::SQLEvaluator::SEPARATE_TREES == 1B= $castC= $cast ne $node_type
ABCresult
1XX1
0111
00X0
0100
1811 0 ▶ $id = $self->join_table_for_type_cast({
Branch: 1 branch
BranchTrueFalseTotal
$cast ? : 0 0 0
1812 # table=>$table,
1813 id=>$node_id,
1814 left=>($cast?1:0),
1815 cast=> $table, # ($cast||$node_type),
1816 join => $ref_join,
1817 check_joins => [$extra_joins]
1818 });
1819 } else {
1820 0 $id=$node_id;
1821 }
1822  
1823 0 my @t = @$pt;
1824 0 my $column;
1825 0 my $iter=0;
1826 0 ▶ while ($iter++ < 100) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iter++ < 100) 0 0 0
1827 0 my ($mdecl,$mtable);
1828 0 ▶ my $can_be_null = ($cast and $iter == 1) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cast && $iter == 1 ? : 0 0 0
Condition0%0/3
$cast and $iter == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$cast and $iter == 1
$cast $iter == 1
Truth table0%0/3
A and B
A= $castB= $iter == 1
ABresult
0X0
100
111
1829 0 my $decl_is = $decl->get_decl_type;
1830 0 my $extra_condition;
1831 my $pos_condition;
1832 0 my $prev = $id;
1833 0 ▶ if ($decl_is == PML_STRUCTURE_DECL or
Branch: 6 branches
BranchTrueFalseTotal
if ($decl_is == 3 or $decl_is == 4) { } 0 0 0
elsif ($decl_is == 6) { } 0 0 0
elsif ($decl_is == 7) { } 0 0 0
elsif ($decl_is == 5) { } 0 0 0
elsif ($decl_is == 13) { } 0 0 0
elsif ($decl->is_atomic) { } 0 0 0
Condition0%0/3
$decl_is == 3 or $decl_is == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$decl_is == 3 or $decl_is == 4
$decl_is == 3 $decl_is == 4
Truth table0%0/3
A or B
A= $decl_is == 3B= $decl_is == 4
ABresult
1X1
011
000
1834 $decl_is == PML_CONTAINER_DECL) {
1835 0 ▶ last unless @t;
Branch: 1 branch
BranchTrueFalseTotal
unless @t 0 0 0
1836 0 $column= shift @t;
1837 0 ▶ if ($column eq '[]' or $column eq 'content()') {
Branch: 1 branch
BranchTrueFalseTotal
if ($column eq "[]" or $column eq "content()") 0 0 0
Condition0%0/3
$column eq "[]" or $column eq "content()"
l!l&&r!l&&!r
000
MC/DC0%0/2
$column eq "[]" or $column eq "content()"
$column eq "[]" $column eq "content()"
Truth table0%0/3
A or B
A= $column eq "[]"B= $column eq "content()"
ABresult
1X1
011
000
1838 0 $column = '#content';
1839 }
1840 0 $mdecl = $decl->get_member_by_name($column);
1841 0 ▶ if (!$mdecl and $decl_is == PML_STRUCTURE_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $mdecl and $decl_is == 3) 0 0 0
Condition0%0/3
not $mdecl and $decl_is == 3
!ll&&!rl&&r
000
MC/DC0%0/2
not $mdecl and $decl_is == 3
not $mdecl $decl_is == 3
Truth table0%0/3
not(A) and B
A= not $mdeclB= $decl_is == 3
ABresult
0X0
100
111
1842 0 $mdecl=$decl->get_member_by_name($column.'.rf');
1843 0 ▶ $mdecl=undef unless $mdecl; # and $mdecl->get_knit_name eq $column;
Branch: 1 branch
BranchTrueFalseTotal
unless $mdecl 0 0 0
1844 }
1845 0 ▶ if ($column eq '#content') {
Branch: 2 branches
BranchTrueFalseTotal
if ($column eq '#content') { } 0 0 0
elsif ($mdecl) { } 0 0 0
1846 # TODO(pajas): Figure out if there are cases when #content
1847 # cannot be NULL.
1848 0 $can_be_null=1;
1849 } elsif ($mdecl) {
1850 0 ▶ unless ($mdecl->is_required) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mdecl->is_required) 0 0 0
1851 0 $can_be_null=1;
1852 }
1853 0 $mdecl = $mdecl->get_knit_content_decl;
1854 }
1855 } elsif ($decl_is == PML_LIST_DECL) {
1856 0 ▶ shift @t if @t and $t[0] eq 'LM';
Branch: 1 branch
BranchTrueFalseTotal
if @t and $t[0] eq "LM" 0 0 0
Condition0%0/3
@t and $t[0] eq "LM"
!ll&&!rl&&r
000
MC/DC0%0/2
@t and $t[0] eq "LM"
@t $t[0] eq "LM"
Truth table0%0/3
A and B
A= @tB= $t[0] eq "LM"
ABresult
0X0
100
111
1857 # if ($decl->is_ordered and @t and $t[0]=~m{^\[\s*(\d+)\s*\]$}) {
1858 # $mdecl = $decl;
1859 # } else {
1860 0 $mdecl=$decl->get_knit_content_decl;
1861 # }
1862 0 $column='#value';
1863 0 $can_be_null=1;
1864 } elsif ($decl_is == PML_ALT_DECL) {
1865 0 ▶ shift @t if @t and $t[0] eq 'AM';
Branch: 1 branch
BranchTrueFalseTotal
if @t and $t[0] eq "AM" 0 0 0
Condition0%0/3
@t and $t[0] eq "AM"
!ll&&!rl&&r
000
MC/DC0%0/2
@t and $t[0] eq "AM"
@t $t[0] eq "AM"
Truth table0%0/3
A and B
A= @tB= $t[0] eq "AM"
ABresult
0X0
100
111
1866 0 $mdecl=$decl->get_knit_content_decl;
1867 0 $column='#value';
1868 0 $can_be_null=1;
1869 } elsif ($decl_is == PML_SEQUENCE_DECL) {
1870 0 ▶ last unless @t;
Branch: 1 branch
BranchTrueFalseTotal
unless @t 0 0 0
1871 0 $column= shift @t;
1872 #print STDERR "prev: $prev id: $id\n";
1873 0 ▶ if ($column=~s/^\[(\d+)\]//g) {
Branch: 2 branches
BranchTrueFalseTotal
if ($column =~ s/^\[(\d+)\]//g) { } 0 0 0
elsif ($column =~ s/\[\s*(\d+)\s*\]$//g) { } 0 0 0
1874 0 $pos_condition = qq{"#pos" = $1-1 };
1875 } elsif ($column=~s/\[\s*(\d+)\s*\]$//g) {
1876 0 $pos_condition = qq{"#elpos" = $1-1 };
1877 }
1878 0 $mdecl = $decl->get_element_by_name($column);
1879 0 ▶ if ($mdecl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdecl) { } 0 0 0
1880 0 $mtable='#e_'.PMLTQ::Common::DeclPathToQueryType($mdecl->get_knit_content_decl->get_decl_path);
1881 } else {
1882 0 ▶ die "Sequence does not allow element '$column' in expression $opts->{expression} at node "
Condition0%0/3
$cast || $node_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$cast || $node_type
$cast $node_type
Truth table0%0/3
A || B
A= $castB= $node_type
ABresult
1X1
011
000
1883 .($cast||$node_type)
1884 ." \$$this_node_id: ".join('/',@t);
1885 }
1886 0 $can_be_null=1;
1887 } elsif ($decl_is == PML_ELEMENT_DECL) {
1888 0 $mdecl=$decl->get_knit_content_decl;
1889 0 $column='#value';
1890 } elsif ($decl->is_atomic) {
1891 # if (@t==1 and $t[0] eq '.') {
1892 # $mdecl = $decl;
1893 # $column='#value';
1894 # shift @t;
1895 # } else {
1896 0 ▶ die "Cannot apply attribute path to an atomic type in expression $opts->{expression} at node "
Condition0%0/3
$cast || $node_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$cast || $node_type
$cast $node_type
Truth table0%0/3
A || B
A= $castB= $node_type
ABresult
1X1
011
000
1897 .($cast||$node_type)
1898 ." \$$this_node_id: ".join('/',@t);
1899 # }
1900 } else {
1901 0 die ref($self)." internal error: Didn't expect type $decl_is\n";
1902 }
1903 0 ▶ die "Didn't find member '$column' on '$table' while compiling expression $opts->{expression} of node '$this_node_id'" unless $mdecl;
Branch: 1 branch
BranchTrueFalseTotal
unless $mdecl 0 0 0
1904  
1905 0 my $mdecl_is = $mdecl->get_decl_type;
1906 0 ▶ $opts->{can_be_null}=1 if $can_be_null;
Branch: 1 branch
BranchTrueFalseTotal
if $can_be_null 0 0 0
1907  
1908 0 ▶ my $is_ambiguous = ($mdecl_is == PML_LIST_DECL or $mdecl_is == PML_ALT_DECL or $mdecl_is == PML_SEQUENCE_DECL) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mdecl_is == 6 || $mdecl_is == 7 || $mdecl_is == 5 ? : 0 0 0
Condition0%0/6
$mdecl_is == 6 or $mdecl_is == 7 or $mdecl_is == 5
l!l&&r!l&&!r
000
$mdecl_is == 6 or $mdecl_is == 7
l!l&&r!l&&!r
000
MC/DC0%0/3
$mdecl_is == 6 or $mdecl_is == 7 or $mdecl_is == 5
$mdecl_is == 6 $mdecl_is == 7 $mdecl_is == 5
Truth table0%0/4
A or B or C
A= $mdecl_is == 6B= $mdecl_is == 7C= $mdecl_is == 5
ABCresult
1XX1
01X1
0011
0000
1909  
1910 #print STDERR "prev: $prev, column: $column, decl: $decl, mdecl: $mdecl, can_be_null: $can_be_null\n";
1911 #print STDERR "mdecl is ",$mdecl->get_decl_type,"; is atomic: ",$mdecl->is_atomic," \n";
1912  
1913 0 ▶ if ($mdecl->is_atomic) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mdecl->is_atomic) { } 0 0 0
elsif ($opts->{'allow_non_atomic'} and $mdecl->get_decl_type != 13 and !@t && $mdecl->get_decl_type != 6 && $mdecl->get_decl_type != 7 || @t == 1 && $t[0] eq '.') { } 0 0 0
1914 0 ▶ if (@t) {
Branch: 1 branch
BranchTrueFalseTotal
if (@t) 0 0 0
1915 0 ▶ die "Cannot follow attribute path past atomic type while compiling expression $opts->{expression} of node "
Condition0%0/3
$cast || $node_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$cast || $node_type
$cast $node_type
Truth table0%0/3
A || B
A= $castB= $node_type
ABresult
1X1
011
000
1916 .($cast||$node_type)." \$$this_node_id: ".join('/',@t);
1917 }
1918 0 return qq( "$prev"."$column" );
1919 ▶ } elsif ($opts->{allow_non_atomic} and $mdecl->get_decl_type != PML_ELEMENT_DECL and
Condition0%0/18
$opts->{"allow_non_atomic"} and $mdecl->get_decl_type != 13 and !@t && $mdecl->get_decl_type != 6 && $mdecl->get_decl_type != 7 || @t == 1 && $t[0] eq "."
!ll&&!rl&&r
000
$opts->{"allow_non_atomic"} and $mdecl->get_decl_type != 13
!ll&&!rl&&r
000
not @t and $mdecl->get_decl_type != 6 and $mdecl->get_decl_type != 7 or @t == 1 and $t[0] eq "."
l!l&&r!l&&!r
000
not @t and $mdecl->get_decl_type != 6 and $mdecl->get_decl_type != 7
!ll&&!rl&&r
000
not @t and $mdecl->get_decl_type != 6
!ll&&!rl&&r
000
@t == 1 and $t[0] eq "."
!ll&&!rl&&r
000
MC/DC0%0/7
$opts->{"allow_non_atomic"} and $mdecl->get_decl_type != 13 and !@t && $mdecl->get_decl_type != 6 && $mdecl->get_decl_type != 7 || @t == 1 && $t[0] eq "."
$opts->{"allow_non_atomic"} $mdecl->get_decl_type != 13 not @t $mdecl->get_decl_type != 6 $mdecl->get_decl_type != 7 @t == 1 $t[0] eq "."
Truth table0%0/12
A and B and not(C) and D and E or F and G
A= $opts->{"allow_non_atomic"}B= $mdecl->get_decl_type != 13C= not @tD= $mdecl->get_decl_type != 6E= $mdecl->get_decl_type != 7F= @t == 1G= $t[0] eq "."
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XX0X0
110XX100
1110X0X0
1110X100
111100X0
11110100
11111XX1
110XX111
1110X111
11110111
1920 ((!@t and $mdecl->get_decl_type != PML_LIST_DECL and $mdecl->get_decl_type != PML_ALT_DECL)
1921 or( @t==1 and $t[0] eq '.'))) {
1922 0 return qq( "$id"."$column" );
1923 } else {
1924  
1925 #
1926 # We now decide our strategy: either we use JOIN in the apropriate SELECT,
1927 # or use a subquery with EXISTS
1928 # or, in PostgreSQL, we may even try JOIN on the current SELECT
1929 #
1930  
1931 0 my $j = $ref_join; # default is join to the current or outer SELECT
1932 0 my $left=''; # use LEFT join
1933 0 ▶ if ($opts->{use_exists}==2) {
Branch: 3 branches
BranchTrueFalseTotal
if ($opts->{'use_exists'} == 2) { } 0 0 0
elsif ($opts->{'allow_non_atomic'}) { } 0 0 0
elsif ($opts->{'can_be_null'} or $is_ambiguous and $cmp) { } 0 0 0
1934 # forced use of EXISTS
1935 0 $j=$extra_joins;
1936 } elsif ($opts->{allow_non_atomic}) {
1937 # # special case: we want to join members
1938 ▶ } elsif ($opts->{can_be_null} or ($is_ambiguous and $cmp)) {
Condition0%0/6
$opts->{"can_be_null"} or $is_ambiguous and $cmp
l!l&&r!l&&!r
000
$is_ambiguous and $cmp
!ll&&!rl&&r
000
MC/DC0%0/3
$opts->{"can_be_null"} or $is_ambiguous and $cmp
$opts->{"can_be_null"} $is_ambiguous $cmp
Truth table0%0/4
A or B and C
A= $opts->{"can_be_null"}B= $is_ambiguousC= $cmp
ABCresult
1XX1
0111
00X0
0100
1939 # either a nullable column or an ambiguous column from some outer SELECT
1940 0 ▶ if (!$opts->{is_positive_conjunct}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $opts->{'is_positive_conjunct'}) { } 0 0 0
elsif ($cmp) { } 0 0 0
1941 # non-positive conjunct: we must use EXIST
1942 0 ▶ $opts->{use_exists}||=1;
Condition0%0/2
$opts->{"use_exists"} ||= 1
l!l
00
MC/DC0%0/1
$opts->{"use_exists"} ||= 1
$opts->{"use_exists"}
Truth table0%0/2
A
A= $opts->{"use_exists"}
Aresult
11
00
1943 0 $j=$extra_joins;
1944 } elsif ($cmp) {
1945 # outer SELECT, we can't join there if nullable
1946 0 ▶ if ($ALLOW_MISPLACED_PG_JOIN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PMLTQ::SQLEvaluator::ALLOW_MISPLACED_PG_JOIN) { } 0 0 0
1947 # but in postgres, we may in fact JOIN to the current SELECT
1948 # (and we do because EXISTS is very slow there,
1949 # try e.g. the query: t-node [ 0x a/aux.rf a-node [] ]
1950 # with forced EXSITS
1951 0 $j = $opts->{join};
1952 } else {
1953 # elsewhere we use EXISTS
1954 0 ▶ $opts->{use_exists}||=1;
Condition0%0/2
$opts->{"use_exists"} ||= 1
l!l
00
MC/DC0%0/1
$opts->{"use_exists"} ||= 1
$opts->{"use_exists"}
Truth table0%0/2
A
A= $opts->{"use_exists"}
Aresult
11
00
1955 0 $j=$extra_joins;
1956 }
1957 } else {
1958 0 $opts->{use_exists}||=1 unless (PREFER_LEFT_JOINS);
1959 #$j=$extra_joins;
1960 0 ▶ if ($opts->{use_exists}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'use_exists'}) { } 0 0 0
1961 0 $j=$extra_joins;
1962 } else {
1963  
1964 # we are in a positive conjunct, so the value must be there and non-null, right?
1965  
1966 0 $left='LEFT';
1967 }
1968 }
1969 }
1970 0 my $i=$self->{join_id}++;
1971 0 $id=$node_id."/$i";
1972 0 my $condition = qq("$id"."#idx" = "$prev"."$column");
1973  
1974 0 ▶ if ($pos_condition) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos_condition) 0 0 0
1975 0 $condition= qq{($condition AND "$id".$pos_condition)};
1976 }
1977  
1978 0 ▶ if ($extra_condition) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_condition) 0 0 0
1979 0 $condition= qq{($condition AND "$id".$extra_condition)};
1980 }
1981 0 my $mdecl_is = $mdecl->get_decl_type;
1982  
1983 0 ▶ if (($mdecl_is == PML_LIST_DECL) and @t and $t[0]=~m{^\[\s*(\d+)\s*\]$}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdecl_is == 6 and @t and $t[0] =~ /^\[\s*(\d+)\s*\]$/) 0 0 0
Condition0%0/6
$mdecl_is == 6 and @t and $t[0] =~ /^\[\s*(\d+)\s*\]$/
!ll&&!rl&&r
000
$mdecl_is == 6 and @t
!ll&&!rl&&r
000
MC/DC0%0/3
$mdecl_is == 6 and @t and $t[0] =~ /^\[\s*(\d+)\s*\]$/
$mdecl_is == 6 @t $t[0] =~ /^\[\s*(\d+)\s*\]$/
Truth table0%0/4
A and B and C
A= $mdecl_is == 6B= @tC= $t[0] =~ /^\[\s*(\d+)\s*\]$/
ABCresult
0XX0
10X0
1100
1111
1984 0 ▶ if ($mdecl->is_ordered) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mdecl->is_ordered) { } 0 0 0
1985 0 $condition= qq{($condition AND "$id"."#pos" = $1-1)};
1986 0 shift @t;
1987 } else {
1988 0 my $p = $mdecl->get_decl_path;
1989 0 $p=~s/^!//;
1990 0 die "Cannot use index '$t[0]' in expression '$opts->{expression}' of node '$this_node_id' on value of type '$p' that is declared in the PML schema as an *unordered* list";
1991 }
1992 }
1993 0 ▶ $table = $mtable||PMLTQ::Common::DeclPathToQueryType($mdecl->get_decl_path);
Condition0%0/3
$mtable || PMLTQ::Common::DeclPathToQueryType($mdecl->get_decl_path)
l!l&&r!l&&!r
000
MC/DC0%0/2
$mtable || PMLTQ::Common::DeclPathToQueryType($mdecl->get_decl_path)
$mtable PMLTQ::Common::DeclPathToQueryType($mdecl->get_decl_path)
Truth table0%0/3
A || B
A= $mtableB= PMLTQ::Common::DeclPathToQueryType($mdecl->get_decl_path)
ABresult
1X1
011
000
1994 0 ▶ push @{$j->{$node_id}},[$id,$table, $condition, $opts->{output_filter} ? 'LEFT' : $left ];
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'output_filter'} ? : 0 0 0
1995 #print STDERR "$node_id => JOIN $table as $id ON $condition\n";
1996 }
1997 0 $decl=$mdecl;
1998 }
1999 0 ▶ if ($iter>=100) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iter >= 100) 0 0 0
2000 0 die "Deep recursion while compiling '$opts->{expression}' of node '$this_node_id'";
2001 }
2002 0 die "Expression '$opts->{expression}' of node '$this_node_id' does not lead to an attomic value";
2003 } elsif ($type eq 'FUNC') {
2004 0 my $name = $pt->[0];
2005 0 my $args = $pt->[1];
2006 0 $opts->{can_be_null}=1;
2007 0 my $id;
2008 0 ▶ if ($name=~/^(?:descendants|lbrothers|sons|depth|depth_first_order|order_span_min|order_span_max|name|type_of)$/) {
Branch: 16 branches
BranchTrueFalseTotal
if ($name =~ /^(?:descendants|lbrothers|sons|depth|depth_first_order|order_span_min|order_span_max|name|type_of)$/) { } 0 0 0
elsif ($name eq 'length') { } 0 0 0
elsif ($name =~ /^(?:lower|upper)$/) { } 0 0 0
elsif ($name =~ /^(?:abs|floor|ceil|exp|sqrt|ln)$/) { } 0 0 0
elsif ($name =~ /^(?:log|power)$/) { } 0 0 0
elsif ($name eq 'address') { } 0 0 0
elsif ($name =~ /^(file|tree_no)$/) { } 0 0 0
elsif ($name eq 'rbrothers') { } 0 0 0
elsif ($name eq 'id') { } 0 0 0
elsif ($name =~ /^(?:round|trunc)$/) { } 0 0 0
elsif ($name eq 'percnt') { } 0 0 0
elsif ($name eq 'substr') { } 0 0 0
elsif ($name =~ /(?:replace|tr)$/) { } 0 0 0
elsif ($name eq 'substitute') { } 0 0 0
elsif ($name eq 'match') { } 0 0 0
elsif ($name eq 'first_defined') { } 0 0 0
2009 0 ▶ if ($args and @$args==1 and !ref($args->[0]) and $args->[0]=~s/^\$//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//) { } 0 0 0
elsif ($args and @$args) { } 0 0 0
Condition0%0/9
$args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//
!ll&&!rl&&r
000
$args and @$args == 1 and not ref $args->[0]
!ll&&!rl&&r
000
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/4
$args and @$args == 1 and not ref $args->[0] and $args->[0] =~ s/^\$//
$args @$args == 1 not ref $args->[0] $args->[0] =~ s/^\$//
Truth table0%0/5
A and B and not(C) and D
A= $argsB= @$args == 1C= not ref $args->[0]D= $args->[0] =~ s/^\$//
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2010 0 $id = $args->[0];
2011 0 ▶ if ($self->cmp_subquery_scope($this_node_id,$id)<0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmp_subquery_scope($this_node_id, $id) < 0) 0 0 0
2012 0 die "Node '$id' belongs to a sub-query and cannot be referred from the scope of node '$this_node_id' ($opts->{expression})\n";
2013 }
2014 ▶ } elsif ($args and @$args) {
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2015 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n";
2016 } else {
2017 0 $id=$this_node_id;
2018 }
2019 0 ▶ $opts->{referred_nodes}{$id}=1 if ref($opts->{referred_nodes});
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts->{"referred_nodes"} 0 0 0
2020  
2021 0 ▶ if ($name =~ /^order_span/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^order_span/) 0 0 0
2022 0 my $span = $1;
2023 0 my $flags = $self->get_schema_flags($self->get_schema_name_for($opts->{type}));
2024 0 ▶ if (!defined($flags) or !($flags & MAX_MIN_ORD)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $flags and $flags & 4) 0 0 0
Condition0%0/3
defined $flags and $flags & 4
!ll&&!rl&&r
000
MC/DC0%0/2
defined $flags and $flags & 4
defined $flags $flags & 4
Truth table0%0/3
A and B
A= defined $flagsB= $flags & 4
ABresult
0X0
100
111
2025 0 my $n = $self->{name2node}{$id};
2026 0 ▶ $n or die "Cannot refer to node '$id' from $name() in expression $opts->{expression} of node '$this_node_id'!\n";
Branch: 1 branch
BranchTrueFalseTotal
$n or die qq[Cannot refer to node '${id}' from $name() in expression $opts->{"expression"} of node '${this_node_id}'!\n] 0 0 0
2027 0 my $type = PMLTQ::Common::GetQueryNodeType($n,$self);
2028 0 my $decl = $self->get_decl_for($type);
2029 0 ▶ if ($decl->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_decl_type == 13) 0 0 0
2030 0 $decl = $decl->get_content_decl;
2031 }
2032 0 my ($order) = map { $_->get_name } $decl->find_members_by_role('#ORDER');
2033 0 ▶ if (defined $order) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $order) { } 0 0 0
2034 0 return qq{"$id"."$order"}
2035 } else {
2036 0 die "No ordering is defined on nodes of type '$type'!\n";
2037 }
2038 }
2039 }
2040 0 ▶ return ($name eq 'descendants') ? qq{("$id"."#r"-"$id"."#idx")}
Branch: 9 branches
BranchTrueFalseTotal
$name eq 'descendants' ? : 0 0 0
$name eq 'lbrothers' ? : 0 0 0
$name eq 'sons' ? : 0 0 0
$name eq 'depth' ? : 0 0 0
$name eq 'depth_first_order' ? : 0 0 0
$name =~ /order_span_min/ ? : 0 0 0
$name eq 'order_span_max' ? : 0 0 0
$name eq 'name' ? : 0 0 0
$name eq 'type_of' ? : 0 0 0
2041 : ($name eq 'lbrothers') ? qq{"$id"."#chord"}
2042 : ($name eq 'sons') ? qq{"$id"."#chld"}
2043 : ($name eq 'depth') ? qq{"$id"."#lvl"}
2044 : ($name eq 'depth_first_order') ? qq{("$id"."#idx"-"$id"."#root_idx")}
2045 : ($name =~ 'order_span_min') ? qq{"$id"."#min_ord"}
2046 : ($name eq 'order_span_max') ? qq{"$id"."#max_ord"}
2047 : ($name eq 'name') ? qq{"$id"."#name"}
2048 : ($name eq 'type_of') ? qq{"$id"."#type"}
2049 : die "PMLTQ internal error while compiling expression: should never get here!";
2050 } elsif ($name eq 'length') {
2051 0 ▶ if ($args and @$args==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 1) { } 0 0 0
Condition0%0/3
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 1
$args @$args == 1
Truth table0%0/3
A and B
A= $argsB= @$args == 1
ABresult
0X0
100
111
2052 0 my $ret = 'LENGTH('
2053 . $self->serialize_expression_pt($args->[0],$opts,$extra_joins)
2054 . ')';
2055 0 return $ret;
2056 } else {
2057 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(string)\n";
2058 }
2059 } elsif ($name=~/^(?:lower|upper)$/) {
2060 0 ▶ if ($args and @$args==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 1) { } 0 0 0
Condition0%0/3
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 1
$args @$args == 1
Truth table0%0/3
A and B
A= $argsB= @$args == 1
ABresult
0X0
100
111
2061 0 return uc($name).'('
2062 . $self->serialize_expression_pt($args->[0],$opts,$extra_joins)
2063 . ')';
2064 } else {
2065 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(string)\n";
2066 }
2067 } elsif ($name=~/^(?:abs|floor|ceil|exp|sqrt|ln)$/) {
2068 0 ▶ if ($args and @$args==1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 1) { } 0 0 0
Condition0%0/3
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 1
$args @$args == 1
Truth table0%0/3
A and B
A= $argsB= @$args == 1
ABresult
0X0
100
111
2069 0 return uc($name).'('
2070 . $self->serialize_expression_pt($args->[0],$opts,$extra_joins)
2071 . ')';
2072 } else {
2073 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(number)\n";
2074 }
2075 } elsif ($name =~ /^(?:log|power)$/) {
2076 0 my $func = uc($name);
2077 0 ▶ if ($args and @$args==1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args and @$args == 1) { } 0 0 0
elsif ($args and @$args == 2) { } 0 0 0
Condition0%0/3
$args and @$args == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 1
$args @$args == 1
Truth table0%0/3
A and B
A= $argsB= @$args == 1
ABresult
0X0
100
111
2078 0 return $func.'(10,CAST('
2079 . $self->serialize_expression_pt($args->[0],$opts,$extra_joins)
2080 . ' AS FLOAT))';
2081 ▶ } elsif ($args and @$args==2) {
Condition0%0/3
$args and @$args == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 2
$args @$args == 2
Truth table0%0/3
A and B
A= $argsB= @$args == 2
ABresult
0X0
100
111
2082 0 return $func.'('
2083 . $self->serialize_expression_pt($args->[0],$opts,$extra_joins).','
2084 . 'CAST('.$self->serialize_expression_pt($args->[1],$opts,$extra_joins).' AS FLOAT)'
2085 . ')';
2086 } else {
2087 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(base,number) or ${name}(number)\n";
2088 }
2089 } elsif ($name eq 'address') {
2090 0 my @arg;
2091 0 ▶ if ($args and @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args) 0 0 0
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2092 0 my $ref = $args->[0];
2093 0 ▶ die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$args > 1 or not $ref =~ /^\$(?!\d)/ 0 0 0
Condition0%0/3
@$args > 1 or not $ref =~ /^\$(?!\d)/
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args > 1 or not $ref =~ /^\$(?!\d)/
@$args > 1 not $ref =~ /^\$(?!\d)/
Truth table0%0/3
A or not(B)
A= @$args > 1B= not $ref =~ /^\$(?!\d)/
ABresult
1X1
011
000
2094 if (@$args>1 or $ref!~/^\$(?!\d)/);
2095 0 @arg = ($ref);
2096 }
2097 0 return $self->serialize_expression_pt(
2098 ['EXP' =>
2099 [FUNC => 'file', [@arg]],
2100 '&', "'##'", '&',
2101 [FUNC => 'tree_no', [@arg]],
2102 '&', "'.'", '&',
2103 [FUNC => 'depth_first_order', [@arg]],
2104 ],$opts,$extra_joins);
2105 } elsif ($name =~ /^(file|tree_no)$/) {
2106 0 my $id;
2107 0 ▶ if ($args and @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args) { } 0 0 0
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2108 0 my $ref = $args->[0];
2109 0 ▶ die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$args > 1 or not $ref =~ s/^\$(?!\d)// 0 0 0
Condition0%0/3
@$args > 1 or not $ref =~ s/^\$(?!\d)//
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args > 1 or not $ref =~ s/^\$(?!\d)//
@$args > 1 not $ref =~ s/^\$(?!\d)//
Truth table0%0/3
A or not(B)
A= @$args > 1B= not $ref =~ s/^\$(?!\d)//
ABresult
1X1
011
000
2110 if (@$args>1 or not $ref=~s/^\$(?!\d)//);
2111 0 ▶ $id= $ref eq '$' ? $this_node_id : $ref;
Branch: 1 branch
BranchTrueFalseTotal
$ref eq '$' ? : 0 0 0
2112 } else {
2113 0 $id = $this_node_id;
2114 }
2115 0 my $n = $self->{name2node}{$id};
2116 0 my $cmp = $self->cmp_subquery_scope($this_node_id,$id);
2117 0 ▶ if (!$n or $cmp<0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $n or $cmp < 0) 0 0 0
Condition0%0/3
not $n or $cmp < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not $n or $cmp < 0
not $n $cmp < 0
Truth table0%0/3
not(A) or B
A= not $nB= $cmp < 0
ABresult
1X1
011
000
2118 0 die "Node '$id' belongs to a sub-query and cannot be referred from the scope of node '$this_node_id' ($opts->{expression})\n";
2119 }
2120 0 ▶ $opts->{referred_nodes}{$id}=1 if ref($opts->{referred_nodes});
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts->{"referred_nodes"} 0 0 0
2121 0 my $j = $opts->{join};
2122 0 $j = $j->{'..'} for 1..$cmp;
2123 0 ▶ my $J = ($j->{$id}||=[]); #($extra_joins->{$id}||=[]);
Condition0%0/2
$j->{$id} ||= []
l!l
00
MC/DC0%0/1
$j->{$id} ||= []
$j->{$id}
Truth table0%0/2
A
A= $j->{$id}
Aresult
11
00
2124 0 my $table = $self->get_schema_name_for(PMLTQ::Common::GetQueryNodeType($n,$self)).'__#files';
2125 0 my $fid = $id."/#file";
2126 0 ▶ push @$J,[$fid,$table, qq("$fid"."#idx" = "$id"."#root_idx")] unless first { $_->[0] eq $fid } @$J;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $_->[0] eq $fid; } , @$J) 0 0 0
2127 0 ▶ return $name eq 'tree_no' ? qq{("$fid"."$name"+1)} : qq{"$fid"."$name"};
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'tree_no' ? : 0 0 0
2128 } elsif ($name eq 'rbrothers') {
2129 0 my $id;
2130 0 ▶ if ($args and @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args) { } 0 0 0
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2131 0 my $ref = $args->[0];
2132 0 ▶ die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$args > 1 or not $ref =~ s/^\$(?!\d)// 0 0 0
Condition0%0/3
@$args > 1 or not $ref =~ s/^\$(?!\d)//
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args > 1 or not $ref =~ s/^\$(?!\d)//
@$args > 1 not $ref =~ s/^\$(?!\d)//
Truth table0%0/3
A or not(B)
A= @$args > 1B= not $ref =~ s/^\$(?!\d)//
ABresult
1X1
011
000
2133 if (@$args>1 or not $ref=~s/^\$(?!\d)//);
2134 0 ▶ $id= $ref eq '$' ? $this_node_id : $ref;
Branch: 1 branch
BranchTrueFalseTotal
$ref eq '$' ? : 0 0 0
2135 } else {
2136 0 $id = $this_node_id;
2137 }
2138 0 my $n = $self->{name2node}{$id};
2139 0 my $cmp = $self->cmp_subquery_scope($this_node_id,$id);
2140 0 ▶ if (!$n or $cmp<0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $n or $cmp < 0) 0 0 0
Condition0%0/3
not $n or $cmp < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not $n or $cmp < 0
not $n $cmp < 0
Truth table0%0/3
not(A) or B
A= not $nB= $cmp < 0
ABresult
1X1
011
000
2141 0 die "Node '$id' belongs to a sub-query and cannot be referred from the scope of node '$this_node_id' ($opts->{expression})\n";
2142 }
2143 0 ▶ $opts->{referred_nodes}{$id}=1 if ref($opts->{referred_nodes});
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts->{"referred_nodes"} 0 0 0
2144 0 my $j = $opts->{join};
2145 0 $j = $j->{'..'} for 1..$cmp;
2146 0 ▶ my $J = ($j->{$id}||=[]); #($extra_joins->{$id}||=[]);
Condition0%0/2
$j->{$id} ||= []
l!l
00
MC/DC0%0/1
$j->{$id} ||= []
$j->{$id}
Truth table0%0/2
A
A= $j->{$id}
Aresult
11
00
2147 0 my $table = $self->get_schema_name_for(PMLTQ::Common::GetQueryNodeType($n,$self)).'__#trees';
2148 0 my $p_id = $id."/#parent";
2149 0 ▶ push @$J,[$p_id,$table, qq("$p_id"."#idx" = "$id"."#parent_idx")] unless first { $_->[0] eq $p_id } @$J;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless &first(sub { $_->[0] eq $p_id; } , @$J) 0 0 0
2150 0 return qq{("$p_id"."#chld"-"$id"."#chord"-1)};
2151 } elsif ($name eq 'id') {
2152 0 my $id;
2153 0 ▶ if ($args and @$args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args) { } 0 0 0
Condition0%0/3
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args
$args @$args
Truth table0%0/3
A and B
A= $argsB= @$args
ABresult
0X0
100
111
2154 0 my $ref = $args->[0];
2155 0 ▶ die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(\$node?)\n"
Branch: 1 branch
BranchTrueFalseTotal
if @$args > 1 or not $ref =~ s/^\$(?!\d)// 0 0 0
Condition0%0/3
@$args > 1 or not $ref =~ s/^\$(?!\d)//
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args > 1 or not $ref =~ s/^\$(?!\d)//
@$args > 1 not $ref =~ s/^\$(?!\d)//
Truth table0%0/3
A or not(B)
A= @$args > 1B= not $ref =~ s/^\$(?!\d)//
ABresult
1X1
011
000
2156 if (@$args>1 or not $ref=~s/^\$(?!\d)//);
2157 0 ▶ $id= $ref eq '$' ? $this_node_id : $ref;
Branch: 1 branch
BranchTrueFalseTotal
$ref eq '$' ? : 0 0 0
2158 } else {
2159 0 $id = $this_node_id;
2160 }
2161 0 my $n = $self->{name2node}{$id};
2162 0 ▶ $n or die "Cannot refer to node '$id' from $name() in expression $opts->{expression} of node '$this_node_id'!\n";
Branch: 1 branch
BranchTrueFalseTotal
$n or die qq[Cannot refer to node '${id}' from $name() in expression $opts->{"expression"} of node '${this_node_id}'!\n] 0 0 0
2163 0 ▶ $opts->{referred_nodes}{$id}=1 if ref($opts->{referred_nodes});
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts->{"referred_nodes"} 0 0 0
2164 0 my $decl = $self->get_decl_for(PMLTQ::Common::GetQueryNodeType($n,$self));
2165 0 ▶ if ($decl->get_decl_type == PML_ELEMENT_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl->get_decl_type == 13) 0 0 0
2166 0 $decl = $decl->get_content_decl;
2167 }
2168 0 my ($m)=$decl->find_members_by_role('#ID');
2169 0 ▶ my $id_attr = defined($m) && $m->get_name;
Condition0%0/3
defined $m && $m->get_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $m && $m->get_name
defined $m $m->get_name
Truth table0%0/3
A && B
A= defined $mB= $m->get_name
ABresult
0X0
100
111
2170 0 ▶ if (defined $id_attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id_attr) { } 0 0 0
2171 0 return $self->serialize_expression_pt(['REF_ATTR',$id,[$id_attr]],$opts,$extra_joins);
2172 } else {
2173 0 return 'NULL';
2174 }
2175 } elsif ($name=~/^(?:round|trunc)$/) {
2176 0 ▶ if ($args and @$args and @$args<3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args and @$args < 3) { } 0 0 0
Condition0%0/6
$args and @$args and @$args < 3
!ll&&!rl&&r
000
$args and @$args
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args and @$args < 3
$args @$args @$args < 3
Truth table0%0/4
A and B and C
A= $argsB= @$argsC= @$args < 3
ABCresult
0XX0
10X0
1100
1111
2177 return uc($name).'('
2178 0 . join(',',map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$args)
2179 . ')';
2180 } else {
2181 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: ${name}(string)\n";
2182 }
2183 } elsif ($name eq 'percnt') {
2184 0 ▶ if ($args and @$args>0 and @$args<3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args > 0 and @$args < 3) { } 0 0 0
Condition0%0/6
$args and @$args > 0 and @$args < 3
!ll&&!rl&&r
000
$args and @$args > 0
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args > 0 and @$args < 3
$args @$args > 0 @$args < 3
Truth table0%0/4
A and B and C
A= $argsB= @$args > 0C= @$args < 3
ABCresult
0XX0
10X0
1100
1111
2185 0 my @args = map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$args;
2186 0 ▶ my $ret = 'round(100*('.$args[0].')'
Branch: 1 branch
BranchTrueFalseTotal
@args > 1 ? : 0 0 0
2187 . (@args>1 ? ','.$args[1] : '').q[)];
2188 0 return $ret;
2189 } else {
2190 0 die "Wrong arguments for function percnt() in expression $opts->{expression} of node '$this_node_id'!\nUsage: percnt(number,precision?)\n";
2191 }
2192 } elsif ($name eq 'substr') {
2193 0 ▶ if ($args and @$args>1 and @$args<4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args > 1 and @$args < 4) { } 0 0 0
Condition0%0/6
$args and @$args > 1 and @$args < 4
!ll&&!rl&&r
000
$args and @$args > 1
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args > 1 and @$args < 4
$args @$args > 1 @$args < 4
Truth table0%0/4
A and B and C
A= $argsB= @$args > 1C= @$args < 4
ABCresult
0XX0
10X0
1100
1111
2194 0 my $cast_to_string;
2195 0 ▶ if ($self->compute_data_type($args->[0],$opts)!=COL_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->compute_data_type($args->[0], $opts) != 1) 0 0 0
2196 0 $cast_to_string=1;
2197 }
2198 0 my @args = map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$args;
2199 0 $args[1].='+1';
2200 0 ▶ $args[0]='cast('.$args[0].' as varchar)' if $cast_to_string;
Branch: 1 branch
BranchTrueFalseTotal
if $cast_to_string 0 0 0
2201 0 return 'SUBSTR('. join(',', @args) . ')';
2202 } else {
2203 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: substr(string,from,length?)\n";
2204 }
2205 } elsif ($name=~/(?:replace|tr)$/) {
2206 0 ▶ if ($args and @$args==3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args == 3) { } 0 0 0
Condition0%0/3
$args and @$args == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$args and @$args == 3
$args @$args == 3
Truth table0%0/3
A and B
A= $argsB= @$args == 3
ABresult
0X0
100
111
2207 0 my $cast_to_string;
2208 0 ▶ if ($self->compute_data_type($args->[0],$opts)!=COL_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->compute_data_type($args->[0], $opts) != 1) 0 0 0
2209 0 $cast_to_string=1;
2210 }
2211 0 my @args = map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$args;
2212 0 ▶ $args[0]='cast('.$args[0].' as varchar)' if $cast_to_string;
Branch: 1 branch
BranchTrueFalseTotal
if $cast_to_string 0 0 0
2213 0 ▶ return ($name eq 'tr' ? 'TRANSLATE' : uc($name) ).'('
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'tr' ? : 0 0 0
2214 . join(',', @args)
2215 . ')';
2216 } else {
2217 0 ▶ die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name".
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'replace' ? : 0 0 0
2218 ($name eq 'replace' ? "(string,target,replacement)\n"
2219 : "(string,from_chars,to_chars)\n");
2220 }
2221 } elsif ($name eq 'substitute') {
2222 0 ▶ if ($args and @$args>=3 and @$args<=4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args >= 3 and @$args <= 4) { } 0 0 0
Condition0%0/6
$args and @$args >= 3 and @$args <= 4
!ll&&!rl&&r
000
$args and @$args >= 3
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args >= 3 and @$args <= 4
$args @$args >= 3 @$args <= 4
Truth table0%0/4
A and B and C
A= $argsB= @$args >= 3C= @$args <= 4
ABCresult
0XX0
10X0
1100
1111
2223 0 my @cast_to_string;
2224 0 for (0..2) {
2225 0 ▶ $cast_to_string[$_]= ($self->compute_data_type($args->[$_],$opts)!=COL_STRING) ? 1 : 0 if $_<@$args;
Branch: 2 branches
BranchTrueFalseTotal
if $_ < @$args 0 0 0
$self->compute_data_type($args->[$_], $opts) != 1 ? : 0 0 0
2226 }
2227 0 my @args = map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$args;
2228 0 for (0..2) {
2229 0 ▶ $args[$_]='cast('.$args[$_].' as varchar)' if ($_<@$args and $cast_to_string[$_]);
Branch: 1 branch
BranchTrueFalseTotal
if $_ < @$args and $cast_to_string[$_] 0 0 0
Condition0%0/3
$_ < @$args and $cast_to_string[$_]
!ll&&!rl&&r
000
MC/DC0%0/2
$_ < @$args and $cast_to_string[$_]
$_ < @$args $cast_to_string[$_]
Truth table0%0/3
A and B
A= $_ < @$argsB= $cast_to_string[$_]
ABresult
0X0
100
111
2230 }
2231 0 my $match_opts = $args[3];
2232 0 ▶ if (defined($match_opts) and (ref($match_opts) or $match_opts!~/^\s*'[icnmg]*'\s*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnmg]*'\s*$/)) 0 0 0
Condition0%0/6
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnmg]*'\s*$/)
!ll&&!rl&&r
000
ref $match_opts or not $match_opts =~ /^\s*'[icnmg]*'\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnmg]*'\s*$/)
defined $match_opts ref $match_opts not $match_opts =~ /^\s*'[icnmg]*'\s*$/
Truth table0%0/4
A and B or not(C)
A= defined $match_optsB= ref $match_optsC= not $match_opts =~ /^\s*'[icnmg]*'\s*$/
ABCresult
0XX0
1000
11X1
1011
2233 0 die "Wrong match options $match_opts for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,pattern,replacement,options), where options is a literal string consisting only of characters from the set [icnmg]\n";
2234 }
2235 0 ▶ return 'REGEXP_REPLACE('.join(',', @args[0..2],$match_opts ? $match_opts : ()).')'
Branch: 1 branch
BranchTrueFalseTotal
$match_opts ? : 0 0 0
2236 } else {
2237 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,pattern,replacement,options)\n";
2238 }
2239 } elsif ($name eq 'match') {
2240 0 ▶ if ($args and @$args>=2 and @$args<=3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args and @$args >= 2 and @$args <= 3) { } 0 0 0
Condition0%0/6
$args and @$args >= 2 and @$args <= 3
!ll&&!rl&&r
000
$args and @$args >= 2
!ll&&!rl&&r
000
MC/DC0%0/3
$args and @$args >= 2 and @$args <= 3
$args @$args >= 2 @$args <= 3
Truth table0%0/4
A and B and C
A= $argsB= @$args >= 2C= @$args <= 3
ABCresult
0XX0
10X0
1100
1111
2241 0 my @cast_to_string;
2242 0 for (0..1) {
2243 0 ▶ $cast_to_string[$_]= ($self->compute_data_type($args->[$_],$opts)!=COL_STRING) ? 1 : 0 if $_<@$args;
Branch: 2 branches
BranchTrueFalseTotal
if $_ < @$args 0 0 0
$self->compute_data_type($args->[$_], $opts) != 1 ? : 0 0 0
2244 }
2245 0 my @args = map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$args;
2246 0 for (0..1) {
2247 0 ▶ $args[$_]='cast('.$args[$_].' as varchar)' if ($_<@$args and $cast_to_string[$_]);
Branch: 1 branch
BranchTrueFalseTotal
if $_ < @$args and $cast_to_string[$_] 0 0 0
Condition0%0/3
$_ < @$args and $cast_to_string[$_]
!ll&&!rl&&r
000
MC/DC0%0/2
$_ < @$args and $cast_to_string[$_]
$_ < @$args $cast_to_string[$_]
Truth table0%0/3
A and B
A= $_ < @$argsB= $cast_to_string[$_]
ABresult
0X0
100
111
2248 }
2249 0 my $match_opts = $args[2];
2250 0 ▶ if (defined($match_opts) and (ref($match_opts) or $match_opts!~/^\s*'[icnm]*'\s*$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnm]*'\s*$/)) 0 0 0
Condition0%0/6
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnm]*'\s*$/)
!ll&&!rl&&r
000
ref $match_opts or not $match_opts =~ /^\s*'[icnm]*'\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $match_opts and ref $match_opts || !($match_opts =~ /^\s*'[icnm]*'\s*$/)
defined $match_opts ref $match_opts not $match_opts =~ /^\s*'[icnm]*'\s*$/
Truth table0%0/4
A and B or not(C)
A= defined $match_optsB= ref $match_optsC= not $match_opts =~ /^\s*'[icnm]*'\s*$/
ABCresult
0XX0
1000
11X1
1011
2251 0 die "Wrong match options [$match_opts] for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,pattern,options?), where options is a literal string consisting only of characters from the set [icnm]\n";
2252 }
2253 0 ▶ return '(REGEXP_MATCHES('.qq{$args[0],'(' || $args[1] || ')',}
Condition0%0/2
$match_opts || q['']
l!l
00
MC/DC0%0/1
$match_opts || q['']
$match_opts
Truth table0%0/2
A
A= $match_opts
Aresult
11
00
2254 .($match_opts || q(''))
2255 .'))[1]'
2256  
2257 } else {
2258 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(string,pattern,options?)\n";
2259 }
2260 } elsif ($name eq 'first_defined') {
2261 0 ▶ if (!$args or @$args<2) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $args or @$args < 2) 0 0 0
Condition0%0/3
not $args or @$args < 2
l!l&&r!l&&!r
000
MC/DC0%0/2
not $args or @$args < 2
not $args @$args < 2
Truth table0%0/3
not(A) or B
A= not $argsB= @$args < 2
ABresult
1X1
011
000
2262 0 die "Wrong arguments for function ${name}() in expression $opts->{expression} of node '$this_node_id'!\nUsage: $name(value1,value2,...)\n";
2263 }
2264 0 my @types = map { $self->compute_data_type($_,$opts) } @$args;
2265 0 my @args = map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$args;
2266 0 ▶ if (first { $_ !=COL_NUMERIC } @types) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&first(sub { $_ != 2; } , @types)) 0 0 0
2267 0 for (@args) {
2268 0 ▶ if ( shift(@types)!=COL_STRING ) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift @types != 1) 0 0 0
2269 0 $_=qq{cast($_ as varchar)} ;
2270 }
2271 }
2272 }
2273 0 return 'COALESCE('.join(',', @args).')'
2274 } else {
2275 0 die "Function ${name}() unknown or not yet implemented!\n";
2276 }
2277 } elsif ($type eq 'EVERY') {
2278 0 $opts->{use_exists}=2;
2279 0 $opts->{is_positive_conjunct}=0;
2280 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"output_filter"}) 0 0 0
2281 0 die "Cannot use quantifier '*' in output filter: '$opts->{expression}'"
2282 }
2283 0 return $self->serialize_expression_pt($pt->[0],$opts,$extra_joins);
2284 } elsif ($type eq 'IF') {
2285 0 my ($condition,$if_true,$if_false) = @$pt;
2286 my $test = PMLTQ::Common::make_string([$self->serialize_element({
2287 0 name => $condition->{'#name'},
2288 condition => $condition,
2289 is_positive_conjunct => 1,
2290 %$opts,
2291 })]);
2292 0 my ($true_type,$false_type) = map $self->compute_data_type($_,$opts), ($if_true, $if_false);
2293 0 my ($if_true_sql,$if_false_sql) = map { $self->serialize_expression_pt($_,$opts,$extra_joins) }
2294 ($if_true,$if_false);
2295 0 ▶ if ($true_type != $false_type or $true_type == COL_UNKNOWN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($true_type != $false_type or $true_type == 0) 0 0 0
Condition0%0/3
$true_type != $false_type or $true_type == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$true_type != $false_type or $true_type == 0
$true_type != $false_type $true_type == 0
Truth table0%0/3
A or B
A= $true_type != $false_typeB= $true_type == 0
ABresult
1X1
011
000
2296 0 $_=qq{cast($_ as varchar)} for ($if_true_sql, $if_false_sql);
2297 }
2298 0 return qq{(CASE WHEN $test THEN $if_true_sql ELSE $if_false_sql END)};
2299 } elsif ($type eq 'ANALYTIC_FUNC') {
2300 0 my $name = shift @$pt;
2301 die "The analytic function ${name}() can only be used in an output filter expression!\n"
2302 0 ▶ unless $opts->{'output_filter'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"output_filter"} 0 0 0
2303 die "The analytic function ${name}() cannot be used in the 'filter' clause!\n"
2304 0 ▶ if $opts->{'output_filter_where_clause'};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"output_filter_where_clause"} 0 0 0
2305 0 my $args = shift @$pt;
2306 die "The analytic function $name without an 'over' clause cannot be used to compute an argument to another analytic function without an 'over' clause $opts->{aggregated} in the output filter expression $opts->{expression}!\n"
2307 if defined($opts->{'aggregated'})
2308 and !@$pt #over
2309 0 ▶ and !($opts->{group_by} and @{$opts->{group_by}});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"aggregated"} and not @$pt and not $opts->{"group_by"} && @{$opts->{"group_by"};} 0 0 0
Condition0%0/9
defined $opts->{"aggregated"} and not @$pt and not $opts->{"group_by"} && @{$opts->{"group_by"};}
!ll&&!rl&&r
000
defined $opts->{"aggregated"} and not @$pt
!ll&&!rl&&r
000
$opts->{'group_by'} && @{$opts->{'group_by'};}
!ll&&!rl&&r
000
MC/DC0%0/4
defined $opts->{"aggregated"} and not @$pt and not $opts->{"group_by"} && @{$opts->{"group_by"};}
defined $opts->{"aggregated"} not @$pt $opts->{'group_by'} @{$opts->{'group_by'};}
Truth table0%0/5
A and not(B) and not(C && D)
A= defined $opts->{"aggregated"}B= not @$ptC= $opts->{'group_by'}D= @{$opts->{'group_by'};}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
2310 0 ▶ $name = 'ratio_to_report' if $name eq 'ratio';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "ratio" 0 0 0
2311 0 my @args;
2312 0 ▶ if ($args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args) 0 0 0
2313 0 ▶ if ($name eq 'concat') {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'concat') { } 0 0 0
elsif ($name =~ /^(rank|dense_rank|row_number)/ and @$args > 0) { } 0 0 0
elsif (@$args > 1) { } 0 0 0
2314 0 ▶ die "The analytic function $name takes one or two arguments concat(STR, SEPARATOR?) in the output filter expression $opts->{expression}; got @$args!\n" if @$args==0 or @$args>2;
Branch: 1 branch
BranchTrueFalseTotal
if @$args == 0 or @$args > 2 0 0 0
Condition0%0/3
@$args == 0 or @$args > 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@$args == 0 or @$args > 2
@$args == 0 @$args > 2
Truth table0%0/3
A or B
A= @$args == 0B= @$args > 2
ABresult
1X1
011
000
2315 0 ▶ if (@$args==2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args == 2) 0 0 0
2316 0 ▶ unless (defined($args->[1]) and !ref($args->[1]) and $args->[1]!~/^\$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->[1] and not ref $args->[1] and not $args->[1] =~ /^\$/) 0 0 0
Condition0%0/6
defined $args->[1] and not ref $args->[1] and not $args->[1] =~ /^\$/
!ll&&!rl&&r
000
defined $args->[1] and not ref $args->[1]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $args->[1] and not ref $args->[1] and not $args->[1] =~ /^\$/
defined $args->[1] not ref $args->[1] not $args->[1] =~ /^\$/
Truth table0%0/4
A and not(B) and not(C)
A= defined $args->[1]B= not ref $args->[1]C= not $args->[1] =~ /^\$/
ABCresult
0XX0
10X0
1100
1111
2317 0 die "The second argument to concat(STR, SEPARATOR?) must be a literal string or number in $opts->{expression}!\n";
2318 }
2319 }
2320 ▶ } elsif ($name =~ /^(rank|dense_rank|row_number)/ and @$args>0) {
Condition0%0/3
$name =~ /^(rank|dense_rank|row_number)/ and @$args > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$name =~ /^(rank|dense_rank|row_number)/ and @$args > 0
$name =~ /^(rank|dense_rank|row_number)/ @$args > 0
Truth table0%0/3
A and B
A= $name =~ /^(rank|dense_rank|row_number)/B= @$args > 0
ABresult
0X0
100
111
2321 0 die "The analytic function $name takes no arguments in the output filter expression $opts->{expression}!\n";
2322 } elsif (@$args>1) {
2323 0 die "The analytic function $name takes at most one arguments in the output filter expression $opts->{expression}!\n";
2324 }
2325 0 for my $arg (@$args) {
2326 0 ▶ push @args, $self->serialize_expression_pt($arg,{%$opts,
Branch: 1 branch
BranchTrueFalseTotal
@$pt ? : 0 0 0
2327 (@$pt ? () : (aggregated=>$name, group_by=>undef))
2328 },$extra_joins)
2329 }
2330 }
2331 0 my $out='';
2332 0 ▶ if ($name eq 'concat') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'concat') { } 0 0 0
elsif ($name eq 'ratio_to_report') { } 0 0 0
2333 0 $out=q{concat_agg(};
2334 0 ▶ if (@args==1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@args == 1) { } 0 0 0
elsif (@args == 2) { } 0 0 0
2335 0 $out.=$args[0];
2336 } elsif (@args==2) {
2337 0 my $sep = $args[1];
2338 0 $out=q{regexp_replace(}.$out.$args[0].' || '.$sep;
2339 }
2340 } elsif ($name eq 'ratio_to_report') {
2341 0 ▶ my $arg = @args ? $args[0] : 'count(*)';
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 0 0
2342 0 $out='(('.$arg.') / sum('.$arg;
2343 } else {
2344 0 ▶ $out=uc($name).'('.(@args ? $args[0] : '');
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 0 0
2345 }
2346 0 ▶ unless (@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 0 0
2347 0 ▶ if ($name eq 'count') {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'count') { } 0 0 0
elsif ($name eq 'ratio_to_report') { } 0 0 0
elsif (not $name =~ /^(rank|dense_rank|row_number)/) { } 0 0 0
2348 0 $out.='*'
2349 } elsif ($name eq 'ratio_to_report') {
2350 0 $out.='count(*)'
2351 } elsif ($name !~ /^(rank|dense_rank|row_number)/) {
2352 0 ▶ if ($opts->{group_by} and @{$opts->{group_by}}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'group_by'} and @{$opts->{'group_by'};}) { } 0 0 0
elsif ($opts->{'output_filter'} < 2) { } 0 0 0
Condition0%0/3
$opts->{"group_by"} and @{$opts->{"group_by"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"group_by"} and @{$opts->{"group_by"};}
$opts->{"group_by"} @{$opts->{"group_by"};}
Truth table0%0/3
A and B
A= $opts->{"group_by"}B= @{$opts->{"group_by"};}
ABresult
0X0
100
111
2353 0 $out .= $opts->{group_by}[0];
2354 } elsif ($opts->{'output_filter'}<2) {
2355 0 die "Cannot use analytic function ${name}() with implicit argument (\$1) in the first filter!\n";
2356 } else {
2357 0 $out .= 'c'.($opts->{'output_filter'}-1).'_1';
2358 }
2359 }
2360 }
2361 0 $out.=')';
2362 0 my ($over,$sort)=@$pt;
2363 0 ▶ if (($over and @$over) or ($sort and @$sort) or $name =~ /^(rank|dense_rank|row_number)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($over and @$over or $sort and @$sort or $name =~ /^(rank|dense_rank|row_number)/) 0 0 0
Condition0%0/12
$over and @$over or $sort and @$sort or $name =~ /^(rank|dense_rank|row_number)/
l!l&&r!l&&!r
000
$over and @$over or $sort and @$sort
l!l&&r!l&&!r
000
$over and @$over
!ll&&!rl&&r
000
$sort and @$sort
!ll&&!rl&&r
000
MC/DC0%0/5
$over and @$over or $sort and @$sort or $name =~ /^(rank|dense_rank|row_number)/
$over @$over $sort @$sort $name =~ /^(rank|dense_rank|row_number)/
Truth table0%0/11
A and B or C and D or E
A= $overB= @$overC= $sortD= @$sortE= $name =~ /^(rank|dense_rank|row_number)/
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
2364 0 $out.= ' OVER (';
2365 0 ▶ if ($over and @$over and !(@$over==1 and $over->[0] eq 'ALL')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($over and @$over and not @$over == 1 && $over->[0] eq "ALL") 0 0 0
Condition0%0/9
$over and @$over and not @$over == 1 && $over->[0] eq "ALL"
!ll&&!rl&&r
000
$over and @$over
!ll&&!rl&&r
000
@$over == 1 && $over->[0] eq 'ALL'
!ll&&!rl&&r
000
MC/DC0%0/4
$over and @$over and not @$over == 1 && $over->[0] eq "ALL"
$over @$over @$over == 1 $over->[0] eq 'ALL'
Truth table0%0/5
A and B and not(C && D)
A= $overB= @$overC= @$over == 1D= $over->[0] eq 'ALL'
ABCDresult
0XXX0
10XX0
11110
110X1
11101
2366 0 $out.= 'PARTITION BY '.join(',',map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$over)
2367 }
2368 0 ▶ if ($sort and @$sort) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sort and @$sort) 0 0 0
Condition0%0/3
$sort and @$sort
!ll&&!rl&&r
000
MC/DC0%0/2
$sort and @$sort
$sort @$sort
Truth table0%0/3
A and B
A= $sortB= @$sort
ABresult
0X0
100
111
2369 0 ▶ $out.=' ORDER BY '.join(',',map { $self->serialize_expression_pt($_->[0],$opts,$extra_joins).
Branch: 1 branch
BranchTrueFalseTotal
$_->[1] ? : 0 0 0
2370 ($_->[1] ? ' '.uc($_->[1]) : '')
2371 } @$sort);
2372 0 ▶ if ($name !~ /^(rank|dense_rank|row_number)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /^(rank|dense_rank|row_number)/) 0 0 0
2373 0 $out.=' RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING'
2374 }
2375 }
2376 0 $out.=')';
2377 }
2378 0 ▶ if ($name eq 'concat') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "concat") 0 0 0
2379 0 ▶ if (@args==2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 2) 0 0 0
2380 #
2381 # we now quote 2nd argument so that we can use it as a regexp
2382 # that matches the trailing separator
2383 # e.g. SQL ''' | ''' (that is q{' | '}) becomes '\'' \| \''$'
2384 # (that is q{\' \| \'$})
2385 #
2386 0 my $trim_separator = $args[1];
2387 0 ▶ if ($trim_separator =~ /^(\s*E?)(['])(.*?)([']\s*)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($trim_separator =~ /^(\s*E?)(['])(.*?)([']\s*)$/) { } 0 0 0
elsif ($trim_separator =~ /^(\s*[NU]?['])(.*?)([']\s*)$/) { } 0 0 0
2388 0 my ($lead,$lead2,$body,$trail)=($1,$2,$3,$4);
2389 0 $body=~s/\\(.)/$1/g; # unquote '
2390 0 $body=quotemeta($body); # quote meta characters
2391 0 $body=~s/\\/\\\\/g; # quote \\ and '
2392 0 $body=~s/'/\\'/g; # quote '
2393 0 ▶ $lead =~s/$/E/ if $lead!~/E/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lead =~ /E/ 0 0 0
2394 0 $trim_separator = $lead.$lead2.$body.'$'.$trail;
2395 } elsif ($trim_separator =~ /^(\s*[NU]?['])(.*?)([']\s*)$/) {
2396 0 my ($lead,$body,$trail)=($1,$2,$3);
2397 0 $body=~s/''/'/g; # unquote '
2398 0 $body=quotemeta($body); # quote meta characters
2399 0 $body=~s/'/''/g; # quote '
2400 0 $trim_separator = $lead.$body.'$'.$trail;
2401 }
2402 0 $out.=qq{,$trim_separator,'')};
2403 }
2404 }
2405 0 return $out;
2406 } elsif ($type eq 'EXP') {
2407 0 my $out='';
2408 0 my $mult='';
2409 0 ▶ $mult = $self->serialize_expression_pt(shift @$pt,$opts,$extra_joins) if @$pt;
Branch: 1 branch
BranchTrueFalseTotal
if @$pt 0 0 0
2410 0 ▶ while (@$pt) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$pt) 0 0 0
2411 0 my $op = shift @$pt;
2412 0 ▶ die "Missing left expression for operator '$op' in expression $opts->{expression} of node '$this_node_id'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @$pt 0 0 0
2413 unless @$pt;
2414 0 my $exp = $self->serialize_expression_pt(shift @$pt,$opts,$extra_joins);
2415 # a+b*c%2+d/2*2+f
2416 # a+ => a+(b) => a+(b*c) => a+mod(b*c,2) => a+mod(b*c,2)+
2417 0 ▶ if ($op eq 'div') {
Branch: 5 branches
BranchTrueFalseTotal
if ($op eq 'div') { } 0 0 0
elsif ($op eq 'mod') { } 0 0 0
elsif ($op eq '*') { } 0 0 0
elsif ($op eq '&') { } 0 0 0
elsif ($op =~ /^[-+]$/) { } 0 0 0
2418 0 $mult=qq{($mult / $exp)};
2419 } elsif ($op eq 'mod') {
2420 0 $mult=qq{MOD($mult,$exp)};
2421 } elsif ($op eq '*') {
2422 0 $mult=qq{($mult * $exp)};
2423 } elsif ($op eq '&') {
2424 0 $out.=qq{$mult || };
2425 0 $mult = $exp;
2426 } elsif ($op =~ /^[-+]$/) {
2427 0 $out.=qq{$mult $op };
2428 0 $mult = $exp;
2429 } else {
2430 0 die "Urecognized operator '$op' in expression $opts->{expression} of node '$this_node_id'\n";
2431 }
2432 }
2433 0 return qq{($out$mult)}
2434 } elsif ($type eq 'SET') {
2435 my $res= '('
2436 0 . join(',', map { $self->serialize_expression_pt($_,$opts,$extra_joins) } @$pt)
2437 . ')';
2438 0 $opts->{can_be_null}=0;
2439 0 return $res;
2440 } else {
2441 0 die "Internal error: unrecognized parse tree item $type\n";
2442 }
2443 } else {
2444 0 ▶ if ($pt=~/^[-0-9]/) { # literal number
Branch: 3 branches
BranchTrueFalseTotal
if ($pt =~ /^[-0-9]/) { } 0 0 0
elsif ($pt =~ s/^(['"])(.*)\1$/$2/s) { } 0 0 0
elsif ($pt =~ s/^\$//) { } 0 0 0
2445 0 return qq( $pt );
2446 } elsif ($pt=~s/^(['"])(.*)\1$/$2/s) { # literal string
2447 0 $pt=~s/\\(.)/$1/sg;
2448 0 ▶ $opts->{can_be_null}=1 if !length $pt;
Branch: 1 branch
BranchTrueFalseTotal
unless length $pt 0 0 0
2449 0 ▶ if ($pt=~m/\\/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pt =~ /\\/) { } 0 0 0
2450 0 $pt=~s/'/\\'/sg;
2451 0 $pt=~s{\\}{\\\\}g;
2452 0 qq( E'$pt' );
2453 } else {
2454 0 $pt=~s/'/''/sg;
2455 0 qq( '$pt' );
2456 }
2457 } elsif ($pt=~s/^\$//) { # a plain variable
2458 0 ▶ if ($pt =~ /^\d+$/) { #column reference
Branch: 1 branch
BranchTrueFalseTotal
if ($pt =~ /^\d+$/) 0 0 0
2459  
2460 die "Column reference \$$pt can only be used in an output filter; error in expression '$opts->{expression}' of node '$this_node_id'\n"
2461 0 ▶ unless $opts->{'output_filter'};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"output_filter"} 0 0 0
2462 0 my $col;
2463 # print STDERR "$opts->{'output_filter'}: \$$pt, aggregated=$opts->{aggregated}, group by (@{$opts->{group_by}||[]}), prev_columns: (@{$opts->{prev_columns}||[]})\n";
2464 0 ▶ if (!$opts->{output_filter_where_clause} and $opts->{group_by} and @{$opts->{group_by}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{'output_filter_where_clause'} and $opts->{'group_by'} and @{$opts->{'group_by'};}) { } 0 0 0
Condition0%0/6
not $opts->{"output_filter_where_clause"} and $opts->{"group_by"} and @{$opts->{"group_by"};}
!ll&&!rl&&r
000
not $opts->{"output_filter_where_clause"} and $opts->{"group_by"}
!ll&&!rl&&r
000
MC/DC0%0/3
not $opts->{"output_filter_where_clause"} and $opts->{"group_by"} and @{$opts->{"group_by"};}
not $opts->{"output_filter_where_clause"} $opts->{"group_by"} @{$opts->{"group_by"};}
Truth table0%0/4
not(A) and B and C
A= not $opts->{"output_filter_where_clause"}B= $opts->{"group_by"}C= @{$opts->{"group_by"};}
ABCresult
0XX0
10X0
1100
1111
2465 0 $col = $opts->{group_by}[$pt-1];
2466 0 ▶ if (!defined $col) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $col) 0 0 0
2467 die "Cannot refer to column number $pt from the expression $opts->{expression} following a 'for' with ".
2468 0 scalar(@{$opts->{group_by}})." column(s): (".join(', ',ListV($opts->{group_by})).")!\n";
2469 }
2470 } else {
2471 0 ▶ if ($opts->{'output_filter'}<2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'output_filter'} < 2) { } 0 0 0
elsif ($pt - 1 < ListV($opts->{'prev_columns'})) { } 0 0 0
2472 0 die "Cannot refer to a numbered column \$$pt from the first filter!\n";
2473 } elsif ($pt-1 < ListV($opts->{prev_columns})) {
2474 0 $col = 'c'.($opts->{'output_filter'}-1).'_'.$pt;
2475 } else {
2476 die "Cannot refer to column number $pt from the expression '$opts->{expression}' following a filter with ".
2477 0 scalar(@{$opts->{prev_columns}})." column(s): (".join(', ',ListV($opts->{prev_columns})).")!\n";
2478 }
2479 }
2480 0 return ' '.$col.' ';
2481 }
2482 0 ▶ if (defined($opts->{'output_filter'}) and $opts->{'output_filter'}==1) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts->{'output_filter'} and $opts->{'output_filter'} == 1) { } 0 0 0
elsif ($opts->{'output_filter'}) { } 0 0 0
Condition0%0/3
defined $opts->{"output_filter"} and $opts->{"output_filter"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"output_filter"} and $opts->{"output_filter"} == 1
defined $opts->{"output_filter"} $opts->{"output_filter"} == 1
Truth table0%0/3
A and B
A= defined $opts->{"output_filter"}B= $opts->{"output_filter"} == 1
ABresult
0X0
100
111
2483 0 ▶ if ($pt eq '$') {
Branch: 2 branches
BranchTrueFalseTotal
if ($pt eq '$') { } 0 0 0
elsif ($self->cmp_subquery_scope($this_node_id, $pt) < 0) { } 0 0 0
2484 0 die "The variable '\$\$' cannot be used in an output filter!\n";
2485 } elsif ($self->cmp_subquery_scope($this_node_id,$pt)<0) {
2486 0 die "Node '$pt' belongs to a sub-query and cannot be referred from the scope of node '$this_node_id' ($opts->{expression})\n";
2487 }
2488 0 return qq{ "#qnodes"."$pt.#idx" }; # not "$pt"."#idx" !!
2489 } elsif ($opts->{'output_filter'}) {
2490 0 die("Cannot refer to a named node '$pt' from an output filters except for the first filter! ($opts->{expression})\n");
2491 } else {
2492 0 ▶ return qq{ "$this_node_id"."#idx" } if $pt eq '$';
Branch: 1 branch
BranchTrueFalseTotal
if $pt eq "\$" 0 0 0
2493 0 ▶ if ($self->cmp_subquery_scope($this_node_id,$pt)<0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cmp_subquery_scope($this_node_id, $pt) < 0) 0 0 0
2494 0 die "Node '$pt' belongs to a sub-query and cannot be referred from the scope of node '$this_node_id' ($opts->{expression})\n";
2495 }
2496 0 return qq( "$pt"."#idx" );
2497 }
2498 } else { # unrecognized token
2499 0 die "Token '$pt' not recognized in expression $opts->{expression} of node '$this_node_id'\n";
2500 }
2501 }
2502 }
2503  
2504 sub serialize_expression {
2505 0 ▶ my ($self,$opts)=@_;
Subroutine serialize_expression: not called CC=15 SCAR=54.8
Pod undocumented
2506 my $pt =
2507 $opts->{'output_filter'}
2508 ? PMLTQ::Common::parse_column_expression($opts->{expression})
2509 0 ▶ : PMLTQ::Common::parse_expression($opts->{expression}); # $pt stands for parse tree
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'output_filter'} ? : 0 0 0
2510 0 ▶ die "Invalid expression '$opts->{expression}' on node '$opts->{id}'" unless defined $pt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pt 0 0 0
2511  
2512 0 ▶ my $extra_joins=$opts->{'output_filter'} ? $opts->{join} : {};
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'output_filter'} ? : 0 0 0
2513 0 $opts->{use_exists}=0;
2514 0 $opts->{can_be_null}=0;
2515 0 my $out = $self->serialize_expression_pt($pt,$opts,$extra_joins); # do not copy $opts here!
2516 0 my $wrap;
2517 0 ▶ if (!$opts->{'output_filter'} and $opts->{use_exists}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opts->{"output_filter"} and $opts->{"use_exists"}) 0 0 0
Condition0%0/3
not $opts->{"output_filter"} and $opts->{"use_exists"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $opts->{"output_filter"} and $opts->{"use_exists"}
not $opts->{"output_filter"} $opts->{"use_exists"}
Truth table0%0/3
not(A) and B
A= not $opts->{"output_filter"}B= $opts->{"use_exists"}
ABresult
0X0
100
111
2518 0 my @from;
2519 my @where;
2520 0 for my $name (grep { $_ ne '..' } keys (%$extra_joins)) {
2521 0 ▶ if ($extra_joins->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_joins->{$name}) 0 0 0
2522 0 my $table;
2523 0 for my $join_spec (@{$extra_joins->{$name}}) {
2524 0 my ($join_as,$join_tab,$join_on,$join_type)=@{$join_spec};
2525 0 ▶ $join_type||='';
Condition0%0/2
$join_type ||= ""
l!l
00
MC/DC0%0/1
$join_type ||= ""
$join_type
Truth table0%0/2
A
A= $join_type
Aresult
11
00
2526 0 $join_tab = $self->get_real_table_name($join_tab);
2527 0 ▶ if (defined $table) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $table) { } 0 0 0
2528 0 $table.=qq(\n $join_type JOIN "$join_tab" "$join_as" ON $join_on);
2529 } else {
2530 0 $table=qq("$join_tab" "$join_as");
2531 0 push @where, $join_on;
2532 }
2533 }
2534 0 push @from,$table;
2535 }
2536 }
2537 0 ▶ if (@from) {
Branch: 1 branch
BranchTrueFalseTotal
if (@from) 0 0 0
2538 0 ▶ $wrap=($opts->{use_exists}==2 ? 'NOT EXISTS' : 'EXISTS').' (SELECT *'
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'use_exists'} == 2 ? : 0 0 0
2539 .' FROM '.join(', ',@from)
2540 .' WHERE '.join("\n AND ",@where);
2541 0 $wrap=~s/%/%%/g;
2542 0 ▶ $wrap.="\n AND " if @where;
Branch: 1 branch
BranchTrueFalseTotal
if @where 0 0 0
2543 0 ▶ if ($opts->{use_exists}==2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'use_exists'} == 2) { } 0 0 0
2544 0 $wrap.='NOT(%s) )';
2545 } else {
2546 0 $wrap.='%s )';
2547 }
2548 }
2549 }
2550 # $out = '' if $opts->{use_exists}==2;
2551 0 return ($out,$wrap,$opts->{can_be_null});
2552 }
2553  
2554 sub compute_data_type {
2555 0 ▶ my ($self, $exp, $opts)=@_;
Subroutine compute_data_type: not called CC=2 SCAR=17.9
Pod undocumented
2556 0 ▶ if ($opts->{output_filter}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'output_filter'}) { } 0 0 0
2557 0 return PMLTQ::Common::compute_column_data_type($self,$exp,$opts);
2558 } else {
2559 0 return PMLTQ::Common::compute_expression_data_type($self,$exp,$opts);
2560 }
2561 }
2562  
2563 sub serialize_predicate {
2564 0 ▶ my ($self,$L,$R,$operator,$opts)=@_;
Subroutine serialize_predicate: not called CC=42 SCAR=75.0
Pod undocumented
2565 0 ▶ $opts->{join}||={};
Condition0%0/2
$opts->{"join"} ||= {}
l!l
00
MC/DC0%0/1
$opts->{"join"} ||= {}
$opts->{"join"}
Truth table0%0/2
A
A= $opts->{"join"}
Aresult
11
00
2566  
2567 my ($left,$wrap_left,$left_can_be_null) = ref($L) ?
2568 0 ▶ (defined($L->{sql}) ? ($L->{sql}) : $self->serialize_expression($L)) : ($L);
Branch: 2 branches
BranchTrueFalseTotal
ref $L ? : 0 0 0
defined $L->{'sql'} ? : 0 0 0
2569 0 ▶ if (ref($L) and defined($L->{use_exists}) and $L->{use_exists}==2) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $L and defined $L->{"use_exists"} and $L->{"use_exists"} == 2) 0 0 0
Condition0%0/6
ref $L and defined $L->{"use_exists"} and $L->{"use_exists"} == 2
!ll&&!rl&&r
000
ref $L and defined $L->{"use_exists"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $L and defined $L->{"use_exists"} and $L->{"use_exists"} == 2
ref $L defined $L->{"use_exists"} $L->{"use_exists"} == 2
Truth table0%0/4
A and B and C
A= ref $LB= defined $L->{"use_exists"}C= $L->{"use_exists"} == 2
ABCresult
0XX0
10X0
1100
1111
2570 0 $R->{is_positive_conjunct}=0;
2571 0 $R->{can_be_null}=1;
2572 }
2573 0 my $right_every;
2574 my ($right,$wrap_right,$right_can_be_null) = ref($R) ?
2575 0 ▶ (defined($R->{sql}) ? ($R->{sql}) : $self->serialize_expression($R)) : ($R);
Branch: 2 branches
BranchTrueFalseTotal
ref $R ? : 0 0 0
defined $R->{'sql'} ? : 0 0 0
2576 0 my $is_positive_conjunct = $opts->{is_positive_conjunct};
2577 0 ▶ my $negate = $operator=~ s/^!// ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$operator =~ s/^!// ? : 0 0 0
2578 0 ▶ $is_positive_conjunct=0 if $is_positive_conjunct && $negate;
Branch: 1 branch
BranchTrueFalseTotal
if $is_positive_conjunct and $negate 0 0 0
Condition0%0/3
$is_positive_conjunct and $negate
!ll&&!rl&&r
000
MC/DC0%0/2
$is_positive_conjunct and $negate
$is_positive_conjunct $negate
Truth table0%0/3
A and B
A= $is_positive_conjunctB= $negate
ABresult
0X0
100
111
2579  
2580 0 my $res;
2581 0 my ($R_type, $L_type) = (COL_UNKNOWN, COL_UNKNOWN);
2582 $R_type = ref($R) ?
2583 (defined($R->{col_type}) ? $R->{col_type} : $self->compute_data_type($R->{expression},$opts))
2584 0 ▶ : defined($opts->{R_type}) ? $opts->{R_type} : COL_UNKNOWN;
Branch: 3 branches
BranchTrueFalseTotal
ref $R ? : 0 0 0
defined $R->{'col_type'} ? : 0 0 0
defined $opts->{'R_type'} ? : 0 0 0
2585 $L_type = ref($L) ?
2586 (defined($L->{col_type}) ? $L->{col_type} : $self->compute_data_type($L->{expression},$opts))
2587 0 ▶ : defined($opts->{L_type}) ? $opts->{L_type} : COL_UNKNOWN;
Branch: 3 branches
BranchTrueFalseTotal
ref $L ? : 0 0 0
defined $L->{'col_type'} ? : 0 0 0
defined $opts->{'L_type'} ? : 0 0 0
2588  
2589 0 ▶ if ($right =~ qr{^\s*[NE]?''\s*$} and $left =~ qr{^\s*[NE]?''\s*$}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($right =~ qr/^\s*[NE]?''\s*$/ and $left =~ qr/^\s*[NE]?''\s*$/) { } 0 0 0
elsif ($right =~ qr/^\s*[NE]?''\s*$/) { } 0 0 0
elsif ($left =~ qr/^\s*[NE]?''\s*$/) { } 0 0 0
Condition0%0/3
$right =~ qr/^\s*[NE]?''\s*$/ and $left =~ qr/^\s*[NE]?''\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
$right =~ qr/^\s*[NE]?''\s*$/ and $left =~ qr/^\s*[NE]?''\s*$/
$right =~ qr/^\s*[NE]?''\s*$/ $left =~ qr/^\s*[NE]?''\s*$/
Truth table0%0/3
A and B
A= $right =~ qr/^\s*[NE]?''\s*$/B= $left =~ qr/^\s*[NE]?''\s*$/
ABresult
0X0
100
111
2590 0 $res = qq{0=0}
2591 } elsif ($right =~ qr{^\s*[NE]?''\s*$}) {
2592 0 ▶ if ($L_type == COL_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($L_type == 1) { } 0 0 0
2593 0 $res = qq{($left }.uc($operator).qq{ $right OR $left IS NULL)}
2594 } else {
2595 0 $res = qq{$left IS NULL}
2596 }
2597 } elsif ($left =~ qr{^\s*[NE]?''\s*$}) {
2598 0 ▶ if ($R_type == COL_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($R_type == 1) { } 0 0 0
2599 0 $res = qq{($right }.uc($operator).qq{ $left OR $right IS NULL)}
2600 } else {
2601 0 $res = qq{$right IS NULL}
2602 }
2603 }
2604 0 ▶ if (!defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
2605 0 ▶ if ($operator =~/[<>=]/) { # includes "fake is-between operator" <N,M>
Branch: 1 branch
BranchTrueFalseTotal
if ($operator =~ /[<>=]/) 0 0 0
2606 0 ▶ if ($L_type == COL_NUMERIC and
Branch: 2 branches
BranchTrueFalseTotal
if ($L_type == 2 and $R_type != 2) { } 0 0 0
elsif ($R_type == 2 and $L_type != 2) { } 0 0 0
Condition0%0/3
$L_type == 2 and $R_type != 2
!ll&&!rl&&r
000
MC/DC0%0/2
$L_type == 2 and $R_type != 2
$L_type == 2 $R_type != 2
Truth table0%0/3
A and B
A= $L_type == 2B= $R_type != 2
ABresult
0X0
100
111
2607 $R_type != COL_NUMERIC) {
2608 0 $left=qq{cast($left as varchar)};
2609 ▶ } elsif ($R_type == COL_NUMERIC and
Condition0%0/3
$R_type == 2 and $L_type != 2
!ll&&!rl&&r
000
MC/DC0%0/2
$R_type == 2 and $L_type != 2
$R_type == 2 $L_type != 2
Truth table0%0/3
A and B
A= $R_type == 2B= $L_type != 2
ABresult
0X0
100
111
2610 $L_type != COL_NUMERIC) {
2611 0 $right=qq{cast($right as varchar)};
2612 }
2613 }
2614 0 ▶ my $cmp =
Branch: 4 branches
BranchTrueFalseTotal
$operator =~ /^<(.*),(.*)>$/ ? : 0 0 0
length $1 && length $2 ? : 0 0 0
length $1 ? : 0 0 0
length $2 ? : 0 0 0
Condition0%0/3
length $1 and length $2
!ll&&!rl&&r
000
MC/DC0%0/2
length $1 and length $2
length $1 length $2
Truth table0%0/3
A and B
A= length $1B= length $2
ABresult
0X0
100
111
2615 $operator=~/^<(.*),(.*)>$/ ? # special "fake is-between operator"
2616 qq{($left - $right)}.
2617 (
2618 (length($1) and length($2)) ? qq{BETWEEN $1 AND $2} :
2619 length($1) ? qq{>=$1} :
2620 length($2) ? qq{<=$2} : die("Internal error: cannot serialize operator $operator\n")
2621 )
2622 : qq{$left }.uc($operator).qq{ $right};
2623 0 ▶ $res = '('.$cmp
Branch: 2 branches
BranchTrueFalseTotal
$left_can_be_null && !$is_positive_conjunct ? : 0 0 0
$right_can_be_null && !$is_positive_conjunct ? : 0 0 0
Condition0%0/6
$left_can_be_null and not $is_positive_conjunct
!ll&&!rl&&r
000
$right_can_be_null and not $is_positive_conjunct
!ll&&!rl&&r
000
MC/DC0%0/2
$left_can_be_null and not $is_positive_conjunct
$left_can_be_null not $is_positive_conjunct
MC/DC0%0/2
$right_can_be_null and not $is_positive_conjunct
$right_can_be_null not $is_positive_conjunct
Truth table0%0/3
A and not(B)
A= $left_can_be_nullB= not $is_positive_conjunct
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= $right_can_be_nullB= not $is_positive_conjunct
ABresult
0X0
100
111
2624 .($left_can_be_null && !$is_positive_conjunct ? qq{ AND $left IS NOT NULL} : '')
2625 .($right_can_be_null && !$is_positive_conjunct ? qq{ AND $right IS NOT NULL} : '')
2626 .')';
2627 }
2628 0 ▶ $res = qq{NOT($res)} if $negate;
Branch: 1 branch
BranchTrueFalseTotal
if $negate 0 0 0
2629 0 ▶ if (defined $wrap_right) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wrap_right) 0 0 0
2630 0 $res=sprintf($wrap_right,$res);
2631 }
2632 0 ▶ if (defined $wrap_left) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wrap_left) 0 0 0
2633 0 $res=sprintf($wrap_left,$res);
2634 }
2635 0 return $res;
2636 }
2637  
2638 sub serialize_element {
2639 0 ▶ my ($self,$opts)=@_;
Subroutine serialize_element: not called CC=47 SCAR=77.2
Pod undocumented
2640 0 my ($name,$node,$as_id,$parent_as_id)=map {$opts->{$_}} qw(name condition id parent_id);
2641 0 my $is_positive_conjunct = $opts->{is_positive_conjunct};
2642 0 ▶ if ($name eq 'test') {
Branch: 4 branches
BranchTrueFalseTotal
if ($name eq 'test') { } 0 0 0
elsif ($name =~ /^(?:and|or|not)$/) { } 0 0 0
elsif ($name eq 'subquery') { } 0 0 0
elsif ($name eq 'ref') { } 0 0 0
2643 return
2644 [$self->serialize_predicate({%$opts,
2645 expression=>$node->{a},
2646 is_positive_conjunct=>$is_positive_conjunct},
2647 {%$opts,
2648 expression=>$node->{b},
2649 is_positive_conjunct=>$is_positive_conjunct},
2650 $node->{operator},
2651 0 $opts),$node];
2652 } elsif ($name =~ /^(?:and|or|not)$/) {
2653 0 my @c = $node->children;
2654 0 ▶ if (defined($is_positive_conjunct)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $is_positive_conjunct) 0 0 0
2655 0 ▶ if ($name eq 'not') {
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'not') { } 0 0 0
elsif ($name eq 'and') { } 0 0 0
elsif ($name eq 'or') { } 0 0 0
2656 0 $is_positive_conjunct=!$is_positive_conjunct;
2657 0 ▶ $is_positive_conjunct=undef if @c>1 and !$is_positive_conjunct;
Branch: 1 branch
BranchTrueFalseTotal
if @c > 1 and not $is_positive_conjunct 0 0 0
Condition0%0/3
@c > 1 and not $is_positive_conjunct
!ll&&!rl&&r
000
MC/DC0%0/2
@c > 1 and not $is_positive_conjunct
@c > 1 not $is_positive_conjunct
Truth table0%0/3
A and not(B)
A= @c > 1B= not $is_positive_conjunct
ABresult
0X0
100
111
2658 } elsif ($name eq 'and') {
2659 0 ▶ $is_positive_conjunct=undef if @c>1 and !$is_positive_conjunct;
Branch: 1 branch
BranchTrueFalseTotal
if @c > 1 and not $is_positive_conjunct 0 0 0
Condition0%0/3
@c > 1 and not $is_positive_conjunct
!ll&&!rl&&r
000
MC/DC0%0/2
@c > 1 and not $is_positive_conjunct
@c > 1 not $is_positive_conjunct
Truth table0%0/3
A and not(B)
A= @c > 1B= not $is_positive_conjunct
ABresult
0X0
100
111
2660 } elsif ($name eq 'or') {
2661 0 ▶ $is_positive_conjunct=undef if @c>1 and $is_positive_conjunct;
Branch: 1 branch
BranchTrueFalseTotal
if @c > 1 and $is_positive_conjunct 0 0 0
Condition0%0/3
@c > 1 and $is_positive_conjunct
!ll&&!rl&&r
000
MC/DC0%0/2
@c > 1 and $is_positive_conjunct
@c > 1 $is_positive_conjunct
Truth table0%0/3
A and B
A= @c > 1B= $is_positive_conjunct
ABresult
0X0
100
111
2662 }
2663 }
2664 @c =
2665 0 grep { @$_ }
2666 map {
2667 0 my $n = $_->{'#name'};
2668 0 $self->serialize_element({
2669 %$opts,
2670 name => $n,
2671 condition => $_,
2672 id => $as_id,
2673 parent_id => $parent_as_id,
2674 is_positive_conjunct=>$is_positive_conjunct
2675 })
2676 0 } grep { $_->{'#name'} ne 'node' } @c;
2677 0 ▶ return unless @c;
Branch: 1 branch
BranchTrueFalseTotal
unless @c 0 0 0
2678 return
2679 0 ▶ $name eq 'not' ? [[['NOT('],@{PMLTQ::Common::_group(\@c,["\n AND "])},[')']],$node] :
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'and' ? : 0 0 0
2680 0 ▶ $name eq 'and' ? [[['('],@{PMLTQ::Common::_group(\@c,["\n AND "])},[')']],$node] :
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'or' ? : 0 0 0
2681 0 ▶ $name eq 'or' ? [[['('],@{PMLTQ::Common::_group(\@c,["\n OR "])},[')']],$node] : ();
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'not' ? : 0 0 0
2682 } elsif ($name eq 'subquery') {
2683 0 my @sql;
2684 my @occ;
2685 0 my @vals = grep ref, AltV($node->{occurrences});
2686 0 ▶ @vals=(Treex::PML::Factory->createStructure({min=>1})) unless @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless @vals 0 0 0
2687 # we treat 0x and 1+x especially
2688 # using exists and not exists
2689 0 my ($exists, $not_exists);
2690 $exists = (@vals==1 and $vals[0]{min}==1 and
2691 0 ▶ (!defined($vals[0]{max}) or !length($vals[0]{max})));
Condition0%0/9
@vals == 1 && $vals[0]{'min'} == 1 && !(defined $vals[0]{'max'} && length $vals[0]{'max'})
!ll&&!rl&&r
000
@vals == 1 and $vals[0]{"min"} == 1
!ll&&!rl&&r
000
defined $vals[0]{'max'} && length $vals[0]{'max'}
!ll&&!rl&&r
000
MC/DC0%0/4
@vals == 1 && $vals[0]{'min'} == 1 && !(defined $vals[0]{'max'} && length $vals[0]{'max'})
@vals == 1 $vals[0]{"min"} == 1 defined $vals[0]{'max'} length $vals[0]{'max'}
Truth table0%0/5
A and B && not(C && D)
A= @vals == 1B= $vals[0]{"min"} == 1C= defined $vals[0]{'max'}D= length $vals[0]{'max'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
2692 $not_exists = ( ! $exists
2693 and @vals == 1
2694 and defined $vals[0]{max} and length $vals[0]{max} and $vals[0]{max} == 0
2695 0 ▶ and ($vals[0]{min}||0) == 0);
Condition0%0/17
!$exists && @vals == 1 && defined $vals[0]{'max'} && length $vals[0]{'max'} && $vals[0]{'max'} == 0 && ($vals[0]{'min'} || 0) == 0
!ll&&!rl&&r
000
not $exists and @vals == 1 and defined $vals[0]{"max"} and length $vals[0]{"max"} and $vals[0]{"max"} == 0
!ll&&!rl&&r
000
not $exists and @vals == 1 and defined $vals[0]{"max"} and length $vals[0]{"max"}
!ll&&!rl&&r
000
not $exists and @vals == 1 and defined $vals[0]{"max"}
!ll&&!rl&&r
000
not $exists and @vals == 1
!ll&&!rl&&r
000
$vals[0]{'min'} || 0
l!l
00
MC/DC0%0/6
!$exists && @vals == 1 && defined $vals[0]{'max'} && length $vals[0]{'max'} && $vals[0]{'max'} == 0 && ($vals[0]{'min'} || 0) == 0
not $exists @vals == 1 defined $vals[0]{"max"} length $vals[0]{"max"} $vals[0]{"max"} == 0 $vals[0]{'min'}
Truth table0%0/7
not(A) and B and C and D and E && F
A= not $existsB= @vals == 1C= defined $vals[0]{"max"}D= length $vals[0]{"max"}E= $vals[0]{"max"} == 0F= $vals[0]{'min'}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
2696 my $subquery = $self->build_sql($node,{
2697 format => 1,
2698 count=> ($exists || $not_exists ) ? 3 : 2,
2699 parent_id=>$opts->{id},
2700 join => {
2701 '..' => $opts->{join}, # where joins for nodes in the outer scope should go
2702 }, # $opts->{join}, # let subqueries use their own join
2703 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
$exists || $not_exists ? : 0 0 0
Condition0%0/3
$exists or $not_exists
l!l&&r!l&&!r
000
MC/DC0%0/2
$exists or $not_exists
$exists $not_exists
Truth table0%0/3
A or B
A= $existsB= $not_exists
ABresult
1X1
011
000
2704  
2705 0 ▶ if ($exists) {
Branch: 2 branches
BranchTrueFalseTotal
if ($exists) { } 0 0 0
elsif ($not_exists) { } 0 0 0
2706 0 return [[['EXISTS ('],@$subquery,[qq')']],$node];
2707 } elsif ($not_exists) {
2708 0 return [[['NOT EXISTS ('],@$subquery,[qq')']],$node];
2709 } else {
2710 0 for my $occ (@vals) { # this is not optimal for @occ>1
2711 0 my ($min,$max)=($occ->{min},$occ->{max});
2712 0 ▶ $min='' unless defined $min;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 0 0 0
2713 0 ▶ $max='' unless defined $max;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max 0 0 0
2714 0 ▶ if (length($min) and length($max)) {
Branch: 3 branches
BranchTrueFalseTotal
if (length $min and length $max) { } 0 0 0
elsif (length $min) { } 0 0 0
elsif (length $max) { } 0 0 0
Condition0%0/3
length $min and length $max
!ll&&!rl&&r
000
MC/DC0%0/2
length $min and length $max
length $min length $max
Truth table0%0/3
A and B
A= length $minB= length $max
ABresult
0X0
100
111
2715 0 ▶ if ($min==$max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min == $max) { } 0 0 0
2716 0 push @occ,[[['('],@$subquery,[qq')=$min']],$node];
2717 } else {
2718 0 push @occ,[[['('],@$subquery,[qq') BETWEEN $min AND $max']],$node];
2719 }
2720 } elsif (length($min)) {
2721 0 push @occ,[[['('],@$subquery,[qq')>=$min']],$node];
2722 } elsif (length($max)) {
2723 0 push @occ,[[['('],@$subquery,[qq')<=$max']],$node];
2724 }
2725 }
2726 0 ▶ return (@occ ? [[ ['('],@{PMLTQ::Common::_group(\@occ,[' OR '])},[')'] ],$node] : ());
Branch: 1 branch
BranchTrueFalseTotal
@occ ? : 0 0 0
2727 }
2728 } elsif ($name eq 'ref') {
2729 0 my $target = $node->{target};
2730 0 my $cmp = $self->cmp_subquery_scope($node,$target);
2731 0 ▶ if ($cmp<0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp < 0) 0 0 0
2732 0 die "Node '$as_id' belongs to a sub-query and cannot be referred from the scope of node '$target'\n";
2733 }
2734 # case $cmp>0 implies we use negative approach on Oracle by forcing using EXISTS (on Postgress this drops performance drammatically)
2735 # FIXME: why exactly do we do it on Oracle?
2736 0 my ($rel) = SeqV($node->{relation});
2737 0 ▶ if ($target and $rel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target and $rel) { } 0 0 0
Condition0%0/3
$target and $rel
!ll&&!rl&&r
000
MC/DC0%0/2
$target and $rel
$target $rel
Truth table0%0/3
A and B
A= $targetB= $rel
ABresult
0X0
100
111
2738 return ['('.$self->relation($as_id,$rel,$target,
2739 0 ▶ {%$opts,is_positive_conjunct=>(($opts->{is_positive_conjunct} || !$cmp)
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'is_positive_conjunct'} || !$cmp ? : 0 0 0
Condition0%0/3
$opts->{"is_positive_conjunct"} or not $cmp
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"is_positive_conjunct"} or not $cmp
$opts->{"is_positive_conjunct"} not $cmp
Truth table0%0/3
A or not(B)
A= $opts->{"is_positive_conjunct"}B= not $cmp
ABresult
1X1
011
000
2740 ? 1 : undef)},
2741 $opts
2742 ).')',$node];
2743 } else {
2744 0 return;
2745 }
2746 } else {
2747 0 Carp::cluck("Unknown element $name ");
2748 0 return;
2749 }
2750 }
2751  
2752 sub cmp_subquery_scope {
2753 0 ▶ my ($self,$src,$target)=@_;
Subroutine cmp_subquery_scope: not called CC=4 SCAR=30.0
Pod undocumented
2754 $_ = ref($_) ? $_ : $self->{name2node}{$_} || croak("Didn't find node '\$$_'")
2755 0 ▶ for $src,$target;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
Condition0%0/3
$self->{"name2node"}{$_} or croak("Didn't find node '\$${_}'")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"name2node"}{$_} or croak("Didn't find node '\$${_}'")
$self->{"name2node"}{$_} croak("Didn't find node '\$${_}'")
Truth table0%0/3
A or B
A= $self->{"name2node"}{$_}B= croak("Didn't find node '\$${_}'")
ABresult
1X1
011
000
2756 0 return PMLTQ::Common::cmp_subquery_scope($src,$target);
2757 }
2758  
2759 sub DESTROY {
2760 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=2 SCAR=17.9
2761  
2762 # Make sure we disconnect from database when destroyed
2763 0 ▶ $self->{dbi}->disconnect() if $self->{dbi};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"dbi"} 0 0 0
2764 }
2765  
2766 2 1; # End of PMLTQ::SQLEvaluator
2767  
2768 __END__
↑ Summary blib/lib/PMLTQ/BtredEvaluator.pm »