From: Justin Hunter Date: Fri, 1 May 2009 17:37:04 +0000 (+0000) Subject: make sure merge bind X-Git-Tag: v0.08103~101^2~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=07a287ced6e57fabab6c2f9f0b6177c91f983a14;p=dbsrgits%2FDBIx-Class.git make sure merge bind test for aformentioned TODO count_joined test for a little while --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 1c89e68..085e643 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -307,7 +307,7 @@ sub search_rs { my $new_attrs = { %{$our_attrs}, %{$attrs} }; # merge new attrs into inherited - foreach my $key (qw/join prefetch +select +as/) { + foreach my $key (qw/join prefetch +select +as bind/) { next unless exists $attrs->{$key}; $new_attrs->{$key} = $self->_merge_attr($our_attrs->{$key}, $attrs->{$key}); } diff --git a/t/47bind_attribute.t b/t/47bind_attribute.t index 3bc1935..be662a2 100644 --- a/t/47bind_attribute.t +++ b/t/47bind_attribute.t @@ -3,7 +3,9 @@ use warnings; use Test::More; use lib qw(t/lib); -use DBICTest; +use DBIC::SqlMakerTest; + +use_ok('DBICTest'); my $schema = DBICTest->init_schema; @@ -11,11 +13,9 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 7 ); + : ( tests => 9 ); } -### $schema->storage->debug(1); - my $where_bind = { where => \'name like ?', bind => [ 'Cat%' ], @@ -55,10 +55,10 @@ my $new_source = $source->new($source); $new_source->source_name('Complex'); $new_source->name(\<<''); -( select a.*, cd.cdid as cdid, cd.title as title, cd.year as year - from artist a - join cd on cd.artist=a.artistid - where cd.year=?) +( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year + FROM artist a + JOIN cd ON cd.artist = a.artistid + WHERE cd.year = ?) $schema->register_extra_source('Complex' => $new_source); @@ -72,11 +72,22 @@ $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] }) ->search({ 'artistid' => 1 }); is ( $rs->count, 1, '...cookbook (bind first) + chained search' ); -TODO: { - # not sure what causes an uninit warning here, please remove when the TODO starts to pass, - # so the real reason for the warning can be found and fixed - local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /uninitialized/ }; +{ + $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })->search({}, { where => \"title LIKE ?", bind => [ 'Spoon%' ] }); + my ($sql, @bind) = @${$rs->as_query}; + is_same_sql_bind( + $sql, \@bind, + "(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) WHERE title LIKE ?)", + [ + [ '!!dummy' => '1999' ], + [ '!!dummy' => 'Spoon%' ] + ], + 'got correct SQL' +); +} + +TODO: { local $TODO = 'bind args order needs fixing (semifor)'; $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] }) ->search({ 'artistid' => 1 }, { diff --git a/t/count/count_joined.t b/t/count/count_joined.t index db69ba6..5f5fa33 100644 --- a/t/count/count_joined.t +++ b/t/count/count_joined.t @@ -11,5 +11,8 @@ plan tests => 1; my $schema = DBICTest->init_schema(); -my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } }); -is($cds->count, 1, "extra joins do not explode single entity count"); +TODO: { + local $TODO = 'TODO until we figure out what we really want'; + my $cds = $schema->resultset("CD")->search({ cdid => 1 }, { join => { cd_to_producer => 'producer' } }); + is($cds->count, 1, "extra joins do not explode single entity count"); +}