1 package DBIx::Class::Storage::DBI::Oracle::WhereJoins;
3 use base qw( DBIx::Class::Storage::DBI::Oracle::Generic );
9 package DBIC::SQL::Abstract::Oracle;
11 use base qw( DBIC::SQL::Abstract );
14 my ($self, $table, $fields, $where, $order, @rest) = @_;
16 $self->_oracle_joins($where, @{ $table });
18 return $self->SUPER::select($table, $fields, $where, $order, @rest);
22 my ($self, $from, @join) = @_;
24 my @sqlf = $self->_make_as($from);
26 foreach my $j (@join) {
27 my ($to, $on) = @{ $j };
29 if (ref $to eq 'ARRAY') {
30 push (@sqlf, $self->_recurse_from(@{ $to }));
33 push (@sqlf, $self->_make_as($to));
37 return join q{, }, @sqlf;
41 my ($self, $where, $from, @join) = @_;
43 foreach my $j (@join) {
44 my ($to, $on) = @{ $j };
46 if (ref $to eq 'ARRAY') {
47 $self->_oracle_joins($where, @{ $to });
50 my $to_jt = ref $to eq 'ARRAY' ? $to->[0] : $to;
54 if (ref $to_jt eq 'HASH' and exists $to_jt->{-join_type}) {
55 #TODO: Support full outer joins -- this would happen much earlier in
56 #the sequence since oracle 8's full outer join syntax is best
58 die "Can't handle full outer joins in Oracle 8 yet!\n"
59 if $to_jt->{-join_type} =~ /full/i;
61 $left_join = q{(+)} if $to_jt->{-join_type} =~ /right/i
62 && $to_jt->{-join_type} !~ /inner/i;
64 $right_join = q{(+)} if $to_jt->{-join_type} =~ /left/i
65 && $to_jt->{-join_type} !~ /inner/i;
68 foreach my $lhs (keys %{ $on }) {
69 $where->{$lhs . $left_join} = \" = $on->{ $lhs }$right_join";
78 unless ($self->_sql_maker) {
80 new DBIC::SQL::Abstract::Oracle( $self->_sql_maker_args )
84 return $self->_sql_maker;
95 DBIx::Class::Storage::DBI::Oracle::WhereJoins - Oracle joins in WHERE syntax
96 support (instead of ANSI).
100 This module was originally written to support Oracle < 9i where ANSI joins
101 weren't supported at all, but became the module for Oracle >= 8 because
102 Oracle's optimising of ANSI joins is horrible. (See:
103 http://scsys.co.uk:8001/7495)
107 DBIx::Class should automagically detect Oracle and use this module with no
112 This class implements Oracle's WhereJoin support. Instead of:
114 SELECT x FROM y JOIN z ON y.id = z.id
118 SELECT x FROM y, z WHERE y.id = z.id
120 It should properly support left joins, and right joins. Full outer joins are
121 not possible due to the fact that Oracle requires the entire query be written
122 to union the results of a left and right join, and by the time this module is
123 called to create the where query and table definition part of the sql query,
124 it's already too late.
128 This module replaces a subroutine contained in DBIC::SQL::Abstract:
136 It also creates a new module in its BEGIN { } block called
137 DBIC::SQL::Abstract::Oracle which has the following methods:
141 =item select ($\@$;$$@)
143 Replaces DBIC::SQL::Abstract's select() method, which calls _oracle_joins()
144 to modify the column and table list before calling SUPER::select().
146 =item _recurse_from ($$\@)
148 Recursive subroutine that builds the table list.
150 =item _oracle_joins ($$$@)
152 Creates the left/right relationship in the where query.
158 Does not support full outer joins.
165 =item L<DBIC::SQL::Abstract>
167 =item L<DBIx::Class::Storage::DBI::Oracle::Generic>
175 Justin Wheeler C<< <jwheeler@datademons.com> >>
179 David Jack Olrik C<< <djo@cpan.org> >>
183 This module is licensed under the same terms as Perl itself.