1 package DBIx::Class::Storage::DBI::Oracle::WhereJoins;
3 use base qw( DBIx::Class::Storage::DBI::Oracle::Generic );
8 __PACKAGE__->sql_maker_class('DBIC::SQL::Abstract::Oracle');
11 package DBIC::SQL::Abstract::Oracle;
13 use base qw( DBIC::SQL::Abstract );
16 my ($self, $table, $fields, $where, $order, @rest) = @_;
18 if (ref($table) eq 'ARRAY') {
19 $where = $self->_oracle_joins($where, @{ $table });
22 return $self->SUPER::select($table, $fields, $where, $order, @rest);
26 my ($self, $from, @join) = @_;
28 my @sqlf = $self->_make_as($from);
30 foreach my $j (@join) {
31 my ($to, $on) = @{ $j };
33 if (ref $to eq 'ARRAY') {
34 push (@sqlf, $self->_recurse_from(@{ $to }));
37 push (@sqlf, $self->_make_as($to));
41 return join q{, }, @sqlf;
45 my ($self, $where, $from, @join) = @_;
47 $self->_recurse_oracle_joins($join_where, $from, @join);
48 if (keys %$join_where) {
49 if (!defined($where)) {
52 if (ref($where) eq 'ARRAY') {
53 $where = { -or => $where };
55 $where = { -and => [ $join_where, $where ] };
61 sub _recurse_oracle_joins {
62 my ($self, $where, $from, @join) = @_;
64 foreach my $j (@join) {
65 my ($to, $on) = @{ $j };
67 if (ref $to eq 'ARRAY') {
68 $self->_recurse_oracle_joins($where, @{ $to });
71 my $to_jt = ref $to eq 'ARRAY' ? $to->[0] : $to;
75 if (ref $to_jt eq 'HASH' and exists $to_jt->{-join_type}) {
76 #TODO: Support full outer joins -- this would happen much earlier in
77 #the sequence since oracle 8's full outer join syntax is best
79 die "Can't handle full outer joins in Oracle 8 yet!\n"
80 if $to_jt->{-join_type} =~ /full/i;
82 $left_join = q{(+)} if $to_jt->{-join_type} =~ /left/i
83 && $to_jt->{-join_type} !~ /inner/i;
85 $right_join = q{(+)} if $to_jt->{-join_type} =~ /right/i
86 && $to_jt->{-join_type} !~ /inner/i;
89 foreach my $lhs (keys %{ $on }) {
90 $where->{$lhs . $left_join} = \"= $on->{ $lhs }$right_join";
104 DBIx::Class::Storage::DBI::Oracle::WhereJoins - Oracle joins in WHERE syntax
105 support (instead of ANSI).
109 This module was originally written to support Oracle < 9i where ANSI joins
110 weren't supported at all, but became the module for Oracle >= 8 because
111 Oracle's optimising of ANSI joins is horrible. (See:
112 http://scsys.co.uk:8001/7495)
116 DBIx::Class should automagically detect Oracle and use this module with no
121 This class implements Oracle's WhereJoin support. Instead of:
123 SELECT x FROM y JOIN z ON y.id = z.id
127 SELECT x FROM y, z WHERE y.id = z.id
129 It should properly support left joins, and right joins. Full outer joins are
130 not possible due to the fact that Oracle requires the entire query be written
131 to union the results of a left and right join, and by the time this module is
132 called to create the where query and table definition part of the sql query,
133 it's already too late.
137 This module replaces a subroutine contained in DBIC::SQL::Abstract:
145 It also creates a new module in its BEGIN { } block called
146 DBIC::SQL::Abstract::Oracle which has the following methods:
150 =item select ($\@$;$$@)
152 Replaces DBIC::SQL::Abstract's select() method, which calls _oracle_joins()
153 to modify the column and table list before calling SUPER::select().
155 =item _recurse_from ($$\@)
157 Recursive subroutine that builds the table list.
159 =item _oracle_joins ($$$@)
161 Creates the left/right relationship in the where query.
167 Does not support full outer joins.
174 =item L<DBIC::SQL::Abstract>
176 =item L<DBIx::Class::Storage::DBI::Oracle::Generic>
184 Justin Wheeler C<< <jwheeler@datademons.com> >>
188 David Jack Olrik C<< <djo@cpan.org> >>
192 This module is licensed under the same terms as Perl itself.