X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fresultset%2Fupdate_delete.t;h=a016d46707a1b2dc4bf43f72427c0a23ece3e2c7;hb=d096e13f26c08593a9ba497d562026beffb4f85d;hp=8810418f0e2b18b40b0d9206f78b39741abc1631;hpb=ff1234ad5a7e8074d1d6006f55f5a2add8a23fb7;p=dbsrgits%2FDBIx-Class.git diff --git a/t/resultset/update_delete.t b/t/resultset/update_delete.t index 8810418..a016d46 100644 --- a/t/resultset/update_delete.t +++ b/t/resultset/update_delete.t @@ -5,16 +5,13 @@ use lib qw(t/lib); use Test::More; use Test::Exception; use DBICTest; - -#plan tests => 5; -plan 'no_plan'; +use DBIC::DebugObj; +use DBIC::SqlMakerTest; my $schema = DBICTest->init_schema(); my $tkfks = $schema->resultset('FourKeys_to_TwoKeys'); -warn "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - my ($fa, $fb) = $tkfks->related_resultset ('fourkeys')->populate ([ [qw/foo bar hello goodbye sensors read_count/], [qw/1 1 1 1 a 10 /], @@ -81,8 +78,12 @@ throws_ok ( ); # grouping on PKs only should pass -$sub_rs->search ({}, { group_by => [ reverse $sub_rs->result_source->primary_columns ] }) # reverse to make sure the comaprison works - ->update ({ pilot_sequence => \ 'pilot_sequence + 1' }); +$sub_rs->search ( + {}, + { + group_by => [ reverse $sub_rs->result_source->primary_columns ], # reverse to make sure the PK-list comaprison works + }, +)->update ({ pilot_sequence => \ 'pilot_sequence + 1' }); is_deeply ( [ $tkfks->search ({ autopilot => [qw/a b x y/]}, { order_by => 'autopilot' }) @@ -92,6 +93,50 @@ is_deeply ( 'Only two rows incremented', ); -$sub_rs->delete; +# also make sure weird scalarref usage works (RT#51409) +$tkfks->search ( + \ 'pilot_sequence BETWEEN 11 AND 21', +)->update ({ pilot_sequence => \ 'pilot_sequence + 1' }); +is_deeply ( + [ $tkfks->search ({ autopilot => [qw/a b x y/]}, { order_by => 'autopilot' }) + ->get_column ('pilot_sequence')->all + ], + [qw/12 22 30 40/], + 'Only two rows incremented (where => scalarref works)', +); + +$sub_rs->delete; is ($tkfks->count, $tkfk_cnt -= 2, 'Only two rows deleted'); + +# make sure limit-only deletion works +cmp_ok ($tkfk_cnt, '>', 1, 'More than 1 row left'); +$tkfks->search ({}, { rows => 1 })->delete; +is ($tkfks->count, $tkfk_cnt -= 1, 'Only one row deleted'); + + +# Make sure prefetch is properly stripped too +# check with sql-equality, as sqlite will accept bad sql just fine +my ($sql, @bind); +my $orig_debugobj = $schema->storage->debugobj; +my $orig_debug = $schema->storage->debug; + +$schema->storage->debugobj (DBIC::DebugObj->new (\$sql, \@bind) ); +$schema->storage->debug (1); +$schema->resultset('CD')->search( + { year => { '!=' => 2010 } }, + { prefetch => 'liner_notes' }, +)->delete; + +$schema->storage->debugobj ($orig_debugobj); +$schema->storage->debug ($orig_debug); + +is_same_sql_bind ( + $sql, + \@bind, + 'DELETE FROM cd WHERE ( cdid IN ( SELECT me.cdid FROM cd me WHERE ( year != ? ) GROUP BY me.cdid ) )', + ["'2010'"], + 'Update on prefetching resultset strips prefetch correctly' +); + +done_testing;