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 if (ref($table) eq 'ARRAY') {
17 $where = $self->_oracle_joins($where, @{ $table });
20 return $self->SUPER::select($table, $fields, $where, $order, @rest);
24 my ($self, $from, @join) = @_;
26 my @sqlf = $self->_make_as($from);
28 foreach my $j (@join) {
29 my ($to, $on) = @{ $j };
31 if (ref $to eq 'ARRAY') {
32 push (@sqlf, $self->_recurse_from(@{ $to }));
35 push (@sqlf, $self->_make_as($to));
39 return join q{, }, @sqlf;
43 my ($self, $where, $from, @join) = @_;
45 $self->_recurse_oracle_joins($join_where, $from, @join);
46 if (keys %$join_where) {
47 if (!defined($where)) {
50 if (ref($where) eq 'ARRAY') {
51 $where = { -or => $where };
53 $where = { -and => [ $join_where, $where ] };
59 sub _recurse_oracle_joins {
60 my ($self, $where, $from, @join) = @_;
62 foreach my $j (@join) {
63 my ($to, $on) = @{ $j };
65 if (ref $to eq 'ARRAY') {
66 $self->_recurse_oracle_joins($where, @{ $to });
69 my $to_jt = ref $to eq 'ARRAY' ? $to->[0] : $to;
73 if (ref $to_jt eq 'HASH' and exists $to_jt->{-join_type}) {
74 #TODO: Support full outer joins -- this would happen much earlier in
75 #the sequence since oracle 8's full outer join syntax is best
77 die "Can't handle full outer joins in Oracle 8 yet!\n"
78 if $to_jt->{-join_type} =~ /full/i;
80 $left_join = q{(+)} if $to_jt->{-join_type} =~ /left/i
81 && $to_jt->{-join_type} !~ /inner/i;
83 $right_join = q{(+)} if $to_jt->{-join_type} =~ /right/i
84 && $to_jt->{-join_type} !~ /inner/i;
87 foreach my $lhs (keys %{ $on }) {
88 $where->{$lhs . $left_join} = \"= $on->{ $lhs }$right_join";
97 unless ($self->_sql_maker) {
99 new DBIC::SQL::Abstract::Oracle( $self->_sql_maker_args )
103 return $self->_sql_maker;
114 DBIx::Class::Storage::DBI::Oracle::WhereJoins - Oracle joins in WHERE syntax
115 support (instead of ANSI).
119 This module was originally written to support Oracle < 9i where ANSI joins
120 weren't supported at all, but became the module for Oracle >= 8 because
121 Oracle's optimising of ANSI joins is horrible. (See:
122 http://scsys.co.uk:8001/7495)
126 DBIx::Class should automagically detect Oracle and use this module with no
131 This class implements Oracle's WhereJoin support. Instead of:
133 SELECT x FROM y JOIN z ON y.id = z.id
137 SELECT x FROM y, z WHERE y.id = z.id
139 It should properly support left joins, and right joins. Full outer joins are
140 not possible due to the fact that Oracle requires the entire query be written
141 to union the results of a left and right join, and by the time this module is
142 called to create the where query and table definition part of the sql query,
143 it's already too late.
147 This module replaces a subroutine contained in DBIC::SQL::Abstract:
155 It also creates a new module in its BEGIN { } block called
156 DBIC::SQL::Abstract::Oracle which has the following methods:
160 =item select ($\@$;$$@)
162 Replaces DBIC::SQL::Abstract's select() method, which calls _oracle_joins()
163 to modify the column and table list before calling SUPER::select().
165 =item _recurse_from ($$\@)
167 Recursive subroutine that builds the table list.
169 =item _oracle_joins ($$$@)
171 Creates the left/right relationship in the where query.
177 Does not support full outer joins.
184 =item L<DBIC::SQL::Abstract>
186 =item L<DBIx::Class::Storage::DBI::Oracle::Generic>
194 Justin Wheeler C<< <jwheeler@datademons.com> >>
198 David Jack Olrik C<< <djo@cpan.org> >>
202 This module is licensed under the same terms as Perl itself.