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);
29 return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/from where oracle_connect_by having order/);
34 my ( $self, $syntax, $sql, $rs_attrs, $rows, $offset ) = @_;
36 my ($cb_sql, @cb_bind) = $self->_connect_by($rs_attrs);
38 $self->{oracle_connect_by_bind} = \@cb_bind;
40 return $self->SUPER::_emulate_limit($syntax, $sql, $rs_attrs, $rows, $offset);
44 my ($self, $attrs) = @_;
49 if ( ref($attrs) eq 'HASH' ) {
50 if ( $attrs->{'start_with'} ) {
51 my ($ws, @wb) = $self->_recurse_where( $attrs->{'start_with'} );
52 $sql .= $self->_sqlcase(' start with ') . $ws;
55 if ( my $connect_by = $attrs->{'connect_by'} || $attrs->{'connect_by_nocycle'} ) {
56 my ($connect_by_sql, @connect_by_sql_bind) = $self->_recurse_where( $connect_by );
57 $sql .= sprintf(" %s %s",
58 ( $attrs->{'connect_by_nocycle'} ) ? $self->_sqlcase('connect by nocycle')
59 : $self->_sqlcase('connect by'),
62 push @bind, @connect_by_sql_bind;
64 if ( $attrs->{'order_siblings_by'} ) {
65 $sql .= $self->_order_siblings_by( $attrs->{'order_siblings_by'} );
69 return wantarray ? ($sql, @bind) : $sql;
72 sub _order_siblings_by {
73 my ( $self, $arg ) = @_;
76 for my $c ( $self->_order_by_chunks($arg) ) {
77 $self->_SWITCH_refkind(
80 SCALAR => sub { push @sql, $c },
81 ARRAYREF => sub { push @sql, shift @$c; push @bind, @$c },
88 ? sprintf( '%s %s', $self->_sqlcase(' order siblings by'), join( ', ', @sql ) )
91 return wantarray ? ( $sql, @bind ) : $sql;
94 # we need to add a '=' only when PRIOR is used against a column diretly
95 # i.e. when it is invoked by a special_op callback
96 sub _where_field_PRIOR {
97 my ($self, $lhs, $op, $rhs) = @_;
98 my ($sql, @bind) = $self->_recurse_where ($rhs);
100 $sql = sprintf ('%s = %s %s ',
101 $self->_convert($self->_quote($lhs)),
102 $self->_sqlcase ($op),
106 return ($sql, @bind);
117 DBIx::Class::SQLAHacks::Oracle - adds hierarchical query support for Oracle to SQL::Abstract
121 See L<DBIx::Class::Storage::DBI::Oracle::Generic> for more informations about
122 how to use hierarchical queries with DBIx::Class.