| 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use base qw( DBIO::Oracle::SQLMaker ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | if (ref($table) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | $where = $self->_oracle_joins($where, @{ $table }[ 1 .. $#$table ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 8 | return $self->next::method($table, $fields, $where, $rs_attrs, @rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 8 | ▶ | sub _recurse_from { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_recurse_from: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 8 | my ($self, $from, @join) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | my @sqlf = $self->_from_chunk_to_sql($from); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 8 | for (@join) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 8 | my ($to, $on) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | ▶ | if (ref $to eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | push (@sqlf, $self->_recurse_from(@{ $to })); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 8 | push (@sqlf, $self->_from_chunk_to_sql($to)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | return join q{, }, @sqlf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | sub _oracle_joins { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_oracle_joins: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | my ($self, $where, @join) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 8 | my $join_where = $self->_recurse_oracle_joins(@join); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | ▶ | if (keys %$join_where) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | if (!defined($where)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | $where = $join_where; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | if (ref($where) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | $where = { -or => $where }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | $where = { -and => [ $join_where, $where ] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | return $where; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | ▶ | sub _recurse_oracle_joins { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_recurse_oracle_joins: called CC=17 SCAR=30.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 8 | my @where; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 8 | for my $j (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | my ($to, $on) = @{ $j }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | push @where, $self->_recurse_oracle_joins(@{ $to }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | if (ref $to eq 'ARRAY'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | ▶ | my $join_opts = ref $to eq 'ARRAY' ? $to->[0] : $to; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | my $left_join = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 8 | my $right_join = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | ▶ | if (ref $join_opts eq 'HASH' and my $jt = $join_opts->{-join_type}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $join_opts eq "HASH" and my $jt = $join_opts->{"-join_type"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | ▶ | $self->throw_exception("Can't handle full outer joins in Oracle 8 yet!\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | if $jt =~ /full/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | $left_join = q{(+)} if $jt =~ /left/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$jt =~ /left/i and not $jt =~ /inner/i
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | && $jt !~ /inner/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | $right_join = q{(+)} if $jt =~ /right/i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$jt =~ /right/i and not $jt =~ /inner/i
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | && $jt !~ /inner/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | $on = $on->{-and}[0] if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ref $on eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | keys %$on == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ref $on->{-and} eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | @{$on->{-and}} == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY" and @{$on->{"-and"};} == 1
ref $on eq "HASH" and keys %$on == 1 and ref $on->{"-and"} eq "ARRAY"
ref $on eq "HASH" and keys %$on == 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 8 | push @where, map { \do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | my ($sql) = $self->_recurse_where({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | $_ => ( length ref $on->{$_} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ? $on->{$_} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | : { -ident => $on->{$_} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 8 | ▶ | $sql =~ s/\s*\=/$left_join =/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | if $left_join; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 8 | "$sql$right_join"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } sort keys %$on; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | return { -and => \@where }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||