1 package # Hide from PAUSE
2 DBIx::Class::SQLAHacks::Oracle;
7 use base qw( DBIx::Class::SQLAHacks );
8 use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
12 # - Review by experienced DBIC/SQL:A developers :-)
13 # - Problem with count and connect_by look the TODO in t/73oracle.t
18 my %opts = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
19 push @{$opts{special_ops}}, {
20 regex => qr/^prior$/i,
21 handler => '_where_field_PRIOR',
24 $self->SUPER::new (\%opts);
28 my ($self, $table, $fields, $where, $order, @rest) = @_;
30 $self->{_db_specific_attrs} = pop @rest;
32 my ($sql, @bind) = $self->SUPER::select($table, $fields, $where, $order, @rest);
33 push @bind, @{$self->{_oracle_connect_by_binds}};
35 return wantarray ? ($sql, @bind) : $sql;
39 my ( $self, $syntax, $sql, $order, $rows, $offset ) = @_;
41 my ($cb_sql, @cb_bind) = $self->_connect_by();
43 $self->{_oracle_connect_by_binds} = \@cb_bind;
45 return $self->SUPER::_emulate_limit($syntax, $sql, $order, $rows, $offset);
50 my $attrs = $self->{_db_specific_attrs};
54 if ( ref($attrs) eq 'HASH' ) {
55 if ( $attrs->{'start_with'} ) {
56 my ($ws, @wb) = $self->_recurse_where( $attrs->{'start_with'} );
57 $sql .= $self->_sqlcase(' start with ') . $ws;
60 if ( my $connect_by = $attrs->{'connect_by'} ) {
61 my ($connect_by_sql, @connect_by_sql_bind) = $self->_recurse_where( $attrs->{'connect_by'} );
62 $sql .= sprintf(" %s %s",
63 ( $attrs->{'nocycle'} ) ? $self->_sqlcase('connect by nocycle')
64 : $self->_sqlcase('connect by'),
67 push @bind, @connect_by_sql_bind;
68 # $sql .= $self->_sqlcase(' connect by');
69 # foreach my $key ( keys %$connect_by ) {
70 # $sql .= " $key = " . $connect_by->{$key};
73 if ( $attrs->{'order_siblings_by'} ) {
74 $sql .= $self->_order_siblings_by( $attrs->{'order_siblings_by'} );
78 return wantarray ? ($sql, @bind) : $sql;
81 sub _order_siblings_by {
82 my ( $self, $arg ) = @_;
85 for my $c ( $self->_order_by_chunks($arg) ) {
86 $self->_SWITCH_refkind(
89 SCALAR => sub { push @sql, $c },
90 ARRAYREF => sub { push @sql, shift @$c; push @bind, @$c },
97 ? sprintf( '%s %s', $self->_sqlcase(' order siblings by'), join( ', ', @sql ) )
100 return wantarray ? ( $sql, @bind ) : $sql;
103 # we need to add a '=' only when PRIOR is used against a column diretly
104 # i.e. when it is invoked by a special_op callback
105 sub _where_field_PRIOR {
106 my ($self, $lhs, $op, $rhs) = @_;
107 my ($sql, @bind) = $self->_recurse_where ($rhs);
109 $sql = sprintf ('%s = %s %s ',
110 $self->_convert($self->_quote($lhs)),
111 $self->_sqlcase ($op),
115 return ($sql, @bind);
126 DBIx::Class::SQLAHacks::Oracle - adds hierarchical query support for Oracle to SQL::Abstract
130 See L<DBIx::Class::Storage::DBI::Oracle::Generic> for more informations about
131 how to use hierarchical queries with DBIx::Class.