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 # Hide from PAUSE
12 DBIC::SQL::Abstract::Oracle;
14 use base qw( DBIC::SQL::Abstract );
17 my ($self, $table, $fields, $where, $order, @rest) = @_;
19 if (ref($table) eq 'ARRAY') {
20 $where = $self->_oracle_joins($where, @{ $table });
23 return $self->SUPER::select($table, $fields, $where, $order, @rest);
27 my ($self, $from, @join) = @_;
29 my @sqlf = $self->_make_as($from);
31 foreach my $j (@join) {
32 my ($to, $on) = @{ $j };
34 if (ref $to eq 'ARRAY') {
35 push (@sqlf, $self->_recurse_from(@{ $to }));
38 push (@sqlf, $self->_make_as($to));
42 return join q{, }, @sqlf;
46 my ($self, $where, $from, @join) = @_;
48 $self->_recurse_oracle_joins($join_where, $from, @join);
49 if (keys %$join_where) {
50 if (!defined($where)) {
53 if (ref($where) eq 'ARRAY') {
54 $where = { -or => $where };
56 $where = { -and => [ $join_where, $where ] };
62 sub _recurse_oracle_joins {
63 my ($self, $where, $from, @join) = @_;
65 foreach my $j (@join) {
66 my ($to, $on) = @{ $j };
68 if (ref $to eq 'ARRAY') {
69 $self->_recurse_oracle_joins($where, @{ $to });
72 my $to_jt = ref $to eq 'ARRAY' ? $to->[0] : $to;
76 if (ref $to_jt eq 'HASH' and exists $to_jt->{-join_type}) {
77 #TODO: Support full outer joins -- this would happen much earlier in
78 #the sequence since oracle 8's full outer join syntax is best
80 die "Can't handle full outer joins in Oracle 8 yet!\n"
81 if $to_jt->{-join_type} =~ /full/i;
83 $left_join = q{(+)} if $to_jt->{-join_type} =~ /left/i
84 && $to_jt->{-join_type} !~ /inner/i;
86 $right_join = q{(+)} if $to_jt->{-join_type} =~ /right/i
87 && $to_jt->{-join_type} !~ /inner/i;
90 foreach my $lhs (keys %{ $on }) {
91 $where->{$lhs . $left_join} = \"= $on->{ $lhs }$right_join";
105 DBIx::Class::Storage::DBI::Oracle::WhereJoins - Oracle joins in WHERE syntax
106 support (instead of ANSI).
110 This module was originally written to support Oracle < 9i where ANSI joins
111 weren't supported at all, but became the module for Oracle >= 8 because
112 Oracle's optimising of ANSI joins is horrible. (See:
113 http://scsys.co.uk:8001/7495)
117 DBIx::Class should automagically detect Oracle and use this module with no
122 This class implements Oracle's WhereJoin support. Instead of:
124 SELECT x FROM y JOIN z ON y.id = z.id
128 SELECT x FROM y, z WHERE y.id = z.id
130 It should properly support left joins, and right joins. Full outer joins are
131 not possible due to the fact that Oracle requires the entire query be written
132 to union the results of a left and right join, and by the time this module is
133 called to create the where query and table definition part of the sql query,
134 it's already too late.
138 This module replaces a subroutine contained in DBIC::SQL::Abstract:
146 It also creates a new module in its BEGIN { } block called
147 DBIC::SQL::Abstract::Oracle which has the following methods:
151 =item select ($\@$;$$@)
153 Replaces DBIC::SQL::Abstract's select() method, which calls _oracle_joins()
154 to modify the column and table list before calling SUPER::select().
156 =item _recurse_from ($$\@)
158 Recursive subroutine that builds the table list.
160 =item _oracle_joins ($$$@)
162 Creates the left/right relationship in the where query.
168 Does not support full outer joins.
175 =item L<DBIC::SQL::Abstract>
177 =item L<DBIx::Class::Storage::DBI::Oracle::Generic>
185 Justin Wheeler C<< <jwheeler@datademons.com> >>
189 David Jack Olrik C<< <djo@cpan.org> >>
193 This module is licensed under the same terms as Perl itself.