use base qw( DBIx::Class::SQLAHacks );
use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
-#
-# TODO:
-# - Review by experienced DBIC/SQL:A developers :-)
-# - Problem with count and connect_by look the TODO in t/73oracle.t
-# - Rename option nocycle to connect_by_nocycle
-#
-
sub new {
my $self = shift;
my %opts = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_;
$self->SUPER::new (\%opts);
}
-sub select {
- my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
-
- my ($sql, @bind) = $self->SUPER::select($table, $fields, $where, $rs_attrs, @rest);
- push @bind, @{$self->{_oracle_connect_by_binds}};
-
- return wantarray ? ($sql, @bind) : $sql;
+sub _assemble_binds {
+ my $self = shift;
+ return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/from where oracle_connect_by having order/);
}
-sub _emulate_limit {
- my ( $self, $syntax, $sql, $rs_attrs, $rows, $offset ) = @_;
+
+sub _parse_rs_attrs {
+ my $self = shift;
+ my ($rs_attrs) = @_;
my ($cb_sql, @cb_bind) = $self->_connect_by($rs_attrs);
- $sql .= $cb_sql;
- $self->{_oracle_connect_by_binds} = \@cb_bind;
+ push @{$self->{oracle_connect_by_bind}}, @cb_bind;
+
+ my $sql = $self->SUPER::_parse_rs_attrs(@_);
- return $self->SUPER::_emulate_limit($syntax, $sql, $rs_attrs, $rows, $offset);
+ return "$cb_sql $sql";
}
sub _connect_by {
$sql .= $self->_sqlcase(' start with ') . $ws;
push @bind, @wb;
}
- if ( my $connect_by = $attrs->{'connect_by'} ) {
- my ($connect_by_sql, @connect_by_sql_bind) = $self->_recurse_where( $attrs->{'connect_by'} );
+ if ( my $connect_by = $attrs->{'connect_by'} || $attrs->{'connect_by_nocycle'} ) {
+ my ($connect_by_sql, @connect_by_sql_bind) = $self->_recurse_where( $connect_by );
$sql .= sprintf(" %s %s",
- ( $attrs->{'nocycle'} ) ? $self->_sqlcase('connect by nocycle')
+ ( $attrs->{'connect_by_nocycle'} ) ? $self->_sqlcase('connect by nocycle')
: $self->_sqlcase('connect by'),
$connect_by_sql,
);
push @bind, @connect_by_sql_bind;
- # $sql .= $self->_sqlcase(' connect by');
- # foreach my $key ( keys %$connect_by ) {
- # $sql .= " $key = " . $connect_by->{$key};
- # }
}
if ( $attrs->{'order_siblings_by'} ) {
$sql .= $self->_order_siblings_by( $attrs->{'order_siblings_by'} );