From: Peter Rabbitson Date: Fri, 6 Mar 2009 22:06:23 +0000 (+0000) Subject: Illustration for rob X-Git-Tag: v0.08240~42 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28fddc39e4fe87002d2a0044462692d198b950f8;p=dbsrgits%2FDBIx-Class.git Illustration for rob --- diff --git a/t/prefetch/multiple_hasmany.t b/t/prefetch/multiple_hasmany.t index 9f858fb..b1faf34 100644 --- a/t/prefetch/multiple_hasmany.t +++ b/t/prefetch/multiple_hasmany.t @@ -17,19 +17,8 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 16 ); -} - -# figure out if we've got a version of sqlite that is older than 3.2.6, in -# which case COUNT(DISTINCT()) doesn't work -my $is_broken_sqlite = 0; -my ($sqlite_major_ver,$sqlite_minor_ver,$sqlite_patch_ver) = - split /\./, $schema->storage->dbh->get_info(18); -if( $schema->storage->dbh->get_info(17) eq 'SQLite' && - ( ($sqlite_major_ver < 3) || - ($sqlite_major_ver == 3 && $sqlite_minor_ver < 2) || - ($sqlite_major_ver == 3 && $sqlite_minor_ver == 2 && $sqlite_patch_ver < 6) ) ) { - $is_broken_sqlite = 1; +# : ( tests => 16 ); + : 'no_plan'; } # once the following TODO is complete, remove the 2 warning tests immediately @@ -129,6 +118,56 @@ my $w; } } + +# Illustration purposes only + +{ + package Inf::Dump; + sub inflate_result { + return [ @_[2,3] ]; + } +} + +my $cd = $schema->resultset ('CD')->create ({ + artist => 1, + title => 'bad cd', + year => 1313, + tags => [ map { { tag => "bad tag $_" } } (1 .. 3) ], + tracks => [ + { title => 'bad track 1', cd_single => { + artist => 1, + title => 'bad_single', + year => 1313, + }}, + map { { title => "bad track $_" } } (2 .. 3), + ], +}); + +my $rs = $schema->resultset ('CD')->search ( + { 'me.cdid' => $cd->id }, + { prefetch => [ 'tags', { tracks => 'cd_single' } ], result_class => 'Inf::Dump' }, +); + +use Text::Table; +my $query = ${$rs->as_query}->[0]; +my ($cols) = ( $query =~ /SELECT (.+) FROM/); +my $tb = Text::Table->new (map { $_ => \ ' | ' } (split /,\s*/, $cols) ); + +my $c = $rs->cursor; +while (my @stuff = $c->next) { + $tb->add (map { defined $_ ? $_ : 'NULL' } (@stuff) ); +} + +$rs->reset; +note Dumper [ + "\n$query", + "\n$tb", + $rs->next +]; + + + + __END__ The solution is to rewrite ResultSet->_collapse_result() and ResultSource->resolve_prefetch() to focus on the final results from the collapse