From: Matt Phillips Date: Fri, 17 May 2013 20:08:09 +0000 (-0400) Subject: squash, data filter shouldnt run on arrayrefref X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=951a5760ebd3f4909a08ebdde89e5f860514094a;p=dbsrgits%2FDBIx-Class.git squash, data filter shouldnt run on arrayrefref --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 6069398..f7e6222 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1995,29 +1995,34 @@ sub insert_bulk { } for my $chunk (@chunked) { - my $current = shift @$chunk; - - my $tuple; - $tuple = sub { - my $row = do { - if (ref $current eq 'ARRAY') { - shift @$current; + if (ref $chunk eq 'REF') { + $self->_insert_bulk($source, $cols, $chunk); + } + else { + my $current = shift @$chunk; + + my $tuple; + $tuple = sub { + my $row = do { + if (ref $current eq 'ARRAY') { + shift @$current; + } + elsif (ref $current eq 'CODE') { + $current->(); + } + }; + + if ($row) { + return $row; } - elsif (ref $current eq 'CODE') { - $current->(); + elsif (!defined $row && @$chunk) { + $current = shift @$chunk; + return $tuple->(); } }; - if ($row) { - return $row; - } - elsif (!defined $row && @$chunk) { - $current = shift @$chunk; - return $tuple->(); - } - }; - - $self->_insert_bulk($source, $cols, $tuple); + $self->_insert_bulk($source, $cols, $tuple); + } } } else { @@ -2232,7 +2237,7 @@ sub _insert_bulk { # we have a split codepath here where col validation happens in the # fetch_tuple, but the tuple isnt used in no proto_bind situations, so we run it - if (not @$proto_bind) { + if (!@$proto_bind && ref $data eq 'ARRAY') { $data_filter->($data->[$_], $_) for (0..$#$data); } diff --git a/t/100populate.t b/t/100populate.t index 82902dc..7f824f2 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -447,14 +447,9 @@ lives_ok ( sub { done_testing; -my $q = $schema->resultset('Artist') - ->search({ - }, - { - columns => [qw/name rank/] - })->as_query; +my $q = $schema->resultset('Artist')->search({}, { columns => [qw/name rank/] })->as_query; #p $q; #diag Dumper($q); #p $schema->resultset('Artist')->result_source; #p Dumper $q; -$schema->storage->insert_bulk($schema->resultset('Artist')->result_source, [qw/name rank/], $q); +$schema->storage->insert_bulk($schema->resultset('Artist')->result_source, [qw/name rank/], [$q]);