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 # - Check NOCYCLE parameter
12 # http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/pseudocolumns001.htm#i1009434
16 my ($self, $table, $fields, $where, $order, @rest) = @_;
18 $self->{_db_specific_attrs} = pop @rest;
20 my ($sql, @bind) = $self->SUPER::select($table, $fields, $where, $order, @rest);
21 push @bind, @{$self->{_oracle_connect_by_binds}};
23 return wantarray ? ($sql, @bind) : $sql;
27 my ( $self, $syntax, $sql, $order, $rows, $offset ) = @_;
29 my ($cb_sql, @cb_bind) = $self->_connect_by();
31 $self->{_oracle_connect_by_binds} = \@cb_bind;
33 return $self->SUPER::_emulate_limit($syntax, $sql, $order, $rows, $offset);
38 my $attrs = $self->{_db_specific_attrs};
42 if ( ref($attrs) eq 'HASH' ) {
43 if ( $attrs->{'start_with'} ) {
44 my ($ws, @wb) = $self->_recurse_where( $attrs->{'start_with'} );
45 $sql .= $self->_sqlcase(' start with ') . $ws;
48 if ( my $connect_by = $attrs->{'connect_by'}) {
49 my ($connect_by_sql, @connect_by_sql_bind) = $self->_recurse_where( $attrs->{'connect_by'} );
50 $sql .= sprintf(" %s %s",
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.