1 package # Hide from PAUSE
2 DBIx::Class::SQLAHacks::OracleJoins;
4 use base qw( DBIx::Class::SQLAHacks );
5 use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
8 my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
10 if (ref($table) eq 'ARRAY') {
11 $where = $self->_oracle_joins($where, @{ $table });
14 return $self->SUPER::select($table, $fields, $where, $rs_attrs, @rest);
18 my ($self, $from, @join) = @_;
20 my @sqlf = $self->_make_as($from);
22 foreach my $j (@join) {
23 my ($to, $on) = @{ $j };
25 if (ref $to eq 'ARRAY') {
26 push (@sqlf, $self->_recurse_from(@{ $to }));
29 push (@sqlf, $self->_make_as($to));
33 return join q{, }, @sqlf;
37 my ($self, $where, $from, @join) = @_;
39 $self->_recurse_oracle_joins($join_where, $from, @join);
40 if (keys %$join_where) {
41 if (!defined($where)) {
44 if (ref($where) eq 'ARRAY') {
45 $where = { -or => $where };
47 $where = { -and => [ $join_where, $where ] };
53 sub _recurse_oracle_joins {
54 my ($self, $where, $from, @join) = @_;
56 foreach my $j (@join) {
57 my ($to, $on) = @{ $j };
59 if (ref $to eq 'ARRAY') {
60 $self->_recurse_oracle_joins($where, @{ $to });
63 my $to_jt = ref $to eq 'ARRAY' ? $to->[0] : $to;
67 if (ref $to_jt eq 'HASH' and exists $to_jt->{-join_type}) {
68 #TODO: Support full outer joins -- this would happen much earlier in
69 #the sequence since oracle 8's full outer join syntax is best
71 croak "Can't handle full outer joins in Oracle 8 yet!\n"
72 if $to_jt->{-join_type} =~ /full/i;
74 $left_join = q{(+)} if $to_jt->{-join_type} =~ /left/i
75 && $to_jt->{-join_type} !~ /inner/i;
77 $right_join = q{(+)} if $to_jt->{-join_type} =~ /right/i
78 && $to_jt->{-join_type} !~ /inner/i;
81 foreach my $lhs (keys %{ $on }) {
82 $where->{$lhs . $left_join} = \"= $on->{ $lhs }$right_join";
93 DBIx::Class::SQLAHacks::OracleJoins - Pre-ANSI Joins-via-Where-Clause Syntax
97 This module was originally written to support Oracle < 9i where ANSI joins
98 weren't supported at all, but became the module for Oracle >= 8 because
99 Oracle's optimising of ANSI joins is horrible.
103 Not intended for use directly; used as the sql_maker_class for schemas and components.
107 Implements pre-ANSI joins specified in the where clause. Instead of:
109 SELECT x FROM y JOIN z ON y.id = z.id
113 SELECT x FROM y, z WHERE y.id = z.id
115 It should properly support left joins, and right joins. Full outer joins are
116 not possible due to the fact that Oracle requires the entire query be written
117 to union the results of a left and right join, and by the time this module is
118 called to create the where query and table definition part of the sql query,
119 it's already too late.
125 =item select ($\@$;$$@)
127 Replaces DBIx::Class::SQLAHacks's select() method, which calls _oracle_joins()
128 to modify the column and table list before calling SUPER::select().
130 =item _recurse_from ($$\@)
132 Recursive subroutine that builds the table list.
134 =item _oracle_joins ($$$@)
136 Creates the left/right relationship in the where query.
142 Does not support full outer joins.
149 =item L<DBIx::Class::Storage::DBI::Oracle::WhereJoins> - Storage class using this
151 =item L<DBIx::Class::SQLAHacks> - Parent module
153 =item L<DBIx::Class> - Duh
159 Justin Wheeler C<< <jwheeler@datademons.com> >>
163 David Jack Olrik C<< <djo@cpan.org> >>
167 This module is licensed under the same terms as Perl itself.