1 package # Hide from PAUSE
2 DBIx::Class::SQLAHacks::Oracle;
4 use base qw( DBIx::Class::SQLAHacks );
5 use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
9 # - Check the parameter syntax of connect_by
10 # - Review by experienced DBIC/SQL:A developers :-)
11 # - Problem with count and connect_by look the TODO in t/73oracle.t
15 my ($self, $table, $fields, $where, $order, @rest) = @_;
17 $self->{_db_specific_attrs} = pop @rest;
19 my ($sql, @bind) = $self->SUPER::select($table, $fields, $where, $order, @rest);
20 push @bind, @{$self->{_oracle_connect_by_binds}};
22 return wantarray ? ($sql, @bind) : $sql;
26 my ( $self, $syntax, $sql, $order, $rows, $offset ) = @_;
28 my ($cb_sql, @cb_bind) = $self->_connect_by();
30 $self->{_oracle_connect_by_binds} = \@cb_bind;
32 return $self->SUPER::_emulate_limit($syntax, $sql, $order, $rows, $offset);
37 my $attrs = $self->{_db_specific_attrs};
41 if ( ref($attrs) eq 'HASH' ) {
42 if ( $attrs->{'start_with'} ) {
43 my ($ws, @wb) = $self->_recurse_where( $attrs->{'start_with'} );
44 $sql .= $self->_sqlcase(' start with ') . $ws;
47 if ( my $connect_by = $attrs->{'connect_by'} ) {
48 my ($connect_by_sql, @connect_by_sql_bind) = $self->_recurse_where( $attrs->{'connect_by'} );
49 $sql .= sprintf(" %s %s",
50 ( $attrs->{'nocycle'} ) ? $self->_sqlcase('connect by nocycle')
51 : $self->_sqlcase('connect by'),
54 push @bind, @connect_by_sql_bind;
55 # $sql .= $self->_sqlcase(' connect by');
56 # foreach my $key ( keys %$connect_by ) {
57 # $sql .= " $key = " . $connect_by->{$key};
60 if ( $attrs->{'order_siblings_by'} ) {
61 $sql .= $self->_order_siblings_by( $attrs->{'order_siblings_by'} );
65 return wantarray ? ($sql, @bind) : $sql;
68 sub _order_siblings_by {
69 my ( $self, $arg ) = @_;
72 for my $c ( $self->_order_by_chunks($arg) ) {
73 $self->_SWITCH_refkind(
76 SCALAR => sub { push @sql, $c },
77 ARRAYREF => sub { push @sql, shift @$c; push @bind, @$c },
84 ? sprintf( '%s %s', $self->_sqlcase(' order siblings by'), join( ', ', @sql ) )
87 return wantarray ? ( $sql, @bind ) : $sql;
98 DBIx::Class::SQLAHacks::Oracle - adds hierarchical query support for Oracle to SQL::Abstract
102 See L<DBIx::Class::Storage::DBI::Oracle::Generic> for more informations about
103 how to use hierarchical queries with DBIx::Class.