X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F71mysql.t;h=2992f95c7d3894c610b64d0dcc3a9af323e4a514;hb=89428546a2960837d82e2d5e6935acdc0eb2f902;hp=84bebc727422e18b1e0d656819d9ff7e72890594;hpb=da6a5860c26c14db6145b7d3ba74bafe6a2a3742;p=dbsrgits%2FDBIx-Class.git diff --git a/t/71mysql.t b/t/71mysql.t index 84bebc7..2992f95 100644 --- a/t/71mysql.t +++ b/t/71mysql.t @@ -411,4 +411,60 @@ ZEROINSEARCH: { ok ($rs->find({ name => "Hardcore Forker $pid" }), 'Expected row created'); } +# Verify that populate in void context uses INSERT INTO foo VALUES (), (), () +# instead of 3 distinct SQL statements as other databases may require. +{ + my $rsrc = $schema->resultset('Artist')->result_source; + my ($rv, $sth, @bind) = $schema->storage->insert_bulk( + $rsrc, + [qw/ artistid name rank charfield /], + [ + [ 100, 'John', 200, 'Smith' ], + [ 101, 'Joan', 201, 'Snith' ], + ], + ); + + is_same_sql_bind( + $sth->{Statement}, + \@bind, + q{INSERT INTO artist ( artistid, name, rank, charfield ) VALUES ( ?, ?, ?, ? ), ( ?, ?, ?, ? )}, + [ + map { [ dummy => $_ ] } ( + 100, 'John', 200, 'Smith', + 101, 'Joan', 201, 'Snith', + ), + ], + ); + + is( $schema->resultset('Artist')->find( 100 )->name, 'John' ); +} + +# Verify that 600 rows ends up with the return SQL having only 40 entries +# because they were inserted 80 rows at a time other than the last group +# of 40 rows. But, all 600 rows are inserted. +{ + my $rsrc = $schema->resultset('Artist')->result_source; + my ($rv, $sth, @bind) = $schema->storage->insert_bulk( + $rsrc, + [qw/ artistid name rank charfield /], + [ + (map { [ 1000 + $_, "X $_", $_ + 1000, "Y $_" ] } 1 .. 600), + ], + ); + + is_same_sql_bind( + $sth->{Statement}, + \@bind, + q{INSERT INTO artist ( artistid, name, rank, charfield ) VALUES } . join(', ', ('( ?, ?, ?, ? )') x 40 ), + [ + map { [ dummy => $_ ] } ( + map { 1000 + $_, "X $_", $_ + 1000, "Y $_" } 561 .. 600 + ), + ], + ); + + is( $schema->resultset('Artist')->find( 1001 )->name, 'X 1' ); + cmp_ok( $schema->resultset('Artist')->search({ artistid => { '>' => 1000 }})->count, '==', 600 ); +} + done_testing;