Two regressions for both context types snuck in during the the big populate()
rewrite
d0cefd99
- In scalar context the return value incorrectly went from () to []
- In void context an empty $data was handed to ::Storage::_insert_bulk
my (@results, $guard);
if (ref $data->[0] eq 'ARRAY') {
+ # column names only, nothing to do
+ return if @$data == 1;
$guard = $self->result_source->schema->storage->txn_scope_guard
if @$data > 2;
# positional(!) explicit column list
if ($i == 0) {
+ # column names only, nothing to do
+ return if @$data == 1;
$colinfo->{$data->[0][$_]} = { pos => $_, name => $data->[0][$_] } and push @$colnames, $data->[0][$_]
for 0 .. $#{$data->[0]};
} 'literal+bind with semantically identical attrs works after normalization';
# test all kinds of population with stringified objects
+# or with empty sets
warnings_like {
local $ENV{DBIC_RT79576_NOWARN};
[qw( rank name )],
[ $rank, $fn ],
]},
+
+ 'empty set' => { AoA => [
+ [qw( name rank )],
+ ]},
};
# generate the AoH equivalent based on the AoAs above
for my $bag (values %$args) {
+ $bag->{AoH} = [];
my @hdr = @{$bag->{AoA}[0]};
for my $v ( @{$bag->{AoA}}[1..$#{$bag->{AoA}}] ) {
push @{$bag->{AoH}}, my $h = {};
use Test::More;
use Test::Warn;
+use Test::Exception;
use lib qw(t/lib);
use DBICTest;
}
}
-ok(eval { $art_rs->populate([]); 1 }, "Empty populate runs but does nothing");
+EMPTY_POPULATE: {
+ foreach(
+ [ empty => [] ],
+ [ columns_only => [ [qw(name rank charfield)] ] ],
+ ) {
+ my ($desc, $arg) = @{$_};
+
+ $schema->is_executed_sql_bind( sub {
+
+ my $rs = $art_rs;
+ lives_ok { $rs->populate($arg); 1 } "$desc populate in void context lives";
+
+ my @r = $art_rs->populate($arg);
+ is_deeply( \@r, [], "$desc populate in list context returns empty list" );
+
+ my $r = $art_rs->populate($arg);
+ is( $r, undef, "$desc populate in scalar context returns undef" );
+
+ }, [], "$desc populate executed no statements" );
+ }
+}
done_testing;