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 my %opts = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
13 push @{$opts{special_ops}}, {
14 regex => qr/^prior$/i,
15 handler => '_where_field_PRIOR',
18 $self->SUPER::new (\%opts);
23 return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/from where oracle_connect_by having order/);
31 my ($cb_sql, @cb_bind) = $self->_connect_by($rs_attrs);
32 push @{$self->{oracle_connect_by_bind}}, @cb_bind;
34 my $sql = $self->SUPER::_parse_rs_attrs(@_);
36 return "$cb_sql $sql";
40 my ($self, $attrs) = @_;
45 if ( ref($attrs) eq 'HASH' ) {
46 if ( $attrs->{'start_with'} ) {
47 my ($ws, @wb) = $self->_recurse_where( $attrs->{'start_with'} );
48 $sql .= $self->_sqlcase(' start with ') . $ws;
51 if ( my $connect_by = $attrs->{'connect_by'} || $attrs->{'connect_by_nocycle'} ) {
52 my ($connect_by_sql, @connect_by_sql_bind) = $self->_recurse_where( $connect_by );
53 $sql .= sprintf(" %s %s",
54 ( $attrs->{'connect_by_nocycle'} ) ? $self->_sqlcase('connect by nocycle')
55 : $self->_sqlcase('connect by'),
58 push @bind, @connect_by_sql_bind;
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;
90 # we need to add a '=' only when PRIOR is used against a column diretly
91 # i.e. when it is invoked by a special_op callback
92 sub _where_field_PRIOR {
93 my ($self, $lhs, $op, $rhs) = @_;
94 my ($sql, @bind) = $self->_recurse_where ($rhs);
96 $sql = sprintf ('%s = %s %s ',
97 $self->_convert($self->_quote($lhs)),
98 $self->_sqlcase ($op),
102 return ($sql, @bind);
113 DBIx::Class::SQLAHacks::Oracle - adds hierarchical query support for Oracle to SQL::Abstract
117 See L<DBIx::Class::Storage::DBI::Oracle::Generic> for more informations about
118 how to use hierarchical queries with DBIx::Class.