X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F73oracle.t;h=c13dfaa0ac7733b390330525647f9543d97d6765;hb=0424d17af479679e643a7600078c310a032f46fd;hp=6c2860759c692fa1308764c57b8da19442532c03;hpb=d815b6a502529d2ba0804d86d25e648d1a0f7631;p=dbsrgits%2FDBIx-Class.git diff --git a/t/73oracle.t b/t/73oracle.t index 6c28607..c13dfaa 100644 --- a/t/73oracle.t +++ b/t/73oracle.t @@ -92,7 +92,7 @@ $dbh->do(qq{ }); $dbh->do(qq{ CREATE OR REPLACE TRIGGER cd_insert_trg - BEFORE INSERT ON cd + BEFORE INSERT OR UPDATE ON cd FOR EACH ROW BEGIN IF :new.cdid IS NULL THEN @@ -343,13 +343,16 @@ if ( $schema->storage->isa('DBIx::Class::Storage::DBI::Oracle::Generic') ) { $schema->resultset('Artist')->create ({ name => 'root', + rank => 1, cds => [], children => [ { name => 'child1', + rank => 2, children => [ { name => 'grandchild', + rank => 3, cds => [ { title => "grandchilds's cd" , @@ -365,6 +368,7 @@ if ( $schema->storage->isa('DBIx::Class::Storage::DBI::Oracle::Generic') ) { children => [ { name => 'greatgrandchild', + rank => 3, } ], } @@ -372,6 +376,7 @@ if ( $schema->storage->isa('DBIx::Class::Storage::DBI::Oracle::Generic') ) { }, { name => 'child2', + rank => 3, }, ], }); @@ -623,6 +628,36 @@ if ( $schema->storage->isa('DBIx::Class::Storage::DBI::Oracle::Generic') ) { is( $rs->count, 2, 'Connect By; LIMIT count ok' ); } + # combine a connect_by with group_by and having + { + my $rs = $schema->resultset('Artist')->search({}, { + select => ['count(rank)'], + start_with => { name => 'root' }, + connect_by => { parentid => { -prior => \ 'artistid' } }, + group_by => ['rank'], + having => { 'count(rank)' => { '<', 2 } }, + }); + + is_same_sql_bind ( + $rs->as_query, + '( + SELECT count(rank) + FROM artist me + START WITH name = ? + CONNECT BY parentid = PRIOR artistid + GROUP BY rank HAVING count(rank) < ? + )', + [ [ name => 'root' ], [ 'count(rank)' => 2 ] ], + ); + + is_deeply ( + [ $rs->get_column ('count(rank)')->all ], + [1, 1], + 'Group By a Connect By query - correct values' + ); + } + + # select the whole cycle tree without nocylce { my $rs = $schema->resultset('Artist')->search({}, { @@ -640,10 +675,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 (