sub select {
my ($self, $table, $fields, $where, $order, @rest) = @_;
- $self->_oracle_joins($where, @{ $table });
+ if (ref($table) eq 'ARRAY') {
+ $where = $self->_oracle_joins($where, @{ $table });
+ }
return $self->SUPER::select($table, $fields, $where, $order, @rest);
}
sub _oracle_joins {
my ($self, $where, $from, @join) = @_;
+ my $join_where = {};
+ $self->_recurse_oracle_joins($join_where, $from, @join);
+ if (keys %$join_where) {
+ if (!defined($where)) {
+ $where = $join_where;
+ } else {
+ if (ref($where) eq 'ARRAY') {
+ $where = { -or => $where };
+ }
+ $where = { -and => [ $join_where, $where ] };
+ }
+ }
+ return $where;
+ }
+
+ sub _recurse_oracle_joins {
+ my ($self, $where, $from, @join) = @_;
foreach my $j (@join) {
my ($to, $on) = @{ $j };
if (ref $to eq 'ARRAY') {
- $self->_oracle_joins($where, @{ $to });
+ $self->_recurse_oracle_joins($where, @{ $to });
}
my $to_jt = ref $to eq 'ARRAY' ? $to->[0] : $to;
die "Can't handle full outer joins in Oracle 8 yet!\n"
if $to_jt->{-join_type} =~ /full/i;
- $left_join = q{(+)} if $to_jt->{-join_type} =~ /right/i
+ $left_join = q{(+)} if $to_jt->{-join_type} =~ /left/i
&& $to_jt->{-join_type} !~ /inner/i;
- $right_join = q{(+)} if $to_jt->{-join_type} =~ /left/i
+ $right_join = q{(+)} if $to_jt->{-join_type} =~ /right/i
&& $to_jt->{-join_type} !~ /inner/i;
}
foreach my $lhs (keys %{ $on }) {
- $where->{$lhs . $left_join} = \" = $on->{ $lhs }$right_join";
+ $where->{$lhs . $left_join} = \"= $on->{ $lhs }$right_join";
}
}
}