Oracle/SQLMaker/Joins.pm

filter: Statementstmt 92.7% 51 / 55 Branchbran 75.0% 21 / 28 Conditioncond 50.0% 9 / 18 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 77.3% 92 / 119 CC 23 SCAR 26.4
CC
23
Cov
80%
_recurse_oracle_joins
22.0
_oracle_joins
4.0
_recurse_from
3.2
CRAP 14.0
« Oracle/SQLMaker.pm ↑ Summary Oracle/Storage/ConnectSetup.pm »
1 package DBIO::Oracle::SQLMaker::Joins;
2 # ABSTRACT: Pre-ANSI Joins-via-Where-Clause Syntax for Oracle
3  
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use base qw( DBIO::Oracle::SQLMaker );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 8 ▶sub select {
Subroutine select: called CC=2 SCAR=7.0
Pod documented
11 8 my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
12  
13 8 ▶ if (ref($table) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $table eq "ARRAY") 8 0 8
14 8 $where = $self->_oracle_joins($where, @{ $table }[ 1 .. $#$table ]);
15 }
16  
17 8 return $self->next::method($table, $fields, $where, $rs_attrs, @rest);
18 }
19  
20 8 ▶sub _recurse_from {
Subroutine _recurse_from: called CC=3 SCAR=11.6
21 8 my ($self, $from, @join) = @_;
22  
23 8 my @sqlf = $self->_from_chunk_to_sql($from);
24  
25 8 for (@join) {
26 8 my ($to, $on) = @$_;
27  
28 8 ▶ if (ref $to eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $to eq 'ARRAY') { } 0 8 8
29 0 push (@sqlf, $self->_recurse_from(@{ $to }));
30 }
31 else {
32 8 push (@sqlf, $self->_from_chunk_to_sql($to));
33 }
34 }
35  
36 8 return join q{, }, @sqlf;
37 }
38  
39 8 ▶sub _oracle_joins {
Subroutine _oracle_joins: called CC=4 SCAR=13.9
40 8 my ($self, $where, @join) = @_;
41 8 my $join_where = $self->_recurse_oracle_joins(@join);
42  
43 8 ▶ if (keys %$join_where) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$join_where) 8 0 8
44 8 ▶ if (!defined($where)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $where) { } 2 6 8
45 2 $where = $join_where;
46 } else {
47 6 ▶ if (ref($where) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $where eq "ARRAY") 2 4 6
48 2 $where = { -or => $where };
49 }
50 6 $where = { -and => [ $join_where, $where ] };
51 }
52 }
53 8 return $where;
54 }
55  
56 8 ▶sub _recurse_oracle_joins {
Subroutine _recurse_oracle_joins: called CC=17 SCAR=30.9
57 8 my $self = shift;
58  
59 8 my @where;
60 8 for my $j (@_) {
61 8 my ($to, $on) = @{ $j };
62  
63 8 ▶ push @where, $self->_recurse_oracle_joins(@{ $to })
Branch: 1 branch
BranchTrueFalseTotal
if ref $to eq "ARRAY" 0 8 8
64 if (ref $to eq 'ARRAY');
65  
66 8 ▶ my $join_opts = ref $to eq 'ARRAY' ? $to->[0] : $to;
Branch: 1 branch
BranchTrueFalseTotal
ref $to eq 'ARRAY' ? : 0 8 8
67 8 my $left_join = q{};
68 8 my $right_join = q{};
69  
70 8 ▶ if (ref $join_opts eq 'HASH' and my $jt = $join_opts->{-join_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $join_opts eq "HASH" and my $jt = $join_opts->{"-join_type"}) 6 2 8
Condition66%2/3
ref $join_opts eq "HASH" and my $jt = $join_opts->{"-join_type"}
!ll&&!rl&&r
026
MC/DC50%1/2
ref $join_opts eq "HASH" and my $jt = $join_opts->{"-join_type"}
ref $join_opts eq "HASH" my $jt = $join_opts->{"-join_type"}
Truth table66%2/3
A and B
A= ref $join_opts eq "HASH"B= my $jt = $join_opts->{"-join_type"}
ABresult
0X0
100
111
71 6 ▶ $self->throw_exception("Can't handle full outer joins in Oracle 8 yet!\n")
Branch: 1 branch
BranchTrueFalseTotal
if $jt =~ /full/i 0 6 6
72 if $jt =~ /full/i;
73  
74 6 ▶ $left_join = q{(+)} if $jt =~ /left/i
Branch: 1 branch
BranchTrueFalseTotal
if $jt =~ /left/i and not $jt =~ /inner/i 4 2 6
Condition66%2/3
$jt =~ /left/i and not $jt =~ /inner/i
!ll&&!rl&&r
204
MC/DC50%1/2
$jt =~ /left/i and not $jt =~ /inner/i
$jt =~ /left/i not $jt =~ /inner/i
Truth table66%2/3
A and not(B)
A= $jt =~ /left/iB= not $jt =~ /inner/i
ABresult
0X0
100
111
75 && $jt !~ /inner/i;
76  
77 6 ▶ $right_join = q{(+)} if $jt =~ /right/i
Branch: 1 branch
BranchTrueFalseTotal
if $jt =~ /right/i and not $jt =~ /inner/i 2 4 6
Condition66%2/3
$jt =~ /right/i and not $jt =~ /inner/i
!ll&&!rl&&r
402
MC/DC50%1/2
$jt =~ /right/i and not $jt =~ /inner/i
$jt =~ /right/i not $jt =~ /inner/i
Truth table66%2/3
A and not(B)
A= $jt =~ /right/iB= not $jt =~ /inner/i
ABresult
0X0
100
111
78 && $jt !~ /inner/i;
79 }
80  
81 $on = $on->{-and}[0] if (
82 ref $on eq 'HASH'
83 and
84 keys %$on == 1
85 and
86 ref $on->{-and} eq 'ARRAY'
87 and
88 8 ▶ @{$on->{-and}} == 1
Branch: 1 branch
BranchTrueFalseTotal
if ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY" and @{$on->{"-and"};} == 1 0 8 8
Condition33%3/9
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY" and @{$on->{"-and"};} == 1
!ll&&!rl&&r
800
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY"
!ll&&!rl&&r
080
ref $on eq "HASH" and keys %$on == 1
!ll&&!rl&&r
008
MC/DC0%0/4
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY" and @{$on->{"-and"};} == 1
ref $on eq "HASH" keys %$on == 1 ref $on->{"-and"} eq "ARRAY" @{$on->{"-and"};} == 1
Truth table20%1/5
A and B and C and D
A= ref $on eq "HASH"B= keys %$on == 1C= ref $on->{"-and"} eq "ARRAY"D= @{$on->{"-and"};} == 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
89 );
90  
91 8 push @where, map { \do {
92 my ($sql) = $self->_recurse_where({
93 $_ => ( length ref $on->{$_}
94 ? $on->{$_}
95 8 ▶ : { -ident => $on->{$_} }
Branch: 1 branch
BranchTrueFalseTotal
length ref $on->{$_} ? : 4 4 8
96 )
97 });
98  
99 8 ▶ $sql =~ s/\s*\=/$left_join =/
Branch: 1 branch
BranchTrueFalseTotal
if $left_join 4 4 8
100 if $left_join;
101  
102 8 "$sql$right_join";
103 }
104 } sort keys %$on;
105 }
106  
107 8 return { -and => \@where };
108 }
109  
110  
111 2 1;
112  
113 __END__
114  
115 =pod
116  
117 =encoding UTF-8
118  
119 =head1 NAME
120  
121 DBIO::Oracle::SQLMaker::Joins - Pre-ANSI Joins-via-Where-Clause Syntax for Oracle
122  
123 =head1 VERSION
124  
125 version 0.900001
126  
127 =head1 DESCRIPTION
128  
129 L<DBIO::Oracle::SQLMaker> subclass that generates Oracle's pre-ANSI
130 WHERE-clause join syntax (C<table1, table2 WHERE table1.id = table2.id>)
131 instead of standard C<JOIN ... ON> syntax.
132  
133 This is used automatically by L<DBIO::Oracle::Storage::WhereJoins> for
134 Oracle databases older than version 9.0. Left and right outer joins are
135 supported via Oracle's C<(+)> syntax. Full outer joins are not supported.
136  
137 =head1 SEE ALSO
138  
139 =over
140  
141 =item * L<DBIO::Oracle::Storage::WhereJoins> - Storage that uses this SQL maker
142  
143 =item * L<DBIO::Oracle::SQLMaker> - Parent SQL maker with Oracle extensions
144  
145 =back
146  
147 =head1 AUTHOR
148  
149 DBIO & DBIx::Class Authors
150  
151 =head1 COPYRIGHT AND LICENSE
152  
153 Copyright (C) 2026 DBIO Authors
154 Portions Copyright (C) 2005-2025 DBIx::Class Authors
155 Based on DBIx::Class, heavily modified.
156  
157 This is free software; you can redistribute it and/or modify it under
158 the same terms as the Perl 5 programming language system itself.
159  
160 =cut
« Oracle/SQLMaker.pm ↑ Summary Oracle/Storage/ConnectSetup.pm »