From: Devin Austin Date: Mon, 16 Apr 2012 17:46:44 +0000 (-0700) Subject: committing for review X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e46bcbe9ba3da50494a0666efb76156ebd80c4a1;p=dbsrgits%2FDBIx-Class.git committing for review --- diff --git a/lib/DBIx/Class/SQLMaker/PostgreSQL.pm b/lib/DBIx/Class/SQLMaker/PostgreSQL.pm index 23083ea..432344c 100644 --- a/lib/DBIx/Class/SQLMaker/PostgreSQL.pm +++ b/lib/DBIx/Class/SQLMaker/PostgreSQL.pm @@ -8,6 +8,10 @@ use base qw( DBIx::Class::SQLMaker ); sub new { my $self = shift; my %opts = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_; + push @{$opts{special_ops}}, { + regex => qr/^with_recursive$/i, + handler => '_with_recursive', + }; $self->next::method(\%opts); } @@ -20,6 +24,7 @@ sub _assemble_binds { sub _parse_rs_attrs { my $self = shift; + warn "INSIDE RS ATTRS"; my ($rs_attrs) = @_; my ($cb_sql, @cb_bind) = $self->_with_recursive($rs_attrs); @@ -30,14 +35,10 @@ sub _parse_rs_attrs { return "$cb_sql $sql"; } -# with_recursive =>{ -# -columns => [ ... ], -# -nrt => $blargh->search.... -# -rt => $blargh->search... -# -union_all 1|0 sub _with_recursive { my ($self, $attrs) = @_; + warn "INSIDE WITH RECURSIVE"; my $sql = ''; my @bind; @@ -45,8 +46,8 @@ sub _with_recursive { if ( $attrs->{'with_recursive'} ) { my $with_recursive = $attrs->{'with_recursive'}; my @fields = @{$with_recursive->{'-columns'}}; - my $nrt = $with_recursive->{'-nrt'}; - my $rt = $with_recursive->{'-rt'}; + my $nrt = $with_recursive->{'-initial'}; + my $rt = $with_recursive->{'-recursive'}; my $union = $with_recursive->{'-union_all'}; # my ($wr, @wb) = $self->_recurse_where( $attrs->{'with_recursive'} ); my ($with_nrt_sql, @with_nrt_bind) = $nrt->as_query; @@ -56,10 +57,10 @@ sub _with_recursive { $sql .= $self->_sqlcase(' with recursive ') . ' temp_wr_query ' . '(' . join(', ', @fields) . ') ' . $self->_sqlcase('as') . ' ( '; $sql .= $with_nrt_sql; - $sql .= $self->_sqlcase(' union all '); + $sql .= $self->_sqlcase(' union all ') if $union; $sql .= $with_rt_sql; $sql .= ' ) '; - + warn "SQL $sql"; return ($sql, @bind); } } diff --git a/t/pg_with_recursive.t b/t/pg_with_recursive.t index f03307d..fac97d4 100644 --- a/t/pg_with_recursive.t +++ b/t/pg_with_recursive.t @@ -92,6 +92,19 @@ do_creates($dbh); $schema->resultset('Artist')->find({ name => 'cycle-root' }) ->update({ parentid => { -ident => 'artistid' } }); + + # begin tests + { + my $search_stuff = { + with_recursive => { + -columns => [qw( artistid parentid name rank )], + -initial => $schema->resultset('Artist')->find({ name => 'root' }), + -recursive => $schema->resultset('Artist')->search({}), + } + }; + # select the whole tree + my $rs = $schema->resultset('Artist')->search({}, $search_stuff); + } } sub do_creates {