X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F47bind_attribute.t;h=be662a2da1d45223c55054fa46fe264339007b34;hb=d759a1ee6f8a74f6439ad1f4fb52c2fe571c48b1;hp=afc5b1a4c6a1d1e4b7c462013076b84c02f32115;hpb=1c133e22c6e3f2701e057ee4f486f1fcaffe8428;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/47bind_attribute.t b/t/47bind_attribute.t index afc5b1a..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,12 +55,12 @@ 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_source('Complex' => $new_source); +$schema->register_extra_source('Complex' => $new_source); $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] }); is ( $rs->count, 1, 'cookbook arbitrary sql example' ); @@ -72,6 +72,21 @@ $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] }) ->search({ 'artistid' => 1 }); is ( $rs->count, 1, '...cookbook (bind first) + chained search' ); +{ + $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 ] })