From: Robert Bohne Date: Fri, 14 May 2010 22:02:41 +0000 (+0000) Subject: Use connect_by OR connect_by_nocycle X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b2fbbf0102269df6dac9178697467eb5d3dd8e6;p=dbsrgits%2FDBIx-Class-Historic.git Use connect_by OR connect_by_nocycle --- diff --git a/lib/DBIx/Class/SQLAHacks/Oracle.pm b/lib/DBIx/Class/SQLAHacks/Oracle.pm index a73137a..b91eb67 100644 --- a/lib/DBIx/Class/SQLAHacks/Oracle.pm +++ b/lib/DBIx/Class/SQLAHacks/Oracle.pm @@ -55,18 +55,14 @@ 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->{'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'} ); diff --git a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm index 9ab80bf..eb6d6f6 100644 --- a/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm +++ b/lib/DBIx/Class/Storage/DBI/Oracle/Generic.pm @@ -421,7 +421,7 @@ sub with_deferred_fk_checks { Following additional attributes can be used in resultsets. -=head2 connect_by +=head2 connect_by or connect_by_nocycle =over 4 @@ -432,6 +432,7 @@ Following additional attributes can be used in resultsets. A hashref of conditions used to specify the relationship between parent rows and child rows of the hierarchy. + connect_by => { parentid => 'prior personid' } # adds a connect by statement to the query: @@ -441,27 +442,17 @@ and child rows of the hierarchy. # person me # CONNECT BY # parentid = prior persionid + -=head2 connect_by_nocycle - -=over 4 - -=item Value: [1|0] - -=back - -If you want to use NOCYCLE set to 1. + connect_by_nocycle => { parentid => 'prior personid' } - connect_by => { parentid => 'prior personid' }, - connect_by_nocycle => 1 - - # adds a connect by statement to the query: - # SELECT - # me.persionid me.firstname, me.lastname, me.parentid - # FROM - # person me - # CONNECT BY NOCYCLE - # parentid = prior persionid + # adds a connect by statement to the query: + # SELECT + # me.persionid me.firstname, me.lastname, me.parentid + # FROM + # person me + # CONNECT BY NOCYCLE + # parentid = prior persionid =head2 start_with diff --git a/t/73oracle.t b/t/73oracle.t index 6c28607..2a89880 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -640,10 +640,9 @@ if ( $schema->storage->isa('DBIx::Class::Storage::DBI::Oracle::Generic') ) { # select the whole cycle tree with nocylce { my $rs = $schema->resultset('Artist')->search({}, { - connect_by_nocycle => 1, start_with => { name => 'cycle-root' }, '+select' => [ \ 'CONNECT_BY_ISCYCLE' ], - connect_by => { parentid => { -prior => \ 'artistid' } }, + connect_by_nocycle => { parentid => { -prior => \ 'artistid' } }, }); is_same_sql_bind (